Friday, August 17, 2012

Magento : Enablle specific payment method for specific IP address

Consider module as Bd_Testpament
Add a filed for Ip in system.xml with follwoing code
<config>
   <sections>
        <payment>
            <groups>
                <testpayment translate="label comment" module="testpayment">
                    <label>Test</label>
                    <comment>Test</comment>
                    <frontend_type>text</frontend_type>
                    <sort_order>256</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>0</show_in_store>
                    <fields>
            <allowed_ips translate="label">
            <label>Allowed Ips</label>
            <frontend_type>text</frontend_type>
            <sort_order>130</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>0</show_in_store>
            </allowed_ips>
                    </fields>
                </secureebsoffer_standard>
            </groups>
        </payment>
    </sections>
</config>

And edit __construct of model with following code

public function __construct()
    {
        parent::__construct();
       
        $allowed_ips=Mage::getStoreConfig('payment/testpayment/allowed_ips');
       
        if($allowed_ips !='')
        {
       
            if(!in_array($_SERVER['HTTP_X_FORWARDED_FOR'],explode(",",$allowed_ips)))
            {
                $this->_canUseCheckout=false;
               
            }
        }
        else
        {
                $this->_canUseCheckout=false;
        }

No comments:

Post a Comment