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.
To begin, we need to create our own Namespace_Module.xml file with our code pool.
Create config.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
<?xml version="1.0"?> <config> <modules> <Namespace_Module> <version>0.1.0</version> </Namespace_Module> </modules> <global> <blocks> <namespace_module> <class>Namespace_Module_Block</class> </namespace_module> </blocks> <helpers> <namespace_module> <class>Namespace_Module_Helper</class></namespace_module> </helpers> <models> <namespace_module><class>Namespace_Module_Model</class> </namespace_module> </models> </global> <frontend> <routers> <namespace_module> <use>standard</use> <args> <module>Namespace_Module</module> <frontName>your own frontname</frontName> </args> </namespace_module> </routers> <layout> <updates> <namespace_module> <file>modulename/layout.xml</file> </namespace_module> </updates> </layout> </frontend> <default> <payment> <modulename_paymentmethodname> <active>1</active> <model>namespace_module/method_paymentmethodname</model> <title>Payment Gateway</title> <order_status>pending</order_status> <language>EN</language> <url>gateway url</url> <allowspecific>0</allowspecific> <group>offline</group> </modulename_paymentmethodname> </payment> </default> </config> |
Create system.xml file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
<?xml version="1.0"?> <config> <sections> <payment> <groups> <modulename_paymentmethodname translate="label"> <label>Your Payment Title</label> <frontend_type>text</frontend_type> <sort_order>8000</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> <fields> <active translate="label"> <label>Enabled</label> <frontend_type>select</frontend_type> <source_model>adminhtml/ system_config_source_yesno</source_model> <sort_order>1</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>0</show_in_store> </active> <order_status translate="label"> <label>New Order Status</label> <frontend_type>select</frontend_type> <source_model>adminhtml /system_config_source_order_status_new</source_model> <sort_order>2</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>0</show_in_store> </order_status> <title translate="label"> <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> </title> <url translate="label"> <label>Gateway URL</label> <frontend_type>text</frontend_type> <sort_order>24</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> </url> <guid translate="label comment"> <label>Merchant GUID</label> <comment></comment> <backend_model>adminhtml/ system_config_backend_encrypted</backend_model> <frontend_type>obscure</frontend_type> <sort_order>25</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>0</show_in_store> </guid> <shared_key translate="label comment"> <label>Shared Key</label> <comment></comment> <backend_model>adminhtml/system_config_backend_encrypted </backend_model> <frontend_type>obscure</frontend_type> <sort_order>26</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>0</show_in_store> </shared_key> <error_email translate="label"> <label>Error email recipient</label> <frontend_type>text</frontend_type> <sort_order>27</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>0</show_in_store> </error_email> <debug translate="label"> <label>Debug</label> <frontend_type>select</frontend_type> <source_model>adminhtml/system_config_source_yesno </source_model> <sort_order>28</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>0</show_in_store> </debug> <cctypes translate="label"> <label>Credit Card Types</label> <frontend_type>multiselect</frontend_type> <source_model>adminhtml/system_config_source_payment_cctype </source_model> <sort_order>40</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>0</show_in_store> <can_be_empty>1</can_be_empty> </cctypes> <useccv translate="label"> <label>Request Card Security Code</label> <frontend_type>select</frontend_type> <source_model>adminhtml/system_config_source_yesno </source_model> <sort_order>41</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>0</show_in_store> </useccv> <allowspecific translate="label"> <label>Payment from Applicable Countries</label> <frontend_type>allowspecific</frontend_type> <sort_order>50</sort_order> <source_model> adminhtml/system_config_source_payment_allspecificcountries </source_model> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>0</show_in_store> </allowspecific> <specificcountry translate="label"> <label>Payment from Specific Countries</label> <frontend_type>multiselect</frontend_type> <sort_order>51</sort_order> <source_model> adminhtml/system_config_source_country </source_model> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>0</show_in_store> <can_be_empty>1</can_be_empty> </specificcountry> <min_order_total translate="label"> <label>Minimum Order Total</label> <frontend_type>text</frontend_type> <sort_order>98</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>0</show_in_store> </min_order_total> <max_order_total translate="label"> <label>Maximum Order Total</label> <frontend_type>text</frontend_type> <sort_order>99</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>0</show_in_store> </max_order_total> <sort_order translate="label"> <label>Sort Order</label> <frontend_type>text</frontend_type> <sort_order>100</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>0</show_in_store> </sort_order> </fields> </modulename_paymentmethodname> </groups> </payment> </sections> </config |
Note: The Payment Module will just Store the Credit Card for further process.
In the config.xml file
1 |
<default> <payment> <modulename_paymentmethodname> <model>namespace_module/method_paymentmethodname</model> |
and system.xml file
1 |
<sections> <payment> <groups> <modulename_paymentmethodname translate="label"> |
In all above three instances, paymentmethodname should be the same.
To display your payment method input fields. Create your own block and phtml file.
1 2 3 4 5 6 7 8 |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<?php class Namespace_Module_Model_Method_Paymentmethodname extends Mage_Payment_Model_Method_Ccsave { /** * Assign data to info model instance * * @param mixed $data * @return Mage_Payment_Model_Info */ public function assignData($data) { if (!($data instanceof Varien_Object)) { $data = new Varien_Object($data); } $info = $this->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.