In this Opencart tutorial developer guide, we are showing how to create a custom payment module or extension in the Opencart version 3. Opencart by default supports more than 45 payment modules. Log in into admin, go to Extensions >> Extensions >> Choose the extension type “Payments”, you can see the lists of payments module in Opencart.
Here is the flow of the most eCommerce website.
Today we are showing you postmortem the payment gateway section.
Here are some of the normal steps that happen in the payment section:
- When the customer is ready to pay for goods or services on your website, they select the payment method on your website.
- There are two ways of payment gateway processing:
- One is Off-site payment processing
In the off-site payment, the website is redirected to the payment service website and payment is made on the payment service website.
There will be no place to enter the credit card information or login to payment gateways.
The payment gateway provides a Payment form in which we matched similar fields.
Data are passed from Form.
Need return URL or cancel URL so that when payment is a success it returns to that return URL and if the payment fails then it returns to the cancel URL.
Skrill, Paypal Standard, Liqpay, etc. are the default payment modules for Off-site payment processing.
- Another is on-site payment processing.
In the on-site payment, the payment is made on the same site, the payment processing is done through APIs.
The payment gateway provides a JSON request.
There will be a form where they can enter the credit card details or bank information etc.
Data are passed as JSON format.
It will return success or failure messages through API in JSON format. Once you get the success or failure data then further processing can be done in the website server and the message can be shown or redirected to the success page.
Authorize.net’s AIM, Paypal Pro, Square, etc. are the default payment modules for on-site payment processing.
- One is Off-site payment processing
- When the payment method is Off-side payment processing then data are passed on hidden fields in the form. If we check the documentation of NoChex you can see the form code like below:
https://ssl.nochex.com/downloads/Payment%20Guides/payment_page_integration_guide.pdf page no. 5
Mostly the payment gateway provides us with the form method type, action URL, and fields that we can pass to them for processing. Once you click the “Confirm Order” button, these hidden fields data are passed to the payment gateway and processing happens in their website.
- When a payment gateway process the payment and is successful then the customer is directed to the success URL.
- When the payment method is On-side payment processing then data are passed from website Server to payment gateway through API, as we are using Opencart which is builtin PHP so we use CURL to call the API.
- The website server passes the data to the payment gateway through API, mostly CURL is used to communicate with the APIs, we pass JSON-formatted HTTP requests to the API endpoint in either the sandbox or production environment of the payment gateway.
- Payment gateway requests authorization for the payment from the customer’s bank, third party provider, or card issuer.
- The bank/provider/card issuer approves or rejects the transaction.
- Payment gateway sends the success or failure response, containing the transaction result, and calls the Callback where the website server can process the data.
- The website server processes data returned by the payment gateway and it redirects to the success page.
These are the steps that happen on Opencart for payments. So we need to take each step into consideration while developing the payment extensions.
Checklist for Developers while integrating the payment extension
Here is the checklist for the developer while integrating the payment extension on the Opencart or custom platform
- Always make a google search if the Opencart payment extension is available, sometimes it is available for free.
- If free is not available then start by creating/asking an account and visiting the documentation.
- Mostly each payment gateway has a test environment so get test credentials. Create a playground account to get test credentials and get familiar with the test environment.
- Check out the PHP SDKs, with this, it will be easy to understand the code. Like for Paypal https://packagist.org/packages/paypal/paypal-checkout-sdk
- Follow the integration guide. Each of the product documentation provides an integration guide. Follow the instructions to make sure your payment process works as needed.
- Be sure to check if what ISO country codes (3‐digit or 4-digit), what language support, and what currencies support are available for that payment gateway.
- Check all your APIs in Postman to confirm everything, before development
- Test the system. Make sure everything works. Remember you can place a test order using test credentials on Postman.
- Be sure to read how error handling is done, how many rate limits, if any domains & IP address restrictions, policies, and compliance
- After reading the documentation, now you can decide whether you need to make the Off-site payment extension or on-site payment extension.
- Then start the development.
In our next post, we will show you how to create the off-site payment extensions, we start by cloning the Skrill or Opencart Paypal standard payment extension, which will help us to understand how we can create the Opencart payment extensions. Till then, please let us know if you need any help or custom development, and keep on learning Opencart.