API for Recurring Payment

If you have your own system and wish to integrate it to senangPay for recurring payments, you will first need to add your products into senangPay. The products need to be created first for auditing purposes. Recurring payments are not available for merchants who subscribe to the senangPay x Stripe package (legacy package).

To start, we will need the information 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, 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.

Getting the Recurring ID

The Recurring ID is a unique identifier for your recurring payment product. To obtain it, you'll need to first create a recurring payment product in the senangPay dashboard.

Here’s a step-by-step guide:

1. Create a new product

  • Navigate to Menu > Product > Create New in your senangPay dashboard.

2. Set up the recurring product:

3. Find the Recurring ID:

  • After creating the recurring product, go to the product details page.

  • Scroll down to the Payment Frequency Setting section.

  • Locate the Recurring ID under the Recurring Type heading.

Parameters to send to senangPay

Below are the details of the elements in the table:

Item
Detail

order_id

Identifies the shopping cart when redirecting after payment. Maximum length is 100 characters.

  • Allowed: A-Z, a-z, 0-9, and dash (-)

  • Example: 3432D4.

recurring_id

Identifies which recurring product/item senangPay processes.

hash

Ensures data integrity between the merchant’s cart and senangPay. Refer to the "How to generate a secure hash" section for details.

name

Adds the customer's name automatically. This is optional and can be edited.

email

Populates the customer's e-mail for them. This is optional and can be edited.

phone

Inserts the customer's phone number. This is optional and adjustable by the customer.

API for recurring payment

post
Path parameters
merchantIDstringRequired

Retrievable from senangPay dashboard

Example: 14222653788472
Body

Request parameters to use recurring API

order_idstringOptional

Unique Order ID, max length 100.

Example: 3432D4
recurring_idstringOptional

Recurring product/item ID retrievable from senangPay dashboard.

Example: 1534997305
hashstringOptionalExample: a8167dd09f01ebed0b18e67b2cc2424a0d058ccc83d94803482ecdeedff7728f
namestringOptional

Customer's name.

Example: Abu Bin Ali
emailstringOptional

Customer's email.

Example: [email protected]
phonestringOptional

Customer's phone number.

Example: 123456789
Responses
302
Redirects to SenangPay's payment page.
post
<?php

  $curl = curl_init();

  curl_setopt_array($curl, array(
    CURLOPT_URL => 'https://api.sandbox.senangpay.my/recurring/payment/{merchantID}',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => 'order_id=ORD12345&recurring_id=172500523839&hash=7b05df018a4f1235d3b6b18d49ea96abfa6f6b686d56c0b2b664fcb7445bd4d0&name=Amir&email=amir%40email.com&phone=123456789',
    CURLOPT_HTTPHEADER => array(
      'Content-Type: application/x-www-form-urlencoded',
    ),
  ));

  $response = curl_exec($curl);

  curl_close($curl);
?>
302

Redirects to SenangPay's payment page.

No content

*The "Test it" option is available when using Firefox or Safari to test the API.

Handling 'Return' and 'Callback' from senangPay

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 ‘Information Required’ section

Below are the details of the elements in the table:

Item
Detail

status_id

Indicates payment status

  • 1 for success

  • 0 for failure

  • 3 for pending (first recurring payment only)

order_id

Identifies the order sent to senangPay, linking the transaction to your application.

msg

Describes the payment status. Maximum length is 100 characters. Replace underscores with spaces when displaying to customers.

  • Example: "Payment_was_successful."

transaction_id

senangPay's unique transaction ID. Max 100 characters.

  • Example: 14363538840.

Use it to track transactions in senangPay.

hash

Ensures data integrity from senangPay to your shopping cart. Refer to the "How to verify secure hash" section for details.

3. Callback: The parameter will be sent via POST method.

Last updated