Skip to main content

Create Subscription Link API

Create a Subscription link#

The following endpoint creates a Subscription Link:

/subscriptions

Request parameters#

Following are the parameters to be sent in the request body:

Fieldis required?Description
subscription_ref_idoptionalstring The subscription_ref_id is upstream id from merchant
namemandatorystring The name associated with the Plan or Package Name
billing_periodoptionalstring The billing_period for subscription can be monthly/weekly/annually/daily, default value is monthly
billing_period_countoptionalinteger The billing_period_count for subscription.For example, If billing_period is set for Monthly and billing_period_count is set as 2, then charge will be made every 2 months, default value is 1
grace_periodoptionalstring The grace_period for subscription can be terminate/ignore/monthly/hourly/weekly/daily. default value is 24 hours . terminate if the subscription was not paid after the due date, the subscription will end immediately And ignore if the subscription was not paid after the due date, the subscription will continue and status remain active.Grace Period should be less than Billing period
grace_period_countoptionalinteger The grace_period for subscription has to be zero for grace_period terminate/ignore & non zero in case of grace_period as monthly/hourly/weekly/daily.for example, if grace_period is set for Monthly and grace_period_count is set as 2, then charge will be made every 2 months
pricemandatorystring The price for a single subscription plan
qtymandatorystring The quantity of subscription plan, total amount will be price * qty
billing_cycle_countoptionalinteger The billing_cycle_count refers number of cycle amount will be charged for fixed cycle. for forever subscription billing_cycle_count is zero default 0
started_atmandatorystring The started_at associated with start date for subscription plan which should be current date or greater
charge_typemandatorystring The charge_type can be manual or automatic (only available for credit card)
notesoptionalstring The note from the merchant
emailmandatorystring The email refers to customer email
mobilemandatorystring The mobile refers to customer mobile
given_namemandatorystring The given_name refers to customer first name
middle_nameoptionalstring The middle_name refers to customer middle name
sur_nameoptionalstring The sur_name refers to customer last name

Example#

curl -u <YOUR_SECRET_KEY> \
-X POST 'https://api.durianpay.id/v1/subscriptions' \
-H 'Is-live: true' \
-H 'Content-Type: application/json' \
-d '{"plan":
{
"subscription_ref_id": "merchant_sub_ref_id",
"name": "Plan/Package Name",
"billing_period": "monthly",
"billing_period_count": 1,
"grace_period": "terminate",
"grace_period_count": 0,
"price": "20000",
"qty": "2"
},
"customer": {
"email": "jude.casper@durianpay.id",
"mobile": "+628978678511",
"given_name": "Jude",
"middle_name": "",
"sur_name": "Casper"
},
"billing_cycle_count": 10,
"started_at": "2021-09-30T12:58:38.210535Z",
"charge_type": "manual",
"notes": "a long notes"
}'

Response#

{
"data": {
"id": "sub_7HAtpFqE7g0944",
"plan": {
"id": "sub_plan_HQYXw2LQlz3333",
"name": "Plan/Package Name",
"billing_period": "monthly",
"billing_period_count": 1,
"grace_period": "terminate",
"grace_period_count": 0,
"price": "20000",
"qty": "2",
"amount": "40000.00",
"subscription_ref_id": "merchant_sub_ref_id"
},
"customer": {
"id": "cus_g0tw6z7sDF4506",
"email": "jude.casper@durianpay.i",
"mobile": "+628978678511",
"given_name": "Jude",
"middle_name": "",
"sur_name": "Casper"
},
"status": "wait_for_payment",
"started_at": "2021-10-01T12:58:38.210535Z",
"next_due_at": "2021-10-01T12:58:38.210535Z",
"subscription_orders": [
{
"billing_period": 1,
"order_id": "ord_A2xXH1YkMU7183",
"status": "unpaid"
}
],
"charge_type": "manual",
"link": "https://links.durianpay.id/subscription-link/b6hRzb"
}
}

Error Response Code : 400#

{
"error": "required fields missing",
"error_code": "DPAY_INVALID_REQUEST",
"request_id": "dp_Adu5tmGx3J4567",
"errors": [
{
"field": "name=\"name invalid\"price=\"price invalid\"quantity=\"quantity invalid\"",
"message": "Please provide valid subscription data"
},
{
"field": "mobile=\"mobile invalid\"given_name=\"given_name invalid\"email=\"email invalid\"",
"message": "Please provide valid subscription customer data"
}
]
}

Error Response Code : 500#

{
"error": "error in creating subscription",
"error_code": "DPAY_INTERNAL_ERROR"
}