Analysis to consider when creating a payment gateway module in Drupal

Análisis para tener en cuenta al crear un módulo de pasarela de pagos en Drupal

To create a payment gateway in Drupal, a specific payment method must be created. A generic module must be developed that can be contributed in a way that does not depend on sensitive or specific information from the project for which it initially belongs.

How to create a module for gateway and payment method – PSE

Initially, this module should only include PSE, however, it should accept future extensions for other payment methods and accept various types that will be added in phases according to the needs of the project or projects that can use this system. 

Basic elements of the system

Type of payment method and PSE payment gateway

You will initially need to create a payment method type called “Commerce Redeban” (plugin id: commerce_redeban) which should be an annotation plugin: CommercePaymentMethodType. 

The payment method described above must be able to store the information necessary for communication with Redeban, i.e. communication URLs, private keys, public keys or other information that is required and must be consulted. 

The PSE payment gateway will also need to be created based on the previously defined payment method. The gateway will implement the previously defined payment method and will be an annotation plugin: “CommercePaymentGateway”. This plugin will be called: “Commerce Redeban” (plugin id: commerce_bredeban).

The transaction entity

The creation of an internal entity for the module is proposed. This entity can be called “Redeban Transaction” (redeban_transaction). This entity must be generated with the minimum fields required to store transaction information, which can be consulted later for validations, such as basic data to generate tokens as well as other order, payment or user data that are required.

System services

The creation of two services for the module is proposed: 

  1. Transaction consultation service. Said service must be able to return entities of type “Redeban Transaction” according to various search elements, for example by order ID, by transaction ID, etc. in an agile and simple way, in addition to being able to store elements of said type autonomously, simplifying the management of said entity, allowing the other elements of the system to create, search, consult and process said transactions in a transparent manner. 
  2. Communication service with Redeban payment gateway and generation of keys, tokens or other data that must be generated at run time by the module. Special care must be taken in the way said module is developed so that all internal calls to the Redeban payment gateway are made in said service and not directly in other objects or files, always having to go through said service. 

Initially, this service will only contain the token calculation methods and the calls to the payment gateway's bank query methods as well as the calculation of the redirection URL to PSE. A method must also be included which must be called from the notification URL (web hook) where the payment will be confirmed.

Platform integration 

The integration of the platform must have several phases which will be detailed below in a superficial way but taking into account that it is the most sensitive part and that it directly affects the flow and operation of purchases on the site.

Steps for integration 

Enable payment method

The step of enabling the payment method is perhaps the one that entails the least risk; as long as the previously defined module works correctly, it will be carried out easily. 

For this step it is important in a “custom” module to override the payment type object in order to override the “getDisplayLabel” method since if the project has the payment method selection it has a special layout. 

Capture payment notification or confirmation

Another important point is to capture the confirmation that is produced through the “web hook” and that will allow you to proceed to create an element in the reload queue. 

Carry out the payment verification system

By allowing payment status verification, a queue can be used to perform individual status verification of each payment on the gateway and thus keep the payment status of the transactions confirmed.