views:

339

answers:

1

I need to make a custom payment method that gets some variables from the customer’s order and sends them as POST variables to an external url.

The variables I need to get from Magento are the total amount, the order number and the products description. Those variables are sent to a url of a third party gateway, where the credit card information is asked in a secure way, and when the transaction is completed, they return the user to my magento site.

I’ve searched for information and tutorials but I still feel a little confused, I’m practically new to programming in magento, so i would really appreciate it if someone could give an step-by-step explanation, or at least a link to a tutorial

Thanks

A: 

This is how Paypal works, so the included module for that would be a good starting point but basically:

  • you have a method on your Payment class that tells Magento that the method is suitable for the order (this lets you use different methods for different order-totals, or currencies etc. but you can just return 'true')

  • if there are any bits of information you need to capture that Magento otherwise won't, you setup a template/block for your Form, and this is shown when the customer selects your method (Paypal doesn't have such a form)

  • you implement an 'authorize' method that does any processing of the order details

  • you implement a getRedirectUrl method that returns a URL for magento to redirect the user too. If you do need to post to your gateway, then your redirect will be to a local URL (/redirect.php say) and here you'll have a form with hidden fields and some javascript that will automatically submit it (you can stick a loading-gif too if you like) which will take the user to the gateway.*

  • if you provide a URL to the gateway to send the customer back to (you normally do...) then you're going to need a page there too, which does any order-cleanup/validating, before redirecting the customer to the checkout confirmation page

(* you could do this as a controller and template within magento if you want (it's a bit tidier), but explaining how to do it that way will take a bit more time than I have)

Greg