How to create Magento payment module

How to create Magento payment module

Here is small example which will explain how to create a simple Magento payment module.

I hope that you know how to create magento module and I will skip this step.
First of all, you have to create in etc folder config.xml file with next content:

< ?xml version="1.0" encoding="UTF-8"?>
 
 
 
1.0.0
 
 
 
 
Inchoo_Mycheckout_Model
 
 
 
 
Inchoo_Mycheckout_Helper
 
 
 
Inchoo_Mycheckout_Block
 
 
 
 
mycheckout/standard// very important thing, here you select the model for your payment method
1
pending
 
sale https://someurl.com
Insert merchant id
0
1
 
 
 
 
standard
 
Inchoo_Mycheckout
customcard

Next step: you have to create system.xml file also in etc folder with next content:

< ?xml version="1.0"?>
 
 
 
<label>Custom CARD MyCheckOut</label>
text
0
1
1
1
 
 
<label>Enabled</label>
select
adminhtml/system_config_source_yesno
10
1
1
0
 
 
 
<label>New Order Status</label>
select
adminhtml/system_config_source_order_status
50
1
1
0
 
 
<label>Gateway URL</label>
text
58
1
1
0
 
 
<label>Merchant ID</label>
text
59
1
1
0
 
 
<label>Payment Applicable From</label>
select
60
adminhtml/system_config_source_payment_allspecificcountries
1
1
0
 
 
<label>Countries Payment Applicable From</label>
multiselect
70
adminhtml/system_config_source_country
1
1
0
1
 
 
<label>Sort Order</label>
text
100
1
1
0
 
 
 
 

In this system.xml file we create options for this payment method. These options you will see in admin section under payment method, also if you need additional options you can add them.

Last step: is creating model in folder model with file-name standard.php. This model is defined in config.xml file. Here is example:

< ?php class Inchoo_Mycheckout_Model_Standard extends Mage_Payment_Model_Method_Abstract { protected $_code = 'mycheckout'; protected $_isInitializeNeeded      = true; protected $_canUseInternal          = false; protected $_canUseForMultishipping  = false; /** * Return Order place redirect url * * @return string */ public function getOrderPlaceRedirectUrl() { //when you click on place order you will be redirected on this url, if you don't want this action remove this method return Mage::getUrl('customcard/standard/redirect', array('_secure' => true));
}
 
}

If your method redirect when customer click on checkout button place order you have to create (customcard/standard/redirect) standard controller with method redirectAction and etc. This page will create html form which will send POST data to payment gateway. All data which you need for creating this form you can get from Magento model $session = Mage::getSingleton(‘checkout/session’); and etc.

When you finish everything you will get next option in admin section:

I hope that will be helpful 🙂

You made it all the way down here so you must have enjoyed this post! You may also like:

Adding custom credit card type to your payment method in Magento Toni Peric
Toni Peric

Adding custom credit card type to your payment method in Magento

Inchoo Flickr Gallery Magento Extension Srdjan Stojiljkovic
Srdjan Stojiljkovic

Inchoo Flickr Gallery Magento Extension

Automatically invoice/ship/complete order in Magento Branko Ajzele
Branko Ajzele

Automatically invoice/ship/complete order in Magento

Tell us about your project

Drop us a line. We'd love to know more about your project.