Skip to main content
General

How To Create A Custom Payment Module In Magento ?

By |January 23, 2015 January 3rd, 2022No Comments

Devising a smooth payment method in an Ecommerce website is crucial in converting a casual visitor into a customer. Any unpleasant experience, especially in the payment process, will raise questions on the integrity and security of the website.

Magento provides a wide array of payment modules built-in with the system.  With the changing market scenarios, we have different kinds of payments methods and gateways in the market. In few instances, we have noticed that there are few unique payment gateways which require additional information for security. We were not able to find a suitable module in the marketplace. In such cases, it’s recommended to build a customized module that handles the complete information required for the payment gateway.

Let’s have a look at building one such customized payment gateway in Magento.

MAGENTO CUSTOM PAYMENT MODULE

To begin, we need to create our own Namespace_Module.xml file with our code pool.

Create config.xml



    
        
            0.1.0
        
    
    
       
           
               Namespace_Module_Block
           
        
        
            
                Namespace_Module_Helper
        
        
            Namespace_Module_Model     
            
        
    
    
        
            
                standard
                
                    Namespace_Module
                    your own frontname
                
            
        
        
            
                
                    modulename/layout.xml
                
            
        
    
    
         
             
                 1
                 namespace_module/method_paymentmethodname
                 Payment Gateway
                 pending
                 EN
                 gateway url
                 0
                 offline
             
         
     

MAGENTO CUSTOM PAYMENT MODULECreate system.xml file



  
    
      
        
          
          text
          8000
          1
          1
          1
          
            
              
              select
              adminhtml/
                system_config_source_yesno
              1
              1
              1
              0
            
           
             
             select
             adminhtml
               /system_config_source_order_status_new
             2
             1
             1
             0
           
           
             <label>Title</label>
             <frontend_type>text</frontend_type>
             <sort_order>1</sort_order>
             <show_in_default>1</show_in_default>
             <show_in_website>1</show_in_website>
             <show_in_store>1</show_in_store>
           
          
            
            text
            24
            1
            1
            1
          
          
            
            
            adminhtml/
              system_config_backend_encrypted
            obscure
            25
            1
            1
            0
          
          
            
            
            adminhtml/system_config_backend_encrypted
            
            obscure
            26
            1
            1
            0
          
          
            
            text
            27
            1
            1
            0
          
          
            
            select
            adminhtml/system_config_source_yesno
            
            28
            1
            1 
            0
          
          
            
            multiselect
            adminhtml/system_config_source_payment_cctype
            
            40
            1
            1
            0
            1
          
          
            
            select
            adminhtml/system_config_source_yesno
            
            41
            1
            1
            0
          
          
            
            allowspecific
            50 
            
              adminhtml/system_config_source_payment_allspecificcountries
            
            1
            1
            0
          
          
            
            multiselect
            51
            
              adminhtml/system_config_source_country
            
            1
            1
            0
            1
          
          
            
            text
            98
            1
            1
            0
          
          
            
            text
            99
            1
            1
            0
          
          
            
            text
            100
            1
            1
            0
          
          
        
      
    
  

Note:

The Payment Module will just Store the Credit Card for further process.

In the config.xml file

              namespace_module/method_paymentmethodname

and system.xml file

           

In all above three instances, paymentmethodname should be the same.

To display your payment method input fields. Create your own block and phtml file.

class Namespace_module_Block_Form_paymentmethodname extends     Mage_Payment_Block_Form_Cc
{
    protected function _construct()
    {
        parent::_construct();
        $this->setTemplate('module/form/paymentmethodname.phtml');
    }
}

Finally create the payment model which will capture the credit card information and store for future use.

getInfoInstance();
       $info->setCcType($data->getCcType())
       ->setCcExpMonth($data->getCcExpMonth())
       ->setCcExpYear($data->getCcExpYear())
       ->setCcNumber($data->getCcNumber())
       ->setCcLast4($this->_getLast4($data->getCcNumber()))
       ->setCcOwner($data->getCcOwner());
       return $this;
    }
}

Implementing the above mentioned code creates a custom payment module which enables retailers to get the necessary data from the customers. Once the data has been obtained, developers need to work on the business logic to use the data in an efficient way.

In a recent study by Forrester, 24% of shopping cart abandonment happens due to limited payment options. With new payment options and gateways surfacing in the market, it’s necessary for retailers to provide adequate payment options to empower a successful purchase.

Magento 1 stores need to be PCI compliant to ensure data security of customers. Make your website PCI compliant by opting for Magento 1 to Magento 2 migration now. Let’s Talk.

Iyappan

Author Iyappan

Iyappan is a Certified Magento Developer Plus Technical Architect at DCKAP. He is passionate about Magento. He is the 'go-to' guy for all our Magento needs. A cool-headed, hands-on veteran of many end-to-end implementations.

More posts by Iyappan

Discover What You’re Missing

Get the weekly email full of actionable ideas and insights you can use at work and home.