Recurring API

A. API for Recurring Payment

If you have your own system and wish to integrate it to senangPay for recurring payments you will need to first add your product into senangPay. The product needs to be created first for auditing purposes.

Below are the details and steps required.

 

B. Info required

To start, we will need the information as below. These can be retrieved from the senangPay Dashboard.

1. Go to Menu > Settings > Profile

2. Refer to the Shopping Cart Integration Link section. Get your Merchant ID and Secret Key information.

3. Then you will need to fill in the Recurring Return URL. This is the URL where senangPay will redirect the buyer to after the payment has been processed.

4. Next, you need to fill in the Recurring Callback URL. Recurring Callback URL is used as an alternative notification to the merchant shopping cart in case there is a breakdown in the transaction flow. For more info on Callback URL, read here.

 

C. Getting the Recurring ID

Recurring id is the unique id that identifies your recurring product. To obtain the recurring id, you must first create a recurring product in senangPay dashboard.

1. Go to Menu >Product > Create New

2. Creating a recurring product. You can learn more on how to create a recurring product here at these links.

3. Once the recurring product has been created, view the product details page, scroll down to Payment Frequency Setting section. The Recurring Id is located under Recurring Type.

D. Parameters to send to senangPay

Below are the details of the elements in the table:

ItemDetail
order_idThis is the id used to identify the shopping cart when senangPay redirects the buyer back after the payment was made. The maximum length is 100 characters. Example 3432D4. Only A to Z, a to z, 1 to 0 and dash allowed.
recurring_idThis is the id used to identify which recurring product/item senangPay needs to process.
hashThis is the data to ensure that data integrity has passed from the merchant’s shopping cart to senangPay. Refer to ‘How to generate the secure hash’ section for more info.
nameThis is the name to populate in the payment form so that customers do not have to key in their names. This is optional and does not have to be a part of the hash. Customers are able to overwrite the value in the payment form.
emailThis is the email to populate in the payment form so that customers do not have to key in their emails. This is optional and does not have to be a part of the hash. Customers are able to overwrite the value in the payment form.
phoneThis is the phone number to populate in the payment form so that customers do not have to key in their phone. This is optional and does not have to be a part of the hash. Customers are able to overwrite the value in payment form.

 

E. How to send the parameters to senangPay (Live)

1. The parameters can be sent either using GET or POST method.

2. The URL is :

https://api.senangpay.my/recurring/payment/

followed by your merchant ID.

3. Example :

https://api.senangpay.my/recurring/payment/14222653788472

 

F. How to send the parameters to senangPay (Sandbox)

1. The parameters can be sent either using GET or POST method.

2. The URL is

https://api.sandbox.senangpay.my/recurring/payment/

followed by your merchant ID.

3. Example:

https://api.sandbox.senangpay.my/recurring/payment/14222653788472

 

G. What Parameters does the shopping cart receive from senangPay

Below are the details of the elements in the table:

ItemDetail
status_idThis is to indicate the status of the payment. It only has 2 values which are 1 for successful and 0 for failed.
order_idThis is the order that was sent to senangPay. This is to identify the transaction generated from your application.
msgThis is the message to describe the payment status. The maximum length is 100 characters. Take note that the message may contain underscores. You can replace the underscore as space when displaying the message to your customer. Example Payment_was_successful.
transaction_idThis is the transaction ID used by senangPay. You can use this ID to track the transaction in senangPay. The maximum length is 100 characters. Example 14363538840
hashThis is the data to ensure that data integrity has passed from senangPay to the merchant’s shopping cart. Refer to the section ‘How to verify if the secure hash’ is correct for more information.

137x22xspace.png.pagespeed.ic.IoAxAisfVW
H. How senangPay sends the parameters to merchant’s shopping cart

1. The parameters will be sent using GET method.

2. The parameters are sent to URL as configured in the Recurring Return URL. Refer to ‘Info Required’ section.

137x22xspace.png.pagespeed.ic.IoAxAisfVW
I. How to generate the secure hash

1. The secure hash is generated by using sha256 on a string consisting of (according to sequence):

  • Secret Key
  • Recurring ID
  • Order ID

2. For example if the values for the parameters are as in PHP  shown below: 

?php

$secret_key = '21245-957';
$recurring_id = '1234';
$order_id = '12';

$hash = hash('sha256',$secret_key.$recurring_id.$order_id);

?>

3. So, the string to be hashed is 21245-957123412, which will generate the hash values of:

  • a8167dd09f01ebed0b18e67b2cc2424a0d058ccc83d94803482ecdeedff7728f

J. How to verify if the secure hash is correct

1. Merchansts will need to generate the secure hash and compare the secure hash that was received from senangPay.

2. For example, if the parameters received from senangPay are as in PHP shown below:

$status_id = '1';
$order_id = '12';
$transaction_id = '14363538840';
$msg = 'Payment_was_successful';

$hash = hash('sha256',$secret_key.$status_id.$order_id.$transaction_id.$msg);

?>

3. So, the string to be hashed is 21245-95711214363538840Payment_was_successful, which will generate the hash values of:

  • 24354422953c29bf4b822f6783bbaf64ef445623d6e8ea4ddc1582a29c03cda0

4. Now you need to compare the hash value that you have generated with the hash value sent from senangPay. If the value does not match then the data may have been tampered with.

 

K. Download sample code

For your refference, please refer to this sample code. Kindly download from here.