📜 ⬆️ ⬇️

Autopayment from the inside: Part 1. How recurrences work



Hi, Habrahabr!

Relatively recently, we launched the recurrent payment service and want to share their internal device with you. Essentially, recurrences are a series of recurring payments. The principle of their work is simple: during the first (parent) payment, a recurrent pattern is registered in the database, which is assigned a unique identifier. All repeated charges are made using this template - the merchant gives a command to his service provider, indicating the recurrent identifier and the amount of payment, and the service provider initiates writing off funds from the user's card.
')
The user himself only needs to accept the offer once, where it is indicated for what and how often the funds will be written off.

In general, the whole process can be divided into two stages - registration of a recurring payment template and re-cancellation of a regular payment. Let us show by the example of using Payler Gate API :

1. Registration template

In the StartSession payment initialization request, you need to set the value of the optional recurrent parameter to true :


In response to the successful execution of the transaction, the identifier of the recurrent payment template created is recurrent_template_id . You can also get it by running a GetStatus request, specifying the key (merchant ID) and order_id parameters . Example response for a successful query:


2. Re-write off

After successful registration of the template, you can re-write off without the participation of the cardholder. To do this, run the RepeatPay request, specifying the following parameters:

key - merchant identifier
order_id - order identifier in the merchant system
amount - payment amount in kopecks (may differ from the amount of the first payment)
recurrent_template_id - recurrent payment template ID

An example of a response to a successful request:


There are several templates that can be registered, and information on each of them can be obtained via a GetTemplate request (it is necessary with the indication of the template identifier, otherwise information about all templates existing in the merchant will come back). If the request is successful, the merchant will receive a response containing the following parameters:

recurrent_template_id - unchanged string
created - the date and time of registration template
card_holder - the name of the cardholder to which the template is attached
card_number - masked card number
expiry - card expiration date (by default, it is created for the entire card validity period)
active - template activity (with true or false values)

And an example of a response to a successful query:


By the way, an ActivateTemplate request will help activate or deactivate a template, in which you need to specify only three parameters - key, recurrent_template_id and active, with a value of true if the template is to be activated, or false - if deactivated.

As you can see, everything is very simple. A little later, we will continue to reveal the topic of auto payments and write another post.

We want to note that the recurrence service is free for our merchants. At this stage, the service is provided by Russian Standard Bank and Alfa Bank, but very soon Promsvyazbank and Surgutneftgazbank will join them.

We will be glad to your questions and comments!

Wishing you a great weekend,
Your payler
Come to us on facebook

Source: https://habr.com/ru/post/256881/


All Articles