There are many tutorials out there which show parts of implementing a payment module. None completely build the module. They all stop short of showing how they implemented their nameless payment method. These holes made something which should have taken a day or take two weeks. Most of that time was spent figuring out the “magento way” to do things. Once that was established, the module itself is very small. 6 files and 300 lines of code.
For the purpose of this discussion on creating a payment module, I’ve made a fake payment gateway to integrate with.
Mockpay is a simple payment gateway consisting of a soap API with two methods and a payment form page.
The methods let you inform the api about the payment and the externally hosted form accepts the payment and sends the customer back to your store after payment is complete. Its similar to PayPal standard, minus the instant pay notification.
How to accept a payment with mockpay
Collect the payment details, and pass them to the api via the beginPayment() method.
$wsdl = 'http://a1ikuznugm2rjfqr.my.phpcloud.com/mockpay/service/endpoint.php?wsdl';
$client = new SoapClient($wsdl);
$response = $client->beginPayment(string $email, float $amount, string $orderId, string $desc, string $uriSuccess, string $uriFailure, string $uriCancel);
The response with be an array with a ‘hasErrors’ element and a ‘errorMessage’ element.
If ‘hasErrors’ is > 1, there was an error. If the submission was successful, the response will include a ‘token’ element. You’ll need this value to get your customer to the payment page.
Once you have the token, you can direct the customer to the payment page, located here:
When your customer arrives at the payment page, the payment details associated with this token will be pulled up automatically, including the amount, email, etc.
The customer puts in the payment details and clicks the pay now button or the cancel button.
Once the payment is complete, you will be redirected to the $uriSuccess,$uriFailre, or $uriCancel uri you filled in when you called beginPayment(). In all cases, the token will be appended to your uri.
At this point, you can use the second method in the api, queryPayment($token), to determine if the payment was successful and take some useful action like completing the order, sending an email, etc.
The code for this fake payment method is on github and has been deployed to my phpcloud container here:
wsdl = “http://a1ikuznugm2rjfqr.my.phpcloud.com/mockpay/service/endpoint.php?wsdl”
form = “http://a1ikuznugm2rjfqr.my.phpcloud.com/mockpay/form/paynow.php?token=value”
The next post will go into creating a magento payment module which utilizes the mockpay payment gateway.