Create Subscription Link API
Request parameters
Following are the parameters to be sent in the request body:
Field | is required? | Description |
---|---|---|
subscription_ref_id | optional | string The subscription_ref_id is upstream id from merchant |
name | mandatory | string The name associated with the Plan or Package Name |
billing_period | optional | string The billing_period for subscription can be monthly/weekly/annually/daily, default value is monthly |
billing_period_count | optional | integer 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_period | optional | string 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_count | optional | integer 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 |
price | mandatory | string The price for a single subscription plan |
qty | mandatory | string The quantity of subscription plan, total amount will be price * qty |
billing_cycle_count | optional | integer 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_at | mandatory | string The started_at associated with start date for subscription plan which should be current date or greater |
charge_type | mandatory | string The charge_type can be manual or automatic (only available for credit card) |
notes | optional | string The note from the merchant |
mandatory | string The email refers to customer email | |
mobile | mandatory | string The mobile refers to customer mobile |
given_name | mandatory | string The given_name refers to customer first name |
middle_name | optional | string The middle_name refers to customer middle name |
sur_name | optional | string The sur_name refers to customer last name |
Example
curl -X POST \
https://api.durianpay.id/v1/subscriptions \
-H 'authorization: [Base64({Your_Server_Key}:)]' \
-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": "2022-09-30T12:58:38.210535Z",
"charge_type": "manual",
"notes": "a long notes"
}'
Response Code : 200
Here is an example of success 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
Here is an example error response for invalid request
{
"error": "required fields missing",
"error_code": "DPAY_INVALID_REQUEST",
"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 : 401
Here is an example error response for unauthorized access
{
"error": "invalid Authorization header in request",
"error_code": "DPAY_UNAUTHORIZED_ACCESS"
}
Error Response Code : 500
Here is an example error response for internal server error
{
"error": "error in creating subscription",
"error_code": "DPAY_INTERNAL_ERROR"
}