Skip to main content
The Cashfree Payment Gateway Element SDK lets you build a fully custom 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 look and feel of your payment flow. The SDK supports three Element payment methods: card (including saved card), net banking, and UPI Intent. It runs on both Android and iOS from a single integration.
This page describes the raw card flow, where your application collects the card number directly and is responsible for PCI DSS (Payment Card Industry Data Security Standard) compliance. To avoid handling raw card numbers, use the React Native Custom Card Component instead, which captures the card number inside an SDK-managed input field.

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 10.3 or higher.
The integration consists of three steps:

Step 1

Create an order

Step 2

Open the payment page

Step 3

Confirm the payment

Step 1: Create an order Server-side

Create an order from your backend server before you process any payment.
This API requires your secret key. Create orders through your server only. Do not call this API directly from your mobile application.
API request for creating an order
Here’s a sample request for creating an order using your desired backend language. Cashfree offers backend SDKs to simplify the integration process.
After successfully creating an order, you will receive a unique order_id and payment_session_id that you need for subsequent steps. You can view the complete API request and response for /orders in the Create Order API.

Step 2: Open the payment page Client-side

After you create the order, 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 10.3 and above. Install the SDK in your React Native project:

iOS configuration

To provide UPI payments on iOS, add the following to your application’s info.plist file:
For iOS, run the following commands:

2. Select a payment method

The Element SDK supports the following payment methods:
In this flow, the customer enters their card details directly in your application UI. Your application receives the raw card number and passes it to the SDK, so your application remains in PCI DSS scope for card data. To avoid handling raw card numbers, use the React Native Custom Card Component instead. You can also charge a previously saved card by passing the saved card instrument ID and CVV.

3. Complete the payment

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

Set up the payment callback

The SDK exposes a CFCallback interface to receive callbacks from the SDK once the payment flow ends. The callback supports two methods:
Set the callback in componentDidMount and remove it in componentWillUnmount. This configuration also handles activity restart cases and prevents memory leaks.
Always call setCallback before calling makePayment.

Create a session

The CFSession object holds the session context for the payment. It accepts the payment_session_id and order_id obtained from Step 1, and the Cashfree environment (CFEnvironment.SANDBOX or CFEnvironment.PRODUCTION).

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. Card objects can be of two types: Card for a new card payment, and SavedCard for a previously saved instrument.
Use the following code to create a card payment object. This is the raw card flow. Your application passes the full card number to the SDK.

Initiate the payment

Call makePayment() to open the Cashfree payment flow for the selected method. Pass the payment object you created in the previous step (CFCardPayment, CFNBPayment, or CFUPIPayment).
doCardPayment() is deprecated. Use makePayment() for card, net banking, and UPI Element payments.

Sample code

The following example shows a complete integration, including session creation, payment object setup for each method, and payment initiation.

Sample GitHub code

You can explore a working integration example on GitHub: GitHub sample Sample UPI Test APK

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. To verify an order you can call our /pg/orders endpoint from your backend. You can also use our SDK to achieve the same.
Always verify the order status from your backend before you deliver goods or services to the customer. You can use the Get Order API for this. An order is successful when the order_status is PAID.

Testing

After you integrate a payment method, verify that it behaves as expected. Follow these steps to test:
  1. Trigger a payment using each method you have integrated.
  2. Confirm that the SDK opens the correct payment screen for the method (Cashfree’s hosted card or net banking screen, or the selected UPI app).
  3. Confirm that onVerify or onError is called when the payment flow ends.
Use the sandbox environment to test payments before you go live.

Error codes

To confirm the error returned in your React Native application, you can view the error codes exposed by the SDK.
The following are some of the error codes that are exposed by the SDK:

Affiliate partner program

As a developer building payment experiences for your clients, you can earn additional income while providing them with industry-leading payment solutions.

Join the Cashfree affiliate partner program and get rewarded every time your clients use Cashfree.

What you get:

  • Earn up to 0.25% commission on every transaction.
  • Become a trusted fintech partner for your clients.
  • Access to a dedicated partner manager for expert support.

What your clients get:

  • Instant activation and go live in minutes.
  • Industry-best success rate across all payment modes.
  • Effortless acceptance of international payments in 140+ currencies.

Get started today. Become a partner now.