Recurring payments are simply resales performed in specific time periods. You can perform them based on any conditions defined by your business model.
Resales do not require all the customer/transaction information. That is why they have to refer to a single transaction performed previously.
Start with preparing the necessary information to perform a resale. In order to do that you must first retrieve the ID number of a previous transaction. This ID number identifies the transaction in PayLane’s systems. You can easily retrieve this number while performing the transaction, for example:
1 2 | $status = $client->directDebitSale($ddebit_params); $id_first_sale = $status['id_sale']; |
1 2 | status = client.direct_debit_sale(ddebit_params) id_first_sale = status["id_sale"] |
1 2 | status = client.direct_debit_sale(ddebit_params) id_first_sale = status['id_sale'] |
1 2 3 4 5 6 | api.directDebitSale(sale, customer, account, new Callback<SaleResult>() { @Override public void onFinish(SaleResult result) { long idSale=result.getIdSale(); } }); |
Although you can refer to any previous transaction ID to perform a resale, we highly recommend to refer to the most recent transaction. This approach has several advantages, for example allows to easily track the transaction flow.
Usually merchants store such ID numbers in their database. This way they do not have to store any sensitive data, yet they are still able to refer to a specific transaction.
Now, having retrieved the ID number (e.g. from your database), prepare information for the resale and call the resaleBySale function.
You can also check whether the transaction was performed successfully by calling the isSuccess method.
Retrieving the transaction ID number (or error details, if anything goes wrong) is also very simple and can be done as shown below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | $resale_params = array( 'id_sale' => $id_first_sale, 'amount' => 99.99, 'currency' => 'EUR', 'description' => 'Recurring billing product #1', ); try { $status = $client->resaleBySale($resale_params); } catch (Exception $e) { // handle exceptions here } if ($client->isSuccess()) { echo "Success, second id_sale: {$status['id_sale']} \n"; } else { die("Error ID: {$status['error']['id_error']}, \n". "Error number: {$status['error']['error_number']}, \n". "Error description: {$status['error']['error_description']}"); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | resale_params = { 'id_sale' => id_first_sale, 'amount' => 99.99, 'currency' => 'EUR', 'description' => 'Recurring billing product #1' } begin status = client.resale_by_sale(resale_params) rescue PayLane::ClientError => e # handle exceptions here end if client.success? puts "Success, id_second_sale: #{status["id_sale"]}" else puts "Error ID: #{status["error"]["id_error"]}, \n"\ "Error number: #{status["error"]["error_number"]}, \n"\ "Error description: #{status["error"]["error_description"]}" exit end |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | resale_params = { 'id_sale' : id_first_sale, 'amount' : 99.99, 'currency' : 'EUR', 'description' : 'Recurring billing product #1' } try: status = client.resale_by_sale(resale_params) except Exception, e: # handle exceptions here if client.is_success(): print 'Success, second id_sale: %s' % status['id_sale'] else: sys.exit('Error ID: ' + str(status["error"]["id_error"]) + '\n' \ 'Error number: ' + str(status["error"]["error_number"]) + '\n' \ 'Error description: ' + str(status["error"]["error_description"])) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | api.resaleSale(idSale, 99.99, "EUR", "Recurring billing product #1", new Callback<FraudSaleResult>() { @Override public void onFinish(FraudSaleResult result) { // success } @HandleException public void onProtocolError(ProtocolException e) { // invoke if not success // e.getCode() - error code // e.getMessage() - error message } @Override public void onError(Exception e) { // connection error etc. } }); |
Recurring payments are just resales performed periodically. It’s your choice whether you want to do this weekly, monthly or annually; it is also possible to perform a resale e.g. when a customer reaches a certain amount that should be paid.