How to create Magento payment module

Featured Image

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"?>
<model>mycheckout/standard</model>// very important thing, here you select the model for your payment method
<title>CUSTOM CARD</title>
<merchant_id>Insert merchant id</merchant_id>

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

< ?xml version="1.0"?>
<mycheckout translate="label comment" module="paypal">
<label>Custom CARD MyCheckOut</label>
<active translate="label">
<title translate="label">
<order_status translate="label">
<label>New Order Status</label>
<label>Gateway URL</label>
<label>Merchant ID</label>
<allowspecific translate="label">
<label>Payment Applicable From</label>
<specificcountry translate="label">
<label>Countries Payment Applicable From</label>
<sort_order translate="label">
<label>Sort Order</label>

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 :-)


Care to rate this post?


Domagoj Potkoc

Backend Developer

Domagoj is Magento Certified Developer who enjoys playing tennis after long hours in front of computer screen.

Other posts from this author

Discussion 63 Comments

1 2
Add Comment
  1. Debdatta

    Many kudus for very informative blog entry.

    How can I add online and offline refund options from admin for a particular payment gateway? If you could provide any type of help I would be highly grateful.

  2. Karthik

    \”SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`magento_database`.`sales_flat_quote_payment`, CONSTRAINT `FK_SALES_FLAT_QUOTE_PAYMENT_QUOTE_ID_SALES_FLAT_QUOTE_ENTITY_ID` FOREIGN KEY (`quote_id`) REFERENCES `sales_flat_quote` (`entity_id`))\”

    Please guide me to solve this.


  3. Paul Rafter

    @ Karthik – You have a Foreign Key Constraint, you can set a flag in your MySQL script…


    Put this at top, this will prevent a FK from preventing your script completing. I would bare in mind this is a quick and dirty fix, there maybe be something wrong with your Magento install.

  4. Amila

    hi, Im half way though using your invaluable tutorial.

    My payment gateway sends back the response to a URL which I can specify. Can you show me how to capture that and update the order status using this module please ?

    many thanks


  5. Borut

    Aren’t there some parts missing here – like for example where do I put HTML which shows up when user selects my new module in checkout?

  6. Hims

    Is it possible to create a magento module in ASP.Net using C#? If yes how?

  7. Karthik

    We like to integrate a payment module for creating admin orders which uses third party transfer.

    When we try to create the order, it gets placed without redirecting.

    Is it possible to make this in magento ?

    If so please guide us to move forward.

    Thanks to all.

  8. Pankaj

    Hello Domagoj Potkoc can u tell me is magento store order in databse before payment or after payment.
    I am newbie in magento

  9. I have my model configured. When I place any of the payment action method which are capture, initialize or authorize. I get error on Payment gateway selection page.

    Note: I do not have Payment Action option available in my configuration section. Is that required?

  10. Cy

    Hello Everyone,
    please am new to magento can any one show me in details how to get this payment gateway to work i cant really get it right.

  11. Vivek

    Hi Sir

    First, I appreciate you and thank you to for writing such brilliant tutorials.

    This solution is not working with magento 1.7 in my case. Will you please give me any guideline for implementing it in magento 1.7.


  12. tarun

    Hello, This is a grate Tutorial. There is module in Magento. I want to Create my module and call method of for payment from my module. Is it possible?

  13. seenu

    A very big unnoticeable bug exists here.
    frontname, here N should be capital

1 2

Add Your Comment

Please wrap all source codes with [code][/code] tags.