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, | 2

Adding custom credit card type to your payment method in Magento

Inchoo Flickr Gallery Magento Extension Srdjan Stojiljkovic
Srdjan Stojiljkovic, | 44

Inchoo Flickr Gallery Magento Extension

Automatically invoice/ship/complete order in Magento Branko Ajzele
Branko Ajzele, | 32

Automatically invoice/ship/complete order in Magento

85 comments

  1. To see payment in front, be sure the payment code is the same name as the config node.

    Example : `protected $_code = ‘my_payment’;`
    And config structure in your XML:
    `config > sections > payment > groups > my_payment`

  2. It not show on frontend how to show that on frontend side? Can you please help me about this.

    1. In your custom model class use:
      protected $_canUseCheckout = true;

    2. Class name always start with capital letter, so make sure that it is Standard.php

  3. Hello
    Thank you for your nice tutorial , I done this its working for me fine, But i could not see payment method name in magento admin panel sales order , Please guide me

    Thanks

  4. I am new in magento so can you please tell me where i can find model folder which is mentioned in your last step

    Thanks

  5. My payment module is not visible on front end. and why did u leave this aspect in your tutorial. what is the use of a service when one cannot use it. means module won’t appear on front end this way. and even no tutorial like this is on your blog. why is that so? it must be a tutorial series. its in complete sorry. Please help me urgently with this.

  6. Hello everyone, Can any one tell me that how can i add a field of payment method logo just like title, when we write any thing in title its displayed in frontend on checkout and i want to add a field of logo so i can add a image and it should displayed in checkout page.

    thank in adv.

  7. Hi Domagoj! i want a paypal popup window right after i click in the order button in onpage checkout page but it so hard with me can you show me how to do that T___T thanks

  8. I need your support friends!

    I have a payment method extension. This generate a Token URL for finally redirect at shopper at gateway.

    But now I need create into my system.xml, Two groups;

    The system.xml file content:

    Payment Methods
    sales
    text
    501
    1
    1
    0

    MyGateway Express
    text
    5
    1
    1
    0

    Enabled
    select
    payment/mygateway_express/active
    adminhtml/system_config_source_yesno
    0
    1
    1
    0

    Title
    text
    20
    required-entry
    1
    1
    0

    API Key
    text
    30
    required-entry
    1
    1
    0

    Signature Key
    text
    40
    required-entry
    1
    1
    0

    Environment
    select
    mygateway/config::getEnvironment
    50
    1
    1
    0

    Shopper Email
    Optional. Send automatically payment instructions at Shopper’s email.
    select
    payment/mygateway_express/shopper_email
    adminhtml/system_config_source_yesno
    120
    1
    1
    0

    Advanced Settings
    config-advanced
    text
    1
    1
    0
    150

    Payment Action
    select
    mygateway/config::getPaymentAction
    20
    1
    1
    0

    New order status
    select
    adminhtml/system_config_source_order_status_processing
    30
    1
    1
    0

    Payment from applicable countries
    allowspecific
    40
    adminhtml/system_config_source_payment_allspecificcountries
    1
    1
    1

    Payment from Specific countries
    multiselect
    50
    adminhtml/system_config_source_country
    1
    1
    1
    1

    Sort order
    text
    60
    1
    1
    0
    validate-not-negative-number

    * The first group for keep general configuration fields (credentials p.e.) and active the original service;
    * The second group for basics fields and enable a new service using the credentials of first group.

    As you see friends, I need this extension shown at Shopper finally two payment options. I’m trying of replicate as work of the Paypal extension but yet aren’t me work. Or otherwise can give me tips or tutorial on how to work with more two groups of this way it…

    Thanks very much!!!!

  9. please help me i want to make credit card payment through user account in magento frontend after place order

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

  11. 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.

    Thanks

  12. 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.

  13. 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?

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

  15. 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.

  16. 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?

  17. 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

    Amila

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

    SET FOREIGN_KEY_CHECKS = 0;

    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.

  19. \”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.

    Thanks.

  20. 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.

  21. I want to upload a zip file and enzip it in my module. I have upload success but don’t know how to enzip.

    Any help please!!!!!!

  22. Hello ,
    I get Notice: Trying to get property of non-object in /var/www/magento/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php on line 568
    when I try to access Payment Methods on admin side . Any help please. I can’t figure out, what’s wrong.

  23. Remember, when working on a local dev machine i.e Windows, it WILL NOT care about case on file names. If you use standard.php on a Linux box the payment method will not show on the frontend. Make SURE you capitalize the first letter of any files within your module folder, the correct file name should be Standard.php. This one drove me crazy! Tute is great thanks Inchoo.

  24. I need little different from this tutorial hope some on can help me i need a payment method with some cash handling charges e.g Cash Handling which include in total amount of order and mentioned separately on order review page. hope some one can help me

  25. how can I get order information to send these variable to passrelle with GET method.
    Help me please
    Thanks for advence.

  26. hi,

    If i want to create a payment method that support recurring payment, what should i do?

    Have you got any suggestions on this?

  27. You are getting basic file not found msg. You need to define a helper class for the payment module if the module is gonna utilize helpers if not then remove included helpers from the xml.

  28. Hi,

    Thank you for this useful post. I tried your codes but i am receiving the following error..

    Fatal error: Class ‘Payment_Ccavenue_Helper_Data’ not found in C:\wamp\www\ccmagento\app\Mage.php on line 516

    Any help

  29. i have to make folder as App->code->local->Ebs->Epay

    and under Epay folder create a new folder etc where two file config and system.. files are update… same as your written notbook,

    and under app/code/core/mage/paypal/model/standered.php i have to put php code…
    but still only advance module have show only… no view in payment method.

    i need urgent.. and i have to put EBS pament gateway under it.. how these possible.

    Thanks

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

    my module shows in the list of modules (configuration>advanced) but not in the Payment Methods ,help ?

  31. Hi,

    Can you suggest some post on integrating CCAvenue in magento? This will certainly help a lot of developers here in south asian region.

    Thanks
    Vikrant

  32. Hey Guys!
    If the module does not appear in the frontend check if the model class in standard.php and config.xml are named the same

  33. How can I add custom tax to this payment module?
    Add custom tax to subtotal and retrieved that on review

  34. I want to use payment gateway which fetch users credit card details there only. I just need to post them certain parameters and redirect. Please elaborate more on below mentioned lines in your article. ( file location and exact code etc)
    ————————
    “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…”

  35. you did not tell us where we going to create file and how it will appear in the admin , no file structure you provide.
    please provide us the file structure .

  36. 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));
    }

    how magento knows to call this function in model.
    can i post request to payment gateway in the above function

  37. Hello,
    I have integrate my payment module and can redirect to payment site from front end order create.
    Now i want to redirect to payment site when we manually place order from admin…

    Is there any way to redirect payment site on order create from admin?

    Thanks in advance,
    Pritesh Modi

  38. Hi very thankful for u r blog.
    but the module label is not showing up in front end ,only the radio button is showing up.

    thank u

  39. I recently started building a payment module for my website to do credit card authorization for a local bank. I read several articles including this one. I am at a point I need an intro to controllers as whether authorization declined or approved I land on the default post checkout page. I would appreciate from anyone out there. If I can peek into some sample code I can learn thus you can point to some open source module that I can peek into or your own code. Many thanks…

  40. @Steet Photography Zine

    Um you comment makes no sense. They just gave instructions on how to make a base template for a payment module.

    You need to write your own controllers, since no payment method has the same controller. Since they all aren’t the same it makes no sense including one.

    But yes the tutorial is missing a controller that you need to write up on your own.

  41. hello sir my payment option is not being displayed in front end .i have followed all the steps in tutorial.my module is being displayed in backend and also in payment option but not on front end .Any body please help.

  42. Great article. Thanks a lot.

    There does seem to be a bug in the system.xml provided. The sort_order tag is closed on line 79 when it should instead be closed on line 83. This lead to a “trying to call a method on a non-object” for me that took a while for me to debug.

  43. Thank you Nered.
    I have tried with two different payment gateway worldpay and EBS.
    When I try with single page checkout I am getting error:
    “There was an error processing your order. Please try after some time” as javascript alert.
    And when try with multiple shipping and then instead of redirect to the gateway url the page goes to checkout/multishipping/success/.
    Can You help me whats the problem?
    Thanks.

  44. Pati the gateway you described is very similar to paypal. If i were you i wuld dupe the paypal module and reconfigure it to your purpose.

    Because paypal already has a working IPN that will save you some time. Reconfigure your action controler by apending the data required by your payment gateway like price, customer info, transaction emblems etc..

    When i was developing eonmega pos for magento i duped paypal module and reconfigured it saved me a lot of time. In adition check out Zend tutorials once you get in to OOP it will be a pice of cacke.

  45. Um, you need to understand this alone is not a functioning payment gateway. This is a say “blank template” on wich you can further develop your own gateway. Basicly this gives you a template and you can rewrite your procesing controler to colmpleate any actions and append any needed information to it.

  46. Thank you for Reply.
    The payment gateway I am using is Billdesk.
    When the customer click on “Place Order’ he will be redirected to the bill desk payment gateway web site. There he paid from visa , debit card etc. After successful payment he is redirect to my website.
    How to do this . I am trying to add controllers/StandardController.php
    But always getting page not found.
    Help me. Thanks.

  47. Thank You , Great post, its help me. But I am getting page not found error while redirecting.
    Please Help me how to do this . i want to redirect to a payment gateway url and after payment back to my website.
    Please help me by replying.

  48. this is really helpfull. Some times Before I was created a payment but for some reason when i created a another payment module i was unable to configure that but for your help i did that back again.
    Anyway thanks for the good tutorial.
    Thanks

  49. Hey…. good tutorial. Actually successfully made a module with it, for credit cards that are authenticated using soap calls..

    but am stuck on the re-direct part… could you elaborate on that please?

  50. Nothing happens , my module shows in the list of modules (configuration>advanced) but not in the Payment Methods ,help ?

  51. Hi Nered,

    I also encountered your problem but what i just did on that is I click the “Save Config” in System>Configuration>Advanced and holla! . .my module was displayed and also my payment module. Hope this will help. =)

  52. // Nothing happens in me. I also try different instructions on books but still nothing. I’m running it in localhost. Any help? Thank you //
    P.S. This is a reference to creating a module. Anyway:

    You need to create a codepool xml file in your app/etc/modules/

    true
    community // Or local depends where you stored the module.

    Also to change the title go here: Module/Mycheckout/etc/system.xml look line 6-7.

  53. How to change the tab caption. From “PBZ Card MyCheckOut” to “MyModule”. Thank you

  54. Nothing happens in me. I also try different instructions on books but still nothing. I’m running it in localhost. Any help? Thank you

  55. Tnx for the showcase but this will not work on its own. You also need the following:

    1. CodePool XML which goes in app/etc/modules/
    This is where you would have to define coodepool for magento. This would be the file that tells magento where the module is located and weather its activated or not.

    2. For a processing you would also need controller, where you would need to define functions such as startAction(), cancelAction(), void etc..

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.

Tell us about your project

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