A subscription comprises three parts:
product name
price
id
field referring to SKU
is an optional field, but if provided, it will be considered unique for a merchant and can't be added to another product object.In the case of updating product prices, the plans and subscriptions associated with the products won't be updated automatically.
Update Subscription API
will need to be called to update the price of each product for a subscription.{
"payment": {
"latest_product_price": true
},
"product": [
{
"name": "Ali",
"product_id": "xpay_product_90e8c92b774641adad16325722fe8c20",
"quantity": 1
},
{
"name": " Raza",
"product_id": "xpay_product_e302a0a0ec984e18aadd09e296323c8c",
"quantity": 1
}
],
}
A plan is a schedule defining how merchants intend to collect recurring payments.
interval
, every
, etc.Interval |
---|
day |
week |
month |
year |
Update Subscription API
with Plan ID to update individual subscriptions.{
"plan_id": "xpay_plan_6f51cae83bbb45bd8588fe0c95e4c2b6"
}
If plan_id is added, it will update the latest billing cycle, products, and payment from the plan ID and override any such value being added in the payload.
<aside> 💡 To update a subscription's pricing, billing cycle, etc., kindly refer to Update a Subscription’s Schedule / Payment.
</aside>
By default, the price of each product will add up to the plan price. However, XPay supports manually adding amounts and currencies if pricing needs to be changed based on frequency, etc. In this case, the Create Plan API
expects the amount: number
and currency: string
to be passed.
start_date
, plan_id
, timezone
, and payment_token
need to be mentioned.<aside> ⚠️ The subscription is not created at the customer level but at the plan level. If different plans are offered to different customers, then merchants will save those plans in their system.
</aside>
Status | Reason |
---|---|
inactive |
Payment Failed |
paid |
Payment successful |
draft |
Created but no action performed |
For every recurring payment, XPay will create an invoice
.
paid
but the third one fails.start_date
and plan
provided.This is the use case where
The merchant can do this if the Payment Method token doesn’t exist.
confirmPayment()
SDK to authenticate, authorize, and collect payment method tokens.Create Subscription API
and collect_advance: false
to be set. XPay will create a subscription and start collecting recurring payments as per the schedule.The payment method token needs to be provided before creating a subscription.
After a successful payment, the payment method token will be provided in the SDK response and webhook.
If the merchant already has a payment method, it can be provided while creating a subscription.
start_date
is an upcoming date, the subscription will be attempted on that date, and the status will be changed from the draft
.If the payment method token doesn't exist, then there are two approaches:
The merchant will follow the same steps as normal payment but modify the Create Payment Intent API
payload, add reason: “token”
in the metadata and subscription
object in the payload to specify subscription payment, and be provided with a payment method token.
subscription_create
webhook.amount
and currency
can't be added here, but those from the plan will be used.// Create PI API Payload
{
"payment_method_types": "card",
"customer": {
"name": "",
"email": "",
"phone": ""
},
"shipping": {
"address1": "",
"city": "",
"country": "",
"zip": "",
"shipping_method": ""
},
"metadata": {
"order_reference": "",
"reason": "token"
},
"subscription": {
"plan_id": "xpay_plan_d081b7f5e8e74c37938597ee7e8cf444",
"start_date": "2024-06-30T10:55:00Z",
"timezone": "Asia/Karachi"
//rest of the subscription payload which you want to add
}
}
reason: "token”
in the Create PI API with a regular payload, and the payment method token will be provided in the SDK response and payment webhook.
Create Subscription API
, and add this key value in payload collect_advance: false
. Here, XPay will not make a payment attempt to create a subscription.<aside>
💡 The default configuration is collect_advance: false
.
</aside>
collect_advance: true
on creating a new subscription?collect_advance: true
is added to the Create Subscription API
, a couple of use cases need to be handled.
failure_action
will be handled accordingly.<aside>
🚧 Create Subscription API
is not idempotent at the moment ****and if you have set ****failure_action: "CONTINUE"
and attempt it twice, it will create two subscriptions.
</aside>
unskipped
before the invoice's payment date.inactive
subscription. However, the merchant can specify in the config to allow and override the default behavior.paused
.start_date
specified.active
status.inactive
status earlier, the merchant will manually charge the unpaid invoice(s) via the Pay Invoice API
.cancelled
.inactive
subscription. However, the merchant can specify in the admin config to override the default behavior.