Popular Topics

Recurring charging of credit cards is a convenient solution for the customer and the seller

This tutorial will help you understand the mechanism of this type of payment and help you implement it correctly on your own website.Recurring payments can be used for subscription or on-demand payments, without the need to re-enter card details.

When you have a token (parameter "cli_auth"), which is a random string representing the connection between the payment card and the seller's account in the Tpay system, you must prepare the transaction.

The unpaid transaction should be generated using the presale API method. In case of payment failure, there is no need to generate new one if the order remains the same.Example of presale parameters:

The information returned in the response is a confirmation of successful or failure charge.In the case of failure, the returned "reason" parameter will contain the rejection code, which can be compared with this table and passed to the client (for example if the payment limit is too low).

You can perform more attempts later by repeating the sale method for the same transaction identifier.

Tpay.com provides ready to use PHP libraries in which making payments with a token is very easy!Check the recurring payment example on github.com.

Example of implementation based on PHP Tpay libraries

In this tutorial: Example of credit card gateway implementation based on PHP Tpay libraries we have described the creation of two classes that are responsible for the first card payment and receiving notification of a payment.When we start the integration of recurring payments, we assume that in the database of the store a given user has already been assigned a minimum of one payment card token.

Create a control function that will enter basic transaction data and prepare an unpaid presale transaction.At this point, we assume that the Client Token downloaded from the customer's database will be forwarded:

This mechanism is now ready to be called whenever you need to charge the payer's account, for example, a subscription or other fee, because the amount may be different from the amount of the original transaction.

In the simplest (not recommended) model, you can use the CRON mechanism, which will call our file encapsulated in additional conditions required in your system (such as verification, whether the customer's account is still active), eg once a month.

Of course, for each charge, the input data of the init() function should take the values you want to debit the payer's account, in this case, we used the sample data.

After each charge, the customer receives the notification email from Tpay.com containing a link to his card deregistration, preventing the next payment.

If your system collects the fee incorrectly, simply make the refund on the Merchant Panel.