PrestaShop 1.7 introduced a new payment API. Below, you’ll find information about how it works.
To develop a payment module for PrestaShop 8, you’ll have to respect some elements:
PaymentModule
.hookPaymentOptions()
& hookPaymentReturn()
and register these hooks (PaymentOptions
and PaymentReturn
).In the hookPaymentOptions()
method, you have to return an array of PaymentOption
.
Here is a list of the PaymentOption class variables. They all have a getter and a setter and are accessible in the array sent to the front office template.
$callToActionText
: The text displayed as the payment method name.$additionalInformation
: Additional information to display to the customer. This is free HTML, and may be used by modules such as bankwire to display to which account the bank transfer should be made.$logo
: The URL to a picture to display in the payment option selection widget.$action
: The URL to which the request to process the payment must be made.$inputs
: An associative array of additional parameters to use when sending the request to $action
.$form
: The custom HTML to display like a form to enter the credit card information.$moduleName
: The name of the module.$binary
: A boolean to set if the module form was generated by binaries and contains a submit button. It’s necessary to adapt the behavior.// create a PaymentOption of type Offline
$offlineOption = new PaymentOption();
$offlineOption->setModuleName($this->name);
$offlineOption->setCallToActionText($this->l('Pay offline'));
$offlineOption->setAction($this->context->link->getModuleLink($this->name, 'validation', ['option' => 'offline'], true));
$offlineOption->setAdditionalInformation($this->context->smarty->fetch('module:paymentexample/views/templates/front/paymentOptionOffline.tpl'));
$offlineOption->setLogo(Media::getMediaPath(_PS_MODULE_DIR_ . $this->name . '/views/img/option/offline.png'));
You can find a example module illustrating the four identified cases of payment modules on GitHub.
We have identified four cases of payment module:
PaymentOption type | Description | Minimal variables |
---|---|---|
Offline | This is the most simple case where you could be (e.g.:Bankwire, Cheque). It’s a simple URL to call, then various information are displayed to the customer. | $callToActionText , $action |
External | It’s a simple URL to call, then the payment is directly processed on the Payment Service Provider’s website (e.g.: PayPal, Paybox). | $callToActionText , $action |
Embedded | You write your credit card number and all the required data directly on the merchant’s website (e.g.: Stripe). | $callToActionText , $form |
Iframe | The payment form is displayed on the merchant’s website, but inside an iframe. | $callToActionText , $additionalInformation |
Note that there are some modules which create the Order with a pending order status during the payment processing (1), while others wait for the payment system’s approval to create it (2). But none of them create an order before the customer passed the payment service (bank, PayPal…).
Make sure you double check the id_cart
before creating the order.
if (2), make sure the amount you use to validateOrder()
comes from the external payment system. Do not use Cart->getOrderTotal()
;
For (2), when receiving a call to process the payment, make sure you double check the source of the call using a signature or a token. Those values must not be known of all.