Skip to main content
The Cashfree Subscription Element SDK lets you build a fully custom subscription payment experience within your React Native application. Unlike the hosted checkout, you collect payment details directly in your own UI and pass them to the SDK, giving you complete control over the appearance and behaviour of your payment flow. The SDK supports three payment methods for subscriptions: card, UPI, and eNach (electronic National Automated Clearing House, also known as net banking). It runs on both Android and iOS from a single integration.

Prerequisites

Complete the following tasks before you start the integration:
  • Create a Cashfree Merchant Account.
  • Log in to the Merchant Dashboard and generate an App ID and Secret Key. Learn how to generate API keys.
  • Use Cashfree React Native SDK version 2.4.0 or above. Get it from npm.
  • Set your Android application’s minSdkVersion to API level 19 or higher.
  • Set your iOS minimum deployment target to 13.0 or higher.
The integration consists of three steps:

Step 1

Create a subscription

Step 2

Open the payment page

Step 3

Confirm the payment

Step 1: Create a subscription Server-side

Create a subscription from your backend server before you process any payment.
This API requires your secret key. Create subscriptions through your server only — do not call this API directly from your mobile application.
After the subscription is created, your backend receives a subscription_id and a subscription_session_id. Pass both values to your React Native client to proceed with the payment.
The following example shows how to create a subscription using the Create Subscription API:
A successful response returns the subscription_id and subscription_session_id. Use these values to build the CFSubscriptionSession object in Step 2. The API returns the following response on success:
For the full list of request parameters and response fields, see the Create Subscription API.

Step 2: Open the payment page Client-side

After you create the subscription, open the payment page so the customer can provide payment details.

1. Set up the SDK

The React Native SDK is hosted on npm. You can get the SDK 2.4.0. The React Native SDK supports Android SDK version 19 and above and iOS minimum deployment target of 13.0 and above. Install the SDK in your React Native project:

Android configuration

Add the following entry inside the <application> tag in your Android manifest file. If you do not enable the cashfree_subscription_flow_enable flag, the SDK will not provide a payment callback.
Add this entry inside the <application> tag, not inside the <activity> tag.

iOS configuration

Update your iOS deployment target in your Podfile to 13.0 or higher:
Run pod install to install the dependency:
To provide UPI payments on iOS, add the following to your application’s info.plist file:

2. Select a payment method

The Subscription Element SDK supports the following payment methods:
In this flow, the customer enters their card details directly in your application UI. The SDK securely processes the card payment and initiates the subscription mandate.

3. Complete the payment

To complete the payment, follow these steps:
  1. Create a CFSubscriptionSession object.
  2. Create the payment object for the selected payment method.
  3. Set up the subscription callback.
  4. Initiate the payment using makeSubsPayment().

Create a session

The CFSubscriptionSession object holds the session context for the payment. It accepts the subscription_session_id and subscription_id obtained from Step 1, and the Cashfree environment (CFEnvironment.SANDBOX or CFEnvironment.PRODUCTION). The following example shows how to create the session object:

Create a payment object

The SDK provides a dedicated payment class for each supported payment method. Build only the object that corresponds to the payment method your customer has selected.
Use the following code to create a card payment object:

Set up the subscription callback

The SDK exposes a callback interface to receive callbacks when the subscription payment journey ends. The callback supports two methods:
Register the callback before calling makeSubsPayment(). Set it in componentDidMount and remove it in componentWillUnmount to handle activity restarts correctly and prevent memory leaks.
The following example shows how to register the callback:
Backend verification is mandatory. The SDK signals that the payment UI flow ended, not that payment succeeded. Always verify payment status from your backend before presenting success.

Initiate the payment

Call makeSubsPayment() to open the payment screen when the customer taps the pay button. Pass the payment object for your selected payment method.

Sample code

The following example shows a complete card payment flow, including session creation, payment object setup, callback registration, and payment initiation.
The following method demonstrates a complete card payment integration:
Refer to the sample integration on GitHub for a working end-to-end implementation.
This SDK is compatible with the Expo framework. For a sample implementation, see the Expo sample on GitHub.

Step 3: Confirm the payment Server-side

After the SDK delivers a callback via onVerify, confirm the payment status from your backend before taking any action. The SDK callback signals only that the payment flow has ended. It does not guarantee a successful payment. Use the Fetch Details of All Payments of a Subscription API to retrieve the current payment status.
The following request fetches all payments for a subscription:
A successful response returns an array of payment objects. Check the payment_status field to determine the outcome. The API returns the following response on success:
Always verify the subscription status from your backend before delivering goods or services to the customer. Proceed only when payment_status is SUCCESS.

Error codes

If a required field or object is missing when you initiate payment, the SDK throws an error. The following table lists SDK-level validation errors and when they occur.
The SDK validation errors are grouped by category as follows:

Session errors

These errors occur when the CFSubscriptionSession object or its required fields are not provided.

Payment method object errors

These errors occur when a payment method object is absent or one of its required fields is not set.

Callback errors

These errors occur when the payment callback is not registered before initiating payment.