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:
1 2 3 4 5 6 7 8 |
// Hook validate order Hook::exec('actionValidateOrder', array( 'cart' => $this->context->cart, 'order' => $order, 'customer' => $this->context->customer, 'currency' => $this->context->currency, 'orderStatus' => $order_status )); |
The method uses two letters templates: order_conf
и voucher
.
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.
hello we are facing issue when set template from controller not able to see other content like header footer and other theme changes.
please help me
HI Mr Simonchk,
Which payment method would you recommend as the best one to integrate with PS V.1.7?
Thank you
Bryan,
I recommend you to search for the module with offline credit card on Prestashop Addons.
hi there, i need to send cart from a prestashop website to an offline credit card form with return order state validation or error, is it possible?
Rahees,
Please contact our support team ([email protected]) with your question.
Hi Mr Alex, I have a serious prestahop issue. If you could resolve this please help me. Same product categories were repeatedly displaying on my shops front page. This happends every time i create a new shop from my back end. Iam waiting for your valuable reply.
Hi can you create a prestashop 1.6 admin theme and how much it cost.