Prerequisites
Make sure that you have the following before you start:- An active Cashfree account. To create one, sign up on the Merchant Dashboard.
- Completed know your customer (KYC) verification and an active Payment Gateway account. For details, see Account activation.
- The Subscriptions product activated for your account. To request activation, contact your account manager or fill out the Support Form.
Choose an integration method
Decide how much of the mandate approval experience you want to build. The following table compares the two main methods:
You can also use the Subscription Element SDKs, which give you a native mobile interface while Cashfree processes the mandate. To create subscriptions without code, for sales-led billing or testing, use the Merchant Dashboard or a Subscription Payment Form.
If you’re not sure which method to use, start with Hosted Checkout. Choose seamless only if a redirect would harm your conversion or brand experience.
Integrate UPI AutoPay
Complete the following steps to build your integration:1
Get API keys and set up webhooks
Log in to the Merchant Dashboard and go to Payment Gateway > Developers > API Keys to get your test and production keys. For details, see Authentication.Then register your webhook endpoint and subscribe to the following events:
SUBSCRIPTION_STATUS_CHANGEDSUBSCRIPTION_AUTH_STATUSSUBSCRIPTION_PAYMENT_NOTIFICATION_INITIATEDSUBSCRIPTION_PAYMENT_SUCCESSSUBSCRIPTION_PAYMENT_FAILEDSUBSCRIPTION_PAYMENT_CANCELLED
SUBSCRIPTION_CONTROLLED_NOTIFICATION_STATUS and SUBSCRIPTION_CONTROLLED_EXECUTION_STATUS.Webhooks tell your system when a customer approves a mandate or a charge fails. If you miss them, your app can show an outdated status, such as a pending mandate that the customer already approved. Verify the signature of every webhook on your server before you act on it. For details, see Subscription webhook signature and Subscription webhooks.2
Create a plan
A plan defines the billing rules that the customer approves. When you create it, choose the following:
- Plan type:
PERIODIC, where Cashfree raises each charge on a schedule, orON_DEMAND, where you raise each charge yourself. - Amount: A fixed recurring amount for periodic plans, or a maximum amount for on-demand plans.
POST /pg/plans). For the plan fields, see Plans.3
Create the subscription and get it authorised
Link a customer to the plan with the Create Subscription API (
POST /pg/subscriptions). The response returns a subscription_session_id. For Hosted Checkout, use it to open the Cashfree authorisation checkout. For seamless, pass it to the Raise a Charge or Create an Auth API with payment_type set to AUTH.The customer approves the mandate with their UPI PIN in their UPI app, through UPI Intent or a QR code. For the authorisation and subscription lifecycle, see Create a subscription.4
Charge the subscription
When the subscription is
ACTIVE, Cashfree raises charges for periodic plans on schedule. For on-demand plans, raise each charge with the Raise a Charge or Create an Auth API (POST /pg/subscriptions/pay), with payment_type set to CHARGE.Every UPI AutoPay charge follows the pre-debit notification and retry rules in UPI AutoPay rules and limits. Cashfree sends the pre-debit notification before each charge that needs one, and you receive the SUBSCRIPTION_PAYMENT_NOTIFICATION_INITIATED webhook. The debit runs at least 24 hours after the notification succeeds. Test charges also wait 24 hours, so raise them a day ahead, or use the Simulate Payment API.To send pre-debit notifications and trigger debits yourself, see Merchant-controlled charging. For charge cut-off times, see Charge a subscription.You can’t change the amount or expiry of an active mandate directly. To charge a different amount on a periodic subscription, create a plan with the new amount and apply it with the CHANGE_PLAN action.5
Manage and reconcile subscriptions
Manage active subscriptions from the Merchant Dashboard or with the Manage Subscription API (For more details, see Manage subscriptions.
POST /pg/subscriptions/{subscription_id}/manage). The following table describes each action:PAUSE and CHANGE_PLAN aren’t supported for on-demand subscriptions.API reference
The following table lists the APIs you use most often:
For full schemas, headers, and error responses, see the Subscriptions API overview. To try the APIs, use the Postman collection.
Test and go live
Test end to end in the sandbox environment (https://sandbox.cashfree.com/pg) before you go live.
Sandbox testing checklist
Use this checklist to track your sandbox testing.Have you tested mandate creation and a simulated UPI PIN approval in the sandbox environment?
Have you tested mandate cancellation and a customer declining the mandate?
SUBSCRIPTION_STATUS_CHANGED and SUBSCRIPTION_AUTH_STATUS webhooks.Have you tested the first charge and verified its webhook?
SUBSCRIPTION_PAYMENT_SUCCESS.Have you tested a charge that fails for insufficient funds?
Have you implemented and tested webhook signature verification?
Go-live checklist
Use this checklist to confirm that you’re ready to switch to production.Has Cashfree approved your KYC?
Is Subscriptions activated in your production account?
Have you added your production API keys to your environment configuration?
Have you updated your webhook URLs to your live HTTPS endpoint?
Have you mapped your error handling to the subscription error codes?
Troubleshooting
The following table explains the subscription statuses that most often need attention after authorisation, and what to do for each:
For all statuses, see Subscription lifecycle. For error codes, see Subscription error codes.