Magento Web Development

How to make a custom Magento payment extension for an external gateway

Note: This tutorial is for Magento versions 1.x.x, and does not work on Magento 2 +.

Magento is a great open source e-commerce platform and has emerged as the market leader in the recent past. However, it still has a steep learning curve and although the community is growing exponentially, I was not able to find a simple tutorial on how to make a Magento payment extension which links up to an external payment gateway.

In this tutorial, I’m going to attempt to show you how to make a bare-minimum extension, which you’ll need to complete because different payment gateways have different APIs, hooks and functionality. This is by no means a definitive guide, but my attempt to try and get you started. Please note this tutorial assumes that you already know how to build a simple custom extension and have average knowledge of Magento, MVC architecture and of course, PHP. This tutorial is for Magento versions 1.4 and above.

I have created a bare-minimum version of the extension which you need to download from the steps that follow. I hope the code will be self-explanatory. For information from Magento’s wiki click here.

Step #1: Click here to download the ZIP archive for this step. Extract it to app/code/local

Step #2: Click here to download the ZIP archive for this step. Extract it to app/design/frontend/base/default/template

Step #3: Click here to download the ZIP archive for this step. Extract it to app/etc/modules

Once you have done this, you need to follow the following steps to get it working:

  1. Open app/code/local/Myname/Mygateway/controllers/PaymentController.php and read through the inline comments carefully. The URL that the payment gateway needs to redirect to on your web site after processing the customer’s payment (based on the naming we’ve used in this example) should be: . This URL will trigger the responseAction() function in the PaymentController, where we will need to validate the response sent by the gateway (to make sure it’s really from there), and if validated, process the order. The validation code is generally provided by the payment gateway.
  2. Open app/design/frontend/base/default/template/mygateway/redirect.phtml . This is where we post our values to our external gateway. We can retrieve any order information and pass it on as hidden form fields, which is submitted via JavaScript.
  3. Log into your Magento admin, clear your cache, and make sure the extension is enabled and working fine by navigating to System -> Configuration -> Sales -> Payment Methods and checking if you can see it there.

It is extremely important to go through all the files to get a perfect understanding of the extension. I figured the best way to learn this is to look at a working example. This took me a long time to figure out and I hope this saves a lot of effort for someone. Happy coding!

260 replies on “How to make a custom Magento payment extension for an external gateway”

Hi, very good article, it’s exactly what I’m looking for, thank you! Any idea why the link won’t show up in System -> Configuration -> Sales -> Payment Methods ?

Hi, I would like to have a simple extension created for my country gateway (yes, we have only one). Would you do it and how much would you charge? Thank you.

Just to make sure I followed the above steps on a fresh copy of Magento 1.6 , and I was able to see it in the extension’s settings under under System -> Configuration -> Sales -> Payment Methods . Enabled is set to ‘No’ by default.

I also use a clean magento 1.6, I’ve tried clearing cache and logging out, the link still doesn’t show up =(. I can see the module in System->Configuration->Advanced->Advanced and it’s enabled, any thoughts?

What “link” are you talking about? Are you talking about the extension that we just created? Or are you trying to reach the extension through a link?

If you’ve followed the steps exactly as it is, you should be able to see a “My Gateway” payment method under System -> Configuration -> Sales -> Payment Methods

how do i set the response url so that the payment gateway response triggers the magento code ?
Is there some specific setter method in magento that I have to put this URL in .

Able to send the request thru the getCheckoutRedirectUrl in mage_payment_model_method_abstract . However not able to set the response part.

yes response is coming from the gateway .. however how do i “configure” magento to start processing once a response comes back to me … Is this configured in the payment controller php ?

eg –>sends the request .. to the gateway>executed by the gateway as a response .

how do i “tell” magento to pick up processing once response.php has been triggered/executed. In my case it seems to just end there .. since i have not set it anywhere.

Also somehow facing the same issue what vladmir seems to be facing .. module shows up in config->advanced->advanced but does not show up in config->sales->payment methods 🙁

Okay you really need to read up on building a Magento extension and MVC architecture before getting to this level. There is no response.php . “response” is a function (responseAction located in file PaymentController.php) which is executed when the payment gateway redirects to the response URL you’ve mentioned. The payment gateway usually sends a POST request to the URL you’ve mentioned. So in the responseAction function you get the response sent by the payment gateway using the $_POST variable. If you still don’t understand how this works, I suggest starting off much smaller and understanding the basics of the MVC architecture and building simple front-end Magento extensions.

thx a lot .. ur comments helped .. Have another q .. is it possible to go to the order review (or stay at the payment information ) in the checkout/onepage depending on whether the payment was successful or not ?

Since this extension is to link up with an external payment gateway, the procedure in Magento is that you are sent via this extension to the payment gateway, and then the payment gateway sends you back to your return URL. You can do whatever you want in your return page depending on whether the payment was successful or not. The checkout page would have nothing to do with it once you are sent out of it.

Hey Junaidbhura,
very nice post, on Magento ver. with developer mode enabled , I got stuck with message: “Notice: Trying to get property of non-object in appcodecoreMageAdminhtmlBlockSystemConfigForm.php on line 526”, after I select Shipping Methods in Admin. How can I trace down such kind of warnings? Thanks

Oh, sorry, i meant: after I select Payment Methods in Admin… With developer mode disabled, it’s ok. Same with original files.

You made my day!!! After a few days of battling to get the integration to my payment gateway via form post working, you put it on a silver platter. Merci beaucoup!

Step #1: Click here to download the ZIP archive for this step. Extract it to appcodelocal

Step #2: Click here to download the ZIP archive for this step. Extract it to appdesignfrontendbasedefaulttemplate

Step #3: Click here to download the ZIP archive for this step. Extract it to appetcmodules

Nope still not working. Talking about these links

great post and code, thanks its helping a lot, my gateway payment generates a “token” in the hidden fields and the recomendations from the bank is to validate this tocken once they return the success.

So i have to store this token somwhere in the DB then once the bank send the client back read the transaction id and the tocken to validate the operation, any idea how can I crate the databae, what fields to include, how to acccess and compare from the controller?


Thanks Xomero,
I’m guessing your payment gateway sends a POST request to your controller. So just do a var_dump() in the responseAction() and do a test transaction. That way you’ll get to see what variables your payment gateway sends you. Based on that you can create a custom table in your database and run a Magento database query: . I’m sorry I won’t be able to help you beyond the scope of this tutorial. All the best!

Thanks junaidbhura for such a great tut.
But, I have a problem, done everything, step by step, but “My Gateway” does not appear in Payment methods?
Yes, i’ve cleared cache and logout/login, still nothing. It’s 1.6 magento.


Very good article, it’s exactly what I’m looking for, thank you!
I have a problem. When I make checkout, the fields of payment for the client (number of card, dates… ) do not appear :S

Can you help me?

Thanks, Fabio! This method is for an external payment gateway, so the fields don’t appear because the credit card information is entered at the payment gateway. Like when you checkout with PayPal you enter all the information on PayPal, right?

Now I understand. Thanks!

To get the amount will be getBaseGrandTotal(); ?> ?
and how to get the product information?

Hi, i followed all your steps but after the payment is made by the external gateway, it redirects to my website main page but does not give me any feedback if my payment was successful.
Is there any way to redirect to a successful payment page?

I am trying out link to an external gateway,I have go as far as contention but now I am slight confused or missing understanding, where to locate the post back reply ,

Great Post really helpful & thank yo for time.

how can save the order in the custom payment.
Is this correct?Order is not stored and i used the code in my response function.

$order = Mage::getModel(‘sales/order’);
$order_id = Mage::getSingleton(‘checkout/session’)->getLastRealOrderId();
$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, ‘Gateway has authorized the


🙁 please give me solun


Hey Vasanth,
The Order ID will be passed by the payment gateway, usually through a POST call. Of course, you need to pass the Order ID to the payment gateway first for it to pass it back to you. Once you get the Order ID from the payment gateway, you can get the order by using:

I already installed the extension.And also refresh the cache & session.Although module is enable in admin panel.But one major problem is not display under system->configuration->sales->Payment_Methods.My magento version is v1.6.2.

Please give me proper solution for this.

Hi Darshan,
I’m afraid I can’t help you out here, because there could be a conflict with this extension with another or a multitude of reasons why this is happening.

Try clearing your cache (both browser and Magento’s) , logging out and logging in. And of course make sure you have uploaded all the files.

Hi. Nice tutorial and thank you for that.

I got a problem after tried to test this on my server. after clicked on shipping method, there is another page appeared on the same page (side-by-side) something like there is an error processing … and after 1-2 seconds it redirected back to checkout page. could you advise me on this problem?

thank you.

Thank you for the excellent post.
I followed exactly, and got the payment method showing on the admin page. However it is not showing on checkout. Then I used the unmodified code as you have published, but with same issue. I am using magento 1.7

Thanks Kavee,
Thats probably because you need to clear the Magento cache under System -> Cache Management. Clear all the caches there to be safe.

No, I’ve tested this on 1.7 on a fresh install. Not sure what the problem could be. You could probably try this carefully on a fresh install too and work backwords from there to find out what’s different. Make sure the extension is enabled in the admin of course. I’m afraid thats about how much I can offer support 🙂 . All the best!

Yes, it works on a fresh installation. Have to find out why not in my existing setup. May be something to do with the custom theme.


It appeared to be a file permission issue. I ran magento-cleanup, and now it is working beautifully!!
Junaid, one more question, what is the return URL to be given to the gateway (for processing gateway return status)? Appreciate your help….

hello junaid, and thanks for your effort.
one thing i still do not understand is how you came up with response url? where and how you define that url? where it comes from?

thanks again

Hi BGz,
To understand this you need to understand MVC architecture and how Magento’s extensions work. The response URL is the name of the function “responseAction” in your PaymentController.php . If you were to name that function “bgzAction” , then your response URL will be . If you have any further questions on the subject I suggest reading up on MVC.

Greetings from Bangalore! If it doesn’t show up on the front end then there’s probably a caching issue or a conflict with some other piece of code. It works fine on a fresh install, so there’s some existing code on your site that conflicts with this extension.

Hello Junaid,

Thanks a lot for sharing this great tutorial.

I am facing an issue when order is placed it is not showing in the Order Grid at Sales->Order listing.

Also is it possible to send request to gateway before placing an order?

Thanks alot

Thanks! If the order isn’t showing up, it probably isn’t placed properly. This method does send a request to the payment gateway and gets a response. You have to write the code to update the order when the response comes back from the payment gateway.

I want to validate response from gateway before placing an order e.g when user place order by new payment gateway:

1. I have to call payment gateway API
2. Get response from API
3. If response is ok from gateway than create new order and redirect user to payment gateway website otherwise show user a message to “there is some internal problem please select any other payment option”.

Looking forward for your help urgently. I have to wrap-up this asap


I understand you are working around a deadline, but I’m afraid that is beyond the scope of this tutorial. This tutorial is meant to take you only this far, and assumes you have the expertise to do the rest.

I can understand it anyway thanks for sharing this tutorial that really helped me. If you share any other related tutorial links I will be thankful

Hi, I have installed the module and everything seems to work great up to the point where the response from the gateway. I get the following error:
Fatal error: Call to a member function getMethodInstance() on a non-object in /Library/WebServer/Documents/www/DEEP/invivo/app/code/core/Mage/Payment/Helper/Data.php on line 119

I am new to working with Magento so maybe I am missing something? I am also testing this on a clean install.

I think I found what I was doing wrong, I was still trying to retrieve the order using the test orderId “123” instead of the real ID of the order.

Hi Thanks for your nice post its helped me to deal with an external i just need some little info regarding redirect if Success. I putted the following link “” in the redirect post page if success.
its able to redirect Successfully after Success but i am getting this message
“The page you requested was not found, and we have a fine guess why” in the site.
which means .It will be helpful if you can help me to search the problem.
do i have to add something after “mygateway/payment/response” or
i have to alter something like “response” to “responseAction” . please brother, help me . I will be grateful to you.


Hi Sazedul,
This is most likely a caching issue. Make sure you go to System -> Cache Management and empty all caches. Also, for a development environment its best to turn off all caches to avoid problems like this one.

FYI, you don’t need to change the response to responseAction in the URL. The word “response” in the URL automatically fires the responseAction function in PaymentController.php . So make sure that you check the response that you get from the payment gateway in the responseAction function and update your order accordingly and maybe even redirect to a success or failure page accordingly.

Thankyou for a brilliant tutorial and for sharing your knowledge. I have just one question!

I know it is beyond the scope of this tutorial but there isn’t many people around that I can ask – so here goes:

How do I generate and post a token along with the orderId?

Thanks, Rafique!
Generating the POST token will need to be custom code. That depends on what you want your token to look like, since there’s no “one way” of generating a POST token. You can ask your payment gateway what that needs to look like. Regarding actually POSTing it, you can just make another hidden field in the redirect.phtml file which sends the POST request to the payment gateway.

Thanks for the reply, I have your module working in that it is processing the order and redirecting to the gateway via the form. I just need to overcome a “Security precondition failed” error at the gateway.

I’m using this for Chase Paymentech BTW!

Kind regards…

I hate to say it, but its beyond the scope of this tutorial!

I think you should read their documentation in detail, and if they gave you some sample code, make sure you replicate that exactly inside Magento so that you don’t miss out any security preconditions and any other specifications of theirs. Good luck!

Hey Juan,
Good job on this saved me hours.. no days trying to create my own module payment gateway from scratch. I have run into a problem and your expertise would be greatly appreciated. As you have said many times over the return url is:

so I changed it to suite my site and now it should be

that looks right until I try it …then it isnt found by the server the function is still responseAction, I extracted everything to their right folders everything works well upto that part.

could I just make a new file called response.php and the just call that function?

making my return url

Hi Eric,
Thanks! My name’s Junaid, btw 😀

It will be better to follow Magento’s MVC structure rather than creating a response.php file . Make sure you’ve made your extension correctly by testing it like:

1. Create a function called ‘testAction’ in the PaymentController.php and echo ‘Hello World’
2. Navigate to and see if you see ‘Hello World’ on your screen. If you don’t then your extension is not set up well, or your site is cached or it could be practically anything!

You need to first learn how to make an extension and how Magento’s MVC architecture works. Only then can you understand how this extension works.

I did read a alot on it for a good two days or so even started building my own module until I came across this. I am definately new at Magento but I recon I got a good grasp on how MVC works even though magento’s is a bit more confusing. I guess the real question is about the folder structure since it wont matter where I put the file if I am not calling the location. as in I was trying to find the specific folders …mygateway/payment/… but I cant find them in the root (/magento/). So I was wondering can you backtrace the folders from response to mygateway.

Hi again junaid,
Just wondering, do the controller files need to be in your template folder as opposed to the base? so:


instead of:

Hi Junaid one last problem it only works for logged in users but a guest gets redirected back to the cart 🙁 Any ideas why that could be the case?

Thanks a lot for the code and everything. Just awesome.

One last thing is there a way to insert the data which are returned from payment gateway to database? Simply wanna store the data in the database which are returned from the database.

Great example. Thanks.
But I’ve got same error as `joe` at `March 20, 2012 at 10:58 am` in this comments…
when I lead to Payment Methods in admin panel, I see
Notice: Trying to get property of non-object in /var/www/data/myproject/htroot/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php on line 568

Magento v.

I nothing changed in files. Guess something wrong in XML.
if I comment out fields section, then it works fine.

I found the error in XML

Section “sort_order” wrote NOT correct.
Must be, so:

Sort Order

but wrote, so:

Sort Order


Hi Junaid, THX for this great extension. The ext works great, i have only a little problem. When all is done in response action (i’m sure that all is done because i receive an email and the order is processing) i cannot redirect to success or failure page. Every url that i put in Mage_Core_Controller_Varien_Action::_redirect(‘checkout/onepage/success’, array(‘_secure’=>true)); is wrong and send me to the home page. Have you ever encountered this kind of problem. Hope you can help me…. The work is pratically done and everything is fine except redirect to success or failure. Sorry for my poor english.



Hi Gianluca
I’m glad this helped you out. Hmm that is a weird problem. Maybe you can try a different redirect function like this:

Just tried …. Still not working. I try to put a log before and after. Both are written to the log. No error in apache… I’m going mad. Everything is working except the redirect. I also try $this->_redirect(‘checkout/onepage/success’, array(‘_secure’=>true));… Same result, no error. If you have any idea that could help me please tell me. Thx a lot for your ext and for your help!

If you get redirected to the home page when you try redirecting to the checkout/onepage/success it means that the order you are trying to access no longer exists in the session. Are you sure you are working with an active order?

Basically, the onepage/success and onepage/failure pages will only work if a user created an order, got redirected to the payment gateway, paid and got redirected back to our site and if the order is still available in $_SESSION (without closing the browser window). Otherwise, you get redirected to the home page.

Yes, I’m sure. After payment if i type manually the url to checkout/onepage/success it works. I also try to put a header location and exit from function…. Still not working….. I don’t know how could i resolve it.

In the responseAction function, the first check is to see if there was a POST, and if there’s no POST to redirect to the home page. Does your payment gateway send you a POST request back to responseAction? If this is not the problem, then I’m not sure what it could be 🙂

Junaid i am newbie to magento can you confirm when magento insert order in sales_flat_order either before payment or after payment and what is #00000001 order id and how it is calculates

Hi Junaid. I am very grateful for your post and code. It has saved me hours of work, but i have two questions that were posted before but not answered:

1. How can i save some of the information returned to my database and relate it to the order? (It may be out of the scope, i know, but if you could just point me in the right direction, i would appreciate it)
2. This Fatal Error shows up instead of a response, i traced it to a class called Mage_Payment_Block_Info : Fatal error: Call to a member function getMethodInstance() on a non-object in magento/app/code/core/Mage/Payment/Helper/Data.php on line 119.
3. Following Magento’s model, how would i implement a SOAP payment gateway. Information is sent, and returns with values, in the same redirect page, so i have to redirect the page myself towards success or failure.

Hi Francisco
1. This is way beyond the scope of this tutorial, and I’m afraid you need to do this on your own
2. I’m not sure what this error is, it could be a conflict with something
3. If you use SOAP, then the SOAP actions would be in the redirectAction, and yes you need to redirect so success and error based on the result. There would be no responseAction

Junaid… thank you very much for your contribution, it is helpful for us. Cheers and continue with your great work

we are using your extension and everything works fine. It connects to the bank successfully. When payment is rejected failure response is activated, but when the payment is accepted, it returns an error. Log Magento active and I get this error.
2013-04-16T05:01:59+00:00 ERR (3): Recoverable Error: Argument 1 passed to Mage_Payment_Helper_Data::getInfoBlock() must be an instance of Mage_Payment_Model_Info, boolean given, called in /home/vetter/public_html/app/code/core/Mage/Sales/Model/Order.php on line 1269 and defined in /home/vetter/public_html/app/code/core/Mage/Payment/Helper/Data.php on line 117
Could you give me a light to fix this?
Thanks for your time and patience

Thanks Junaid, you made my day! 😀
The script works perfectly!
But now a have a little problem… With success payments, all is perfect, but when payment fails, it seems “cancelAction()” function hasn’t been triggered. So, wrong orders aren’t change to “canceled” status. Oddly, the redirect to failure page works!
Have you some advice?
i suspect there’s a problem with my gateway, because it refresh twice the redirect link URL (that the payment gateway needs to redirect to my own site). Maybe does it lost something with session id?

thanks again

Thank you so much for this great tutorial, i got it working until i get to the return URL.
My payment gateway returns the values in the URL so its not a POST but a GET.
example: /mygateway/payment/response/&orderInfo=100000033&

how can get the values?? normal GET and REQUEST is not working.

Thank again

Hi Fadi,
I’m not sure if it was a typo, but it doesn’t look like the URL is configured properly. You mentioned:
Whereas a proper URL would be:
(Notice the question mark) . Let me know if this works.

thanks junaid for the help, i was able to get the info i needed from the URL but now i have another problem. below is the return URL i get from the payment gateway:

this url is giving me a 404, unless i remove the return URL from the link it works fine.

any ideas.

Again the problem is with the URL:
won’t work, but:

You just need to replace the first ‘&’ with a ‘?’ for it to be recognized as a proper URL. If you are not able to control what your payment gateway is sending back to you, then tell the payment gateway to send the response to
so the URL becomes something like:
which is a valid URL


I noticed by default Magento will send the transaction ID not the order ID to the processor. Is there any way to send the order ID instead?

Also, how would I add the customer’s IP address to the fields transmitted?

Hi Joe,
Since this is a custom payment gateway that we are building, Magento doesn’t “send” anything. It is us through our code who can determine what to send and what not to send. To answer your question: Yes we can send the order ID and the customer’s IP. But I’m afraid that is beyond the scope of this tutorial. You can take a deeper look at the code and I’m sure you will find your answer.

Hi Junaid, thanks for your tutorial. It’s a great help.

I notice that the order is immediately saved into database when the ‘Place Order’ button on checkout page is hit. I knew this from the admin page, there were pending order comes in before the gateway redirect to magento shop.
Is it an issue or something? I thought the order should be saved after get valid response from the gateway.
note: I’m working on localhost actually, with simple php script as server. Or is this the issue..?

Hi Wily,
Don’t worry about it, this is default Magento behavior. The order is first created with the status “Pending” and then depending on whether the payment was successful or not, the status of the order is updated.

Hi Raju
Unfortunately this is beyond the scope of this tutorial. If you read the code carefully, I’m sure you will find what you are looking for

nice tutorial,
i need to know how to handle the transaction complete stage
eg: after the payment complete it returns the transaction complete and i need to update my stock quantity according to that status, so how can i do such a process from this module, i’m new to magento please give me some help THx

Hi Sajith
If you look at the code, this is done automatically when you update the order. Please read how Magento handles orders when it is updated for more information.

yes i found it Junaid thank you very much for your kind quick response,
can u please tell is there any way to get the back end details that means think i add

Gateway URL

i need to take this value to redirect.phtml action

is there any way to get that value Junaid?

ohh this is related to your tutorial junaid, i think u didn’t get my question.
eg: after your module activate , back end panel we can add gateway url
so if i want to add it in form action without hard cording , means get the value that inserted by back end form name=”mygatewayform” method=”post” action=””

how to do??

This tutorial is about linking to an external payment gateway and getting a response back. This tutorial is not about getting an extension’s settings into the code as you are suggesting.

Hii Junaid
Excellent tutorial but i am facing a problem.When my gateway redirect me to my website it show me an error page ” Fatal error: Call to a member function getMethodInstance() on a non-object in /home/content/78/10881478/html/app/code/core/Mage/Payment/Helper/Data.php on line 119″. Please tell me how can i remove this error.

I had exactly similar problem, i have resolved it by the following way.
Here is the findings:
First of all make it sure that you have got order id / transaction id on your payment gateway response. Usually payment gateway refer order id as transaction id, so see the documentation of payment gateway about the response variables naming.
If you don’t find the order id / transaction id variable on the documents, you can also track it by using :

if($validated) {

Lets say you have got the transaction id by the name tran_id so ,you can code like : $orderId=$this->getRequest()->getPost(‘tran_id’);

I have solved it by this way, hope your problem also resolved.

Let me know your update.


hii Shahed
I worked as you said in above post but still getting same error. if i comment $order->sendNewOrderEmail(); then it work fine for me. Please help me to resolve this problem. I am using federal bank payment gateway.


i m using your code on my website but when i m integrating with ccavenue and after the process of the order to ccavenue if i press the cancel button on the ccavenue page the redirect to my index.php page and the order is proccessed with out payment it is not redirecting to the failure page. I have done all the major steps as directed. Please guide on this

Hi Biodun,
This is a standard extension which should work on all versions of Magento. Any extension can be packaged and deployed on Magento Connect.

I found the solution.

Replace the below lines(34-35):
$order = Mage::getModel(‘sales/order’);

by below code:
$order = Mage::getModel(‘sales/order’)->loadByIncrementId($orderId);
if($order[‘increment_id’] == “”)
echo “Order ID $orderId not found, please verify this Order Number is correct.”; die();
condition to check increment_id is used in case order id returned by payment gateway is not correct.

In my case payment gateway was not returning order id. I Use following code
$orderId = Mage::getModel(“sales/order”)->getCollection()->getLastItem()->getIncrementId();

and it start working fine


This is an old post but it has been great for helping me integrate a payment solution.

I am 99% there but am stuck on the notification back from my payment gateway.

The payment gateway provide a notification to the server via an HTTP GET request, letting you know if a payment was accepted or declined.

They provide a url for this example below

But I am not sure how to use this to notify site if payment has been completed.

Any help would be great.

Let me make that a bit clearer

So the notification url I will be using is below

SessionID is a unique ID assigned by payment gateway

Note is the orderID which was generated by magento

Tariff is the price of the order in pence i.e. 100p

Status is the status of payment, there are about 10 different types and Status=100 is a successful payment and Status=200 is a failed payment

Thank for you module, I am having a problem with with response, the if statement do not validate response from my gateway, how do I make it that if $validate = 00 show success and redirect else error

Hello and thank you for this awesome post. It’s just the thing I’ve been looking for a couple of weeks by now.
I have a weird issue. I did all the steps on a fresh Magento copy locally ( and it appeared in the admin panel. I did the logic and everything, and I uploaded the files (double-checked, all files are uploaded) on a Magento live store. I can’t see my module there. So, same files on local and live, version local, live, and it doesn’t work on the live version. Any ideas?

Hi Dejan,
Have you tried clearing all your caches on your live site under System -> Cache Management? You can also triple check if you have uploaded all the necessary files (perhaps you forgot one?)

Yes, the cache is disabled while I am doing this.

And I checked again, all files are there… I uploaded them as full folders in three steps, just like the packs.

And also it doesn’t show on frontend locally either. (v I didn’t check this before because I can’t test it on my local server. “Enabled” parameter is set to “Yes”.

Please ignore my previous replies, I had a small error in the config.xml (one name opening the tag, another closing, but it seems 1.7 ignored this somehow and showed me the module). I am testing further so I will get back as soon as I have result. Thank you for your fast reply.

OK, I made it. Thank you so much, this was such a pain for a long time and now it is solved in a couple of hours. Brilliant!

Hi, thanks for your awesome tutorial, but I encountered a little problem in Everything is fine except that I cannot change settings in admin. nothing happens when I clicked save. Any ideas?

Hello. Thank you for bootstarter. I’m going to use successAction and cancelAction to handle payment status. So, user successfully redirects to bank’s payment page, but when he redirects to bla/bla/bla/success, his checkout/session is lost. Something happens between

header(‘location’. $myurl);

in redirectAction and

$session-> getMyVar();

in successAction.
I realy got stuck with it. Please help.

What the names of all the values ​​that I can to post on the redierct page ?????

For example getBaseGrandTotal ();?>

Thanks for the tutorial!! I’m having the same problems as Chandler. Everything is worked perfectly except that I can’t seem to be able to save the config under admin->system->configurations->payment methods. There is no error message and nothing in Chrome console. Please help if you have any idea what this could be?

And yes… I tried all the basics, like clearing the cache and reindexing

Very Helpful tutorial simple and easy to get working. I’m having a problem after moving my site from local host to a live server. I have a button on the redirect page but it does not seem to display when the site is live. Any suggestions???

Hi Chero,
I’m glad you found this useful. If this works on your localhost, then make sure you have uploaded all files correctly and clear all caches. Other than this, the problem could be a range of things!

Hi junaid,

I have created a custom paument gateway but i am not able to debug in capture function and orders are successful created


__(‘Invalid amount for capture.’));
$order = $payment->getOrder();
echo “”;
$file = fopen(“test.txt”,”a”);
Mage::log(“Logging a message pankaj”);

$this->_place($payment, $amount, self::REQUEST_TYPE_AUTH_CAPTURE);
return $this;

thank you for your wonderful post
I am having issue with red hat OS. I am able to successfully configure with your above steps in ubuntu
Its not working in Red hat I am not able to see the link in system – > configuration – > advanced – > advanced
Could you please help me

Hi Sathiesh,
The OS is not the problem. There must be a problem with your Magento installation. Have you cleared all your caches?

Thanks for this module, this helped a lot, but I have a question, the payment gateway I am to connect to is requesting for the following

Pending Return Url
Cancel Return Url
Success Return Url
Failure Return Url
I am confused on what to use…
am I suppose to use for everything..
Please your response will be appreciated…

Hi there,
Each URL points to a function in the controller. For example, payment/response points to PaymentController -> responseAction . If you want a cancel URL, you can make another function in PaymentController called cancelAction() . For success, successAction() , etc.

One more question to ask sir,

How do I get the type of product being bought and the email of the user buying the product at my checkout page, I mean the redirect.phtml


Hello, i’m creating my own payment method gateway, following your steps but the payment controller doesn’t seem to handle the response of the gateway properly.
I could verify the gateway recives my POST correctly, but I don´t know why responseAction doesn’t handle gateway´s response. I woluld like to know how I must change or verify ? Thank you for your help..

I am getting error. Please help me to resolve this.

Fatal error: Call to a member function getMethodInstance() on a non-object in /opt/lampp/htdocs/magento1.6/app/code/core/Mage/Payment/Helper/Data.php on line 119

if i need to send error message from the paymentcontroller.php to the failer redirected page what function should i use??

Add the error before redirecting to the failure page. Something like this:
Mage::getSingleton( ‘customer/session’ )->addError( ‘There was an error…’ );

Hi. i have everything working except for one issue. when i checkout and the gateway posts back to my success url, the order is entered into sales > orders but doesnt create the invoice and apply payment to the order – it shows total due $the amount.

in my redirect.phtml file i have tried the clientSuccessfulPurchaseUrl as both $site_url;?>mygateway/payment/response and $site_url;?>checkout/onepage/success

in both cases, successful transactions are showing as successful to the customer but in admin > sales > orders the payment isnt being applied.

the gateway has confirmed that they are receiving and processing the transaction and posting back to my success url.

any help would be great. thanks.

Hi Jack,
The Sales -> Invoices are different from Sales -> Orders. You need to create the invoices manually from the orders, it won’t automatically get created after a payment, unless you write code for that. The payment wont be “applied” to the order, only the status would change to “processing”. Hope this helps.

i see. so i have everything working as intended? in this case, i would need to cross reference my pending orders with my gateways transactions and manually create my invoices in magento to apply payment?

in terms of writing the additional code to perform the automatic creation of invoices, is this something you could do as a project for me?

Hi Jack,
You don’t need to cross-reference your payments with the gateway. That’s where the order status comes in. Pending orders would have a status ‘pending’ , and orders which have been paid will have a status ‘processing’. This is set in the responseAction()

Please send me an email regarding anything outside of this tutorial. My email address is in the contact page.

Hi Juanid

Thanx for this excellent contribution. In my case everything is working fine but order email is not been sent. Any idea?

Best regards

Hi Juanid,

This extension is really helpful and helped us a lot but I got stuck with the following:
I have integrated HDFC payement gateway with mygateway but I am stuck with responseAction(), $this->getRequest()->isPost() is is returning false, response is coming through hdfc as post data but it doesn’t retrieve post data in responseAction().
Can you please suggest me how do I get post response in responseAction(). It would be great if you add your inputs on this.
Thanks in advance.

Parag Pradip Kamble.

Hi Parag,
You can try using $_POST . If that is also empty, it means that a POST response is not being sent.

Great Post and very helpful,
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

save my life, god bless you and the Guadalupe Virgin pay your wonderful post really save my life, do you have any paypal acoount for sendind some of my apreciate XD

Hi Junaid, so glad to found these resources. I’m also stuck with the response now.I redirected my response,using the below link:

but it will be redirected back in http://localhost/magento/test/index.php (home page).it will not display any success or error page.

I added on response action from the payment controller the ff. lines:
$orderId= $_GET[‘orderId’];
echo “no orderId”;


expectedly, it should go inside if($validated) condition. but then its not working. Hope you can help me on these.



Thanks for nice tutorial. It real work nice. but i have one problem occur , when i proceed to checkout no any display the payment method . please help me.


First of all, thank you for this great post and great magento module!

I’m having a little problem with it. I have tested it on a fresh magento installation and work great, but when I try to addapt it on my website , when I place an order, instead of getting me to the payment gateway link from ‘redirect.phtm’, it get me to‘ (mywebsite is just for example, it’s actually my website link)
Could you help me with this problem?
Also, I want to know how much it cost, if you want, to integrate this module to my website, I’m a beginner and I don’t have so much time to spend on it.

Thank you!


Thanks this really helped. quick question, the payment site I am trying to setup requires that every transaction request com with unique code that identifies my account with them. how do i send that value together with the other things like price etc?


Thank you for the module, it has been very useful and is easy to customize. I did have one question, do you know which are the variables that Magento uses for Total cart price and others? In order to pass them on as hidden fields i need to know how to call them, and I haven’t had much luck on other forums.

Thank you!

It seems that this no longer works.

In the responseAction the $_POST variable is empty. I think that this is due to the fact that since 1.8 it is necessary to include a form_key with all post requests however I do not see how this is practical in this situation.

Hi Matthew,
This is not true. This even works in 1.9. There must be something else wrong. If the POST is empty in the responseAction, then the payment gateway is probably sending something other than POST.

I have follow your instructions and create the module. I installed to a multilinguage store. For redirection I create two links ( and The problem is that my bank accept only one link. So I think that if change the redirection link in Standard.php the module will work. Change line 10 to return Mage::getBaseUrl(‘eurobankpayments/payment/redirect’, array(‘_secure’ => true)); but return me the error “Invalid base url type”.
Also I believe that I will have problem with responseAction(). The will not work and will be something like
Can you please help me with this
Thank you in advance

If your bank accepts only one URL, then use only one URL. Why do you need two URLs? If you want to find out which store the order was placed from, that information is present in the order.

Hi Junaid,

Is there a way to retrieve the data from the gateway via $_GET response?
The gateway I’m working with sends it via $_GET.


I Want To Know How I Can Configure My Response Page In Your Given Code .

Cause I m going to connect with vpos system to alignetsec will u please tell me how i can configure that response code..

Thank you
Chirag Zunzvadia

I am having an issue when dwolla payment exenstion just stalls and do not redirect. any one has any suggestion on how to make this work?

Hi Chima,
Yes that’s correct, this is where it would redirect. You can add whatever code you want in your PaymentController in the redirectAction() and then write the rewrite code to the payment gateway here.

Hi Junaid,

Many thanks for your quick response. I don’t seem to be getting this part right.
I did this ->
public function redirectAction(‘’) {
$block = $this->getLayout()->createBlock(‘Mage_Core_Block_Template’,’mygateway’,array(‘template’ => ‘mygateway/redirect.phtml’));

Did i get something wrong?

Pls tnx

Hi Junaid,

Pardon my last reply, too much work thats why i was unable to figure that out. I’m now been redirected to the payment gateway portal.
Issue now is, i need to requery the value sent by the payment gateway so that the customer can get the response of their transaction.
I’m lost here.
Can you please help?

Hi Junaid,

Thank you for your contribution. I was able to make a custom payment module via your example. It was working pretty well. However when we switch our website via ssl. The order email notification is not sending. But before ssl it was working fine. I checked on our gateway lobby. Payment was in but the order confirmation is not working. Do you have any idea what when wrong?

Thank you bro for your great work it is very usefull your extension I integrated to magento and works perfect! you save my assss 🙂

Thank you so much for this tutorial, it’s awesome!!!
Quick question – where is the form view to take card details etc..? Only thing in the frontend is redirect.phtml; shouldn’t there be form.phtml to take card details?

Thanks again

hi implemented eveything here as discribed but i keep on getting the error below

Fatal error: Call to a member function getMethodInstance() on a non-object in /Applications/AMPPS/www/magento/app/code/core/Mage/Payment/Helper/Data.php on line 119

any help?

I have followed the above tutorial step by step (using all the file etc names as listed above). However my issue is in the payment flow after I return from the external payment page I get redirected the the page and I am presented with the below error message and I am not sure how to fix it?

Hoping you may have a suggestion.

Fatal error: Call to a member function getMethodInstance() on a non-object in /var/www/skin/app/code/core/Mage/Payment/Model/Observer.php on line 46

How do i keep the cart items if transaction fails and how do i display the response message to the user if the transaction fails, e.g. if gateway responds saying “insufficient funds” how do i display that to the user?

Hi Derek,
You can’t keep cart items. That’s how Magento works. It clears the cart to create an order with “Pending” status. If you want to show a message to the user, you can store it in the session and display it as needed.

Hello Junaid,

I am new to Magento, Thank you for the tutorial, my payment gateway ask for more parameter. such as Name, Email and Phone Number. How can I retrieve this value from the customer billing address ? So as to complete the redirection. A mage to get Name, Email and Phone Number . Thanks Bro.

thank you junaid bhura for this code, but order confirmation email not sending to customer through this code… any solution?

What happens if I start a payment and during the transaction process I just stop the server application ?

In my tests: the payment was in fact confirmed .
But my order was not created on Magento.
Then the client bought again. (1 order to two payment credited)

i tried with above code but it was not redirecting to payment gateway url which 3rd party site.
and also i want to send host and merchant id to tha

please do the needful

Hello Greate post i realy enjoyed it ……….and it was exactly what i was looking for……..
but i wanted to ask how to have extra information on the reponse process

Hi , Thanks for this tutorial. this awesome unique tutorial i ever learned. when i select payment method on customer point of view i want to select card details can you help me?

Hello Junaid,
Thanks for the article. Does this work in Magento 2.2.4? I am placing your sample files in the specified locations but the new Module is not getting added in the list of modules.

Thank you for the tutorial. It worked for me. I have a question, the bank gave me the link and some codes so in the payment page it will show the merchant name and amount to be deducted. In which file do i have to insert it?

Leave a Reply

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