In this article I’m going to tell you how to create a payment module for Prestashop. Every country has its own payment methods, some are more popular than others. There are such methods as PayPal that can be found all over the world but every country has its own favorite anyway.
Rather than being inherited from the “Module” class all payment methods are inherited from the special class – “PaymentModule”.
module_country, module_currency, module_group are the tables that work with the payment methods, and allow to restrict the use of the payment method in a particular country, with a particular currency or for a specific group of users.
The most important method in the class PaymentModule is validateOrder, it is responsible for the order creation. In this method also a single hook class: actionValidateOrder is called:
Partner With UsLet's discuss how to grow your business. Get a Free Quote.
// Hook validate order
'cart' => $this->context->cart,
'order' => $order,
'customer' => $this->context->customer,
'currency' => $this->context->currency,
'orderStatus' => $order_status
The method uses two letters templates:
Usually there are several payment methods:
- Using the API. The developer needs to learn the payment system’s API to refer to available methods, create an order, send your credit card information, etc;
- Transition to the payment page, on the side of the payment system – usually required to generate a form, for transmitting the payment data directly to the side of the payment system;
- Iframe integration – it is between the first and the second method. Because the customer does not leave the site, while the interaction with the API is typically less than in the first method;
- Offline methods.
If you want to learn how payment methods work you can look at simple methods that the system provides out of the box: Cheque and Bankwire.
Let’s take a look at the methods and hooks that are generally used by payment modules. Thus, almost any payment module will use the following hooks:
- ‘payment’ – is called in a checkout step where customer need to choose the payment method;
- ‘header’ – is used to connect the css and js scripts;
- ‘orderConfirmation’ – is called on the page on which the user gets after the order completion. Usually includes payment information;
- ‘adminOrder’ – is called on the order details page in the admin panel. For example, it can be used to display information about the payment, forms, API use or refunds.
Before creating the payment module, you need to decide at what moment the order will be created. Sometimes this can be a requirement of the payment system itself. There are scenarios when it is better to form the order after the payment, but sometimes the order can be formed before the payment.
It is always necessary to thought out the logic of the payment statuses.
The difficulty of creating such a module depends on the API, and the tasks that need to be implemented, i.e., whether you need to support the refunds, subscription, etc.