Skip to main content
The Cashfree Custom Card Component lets you embed a secure, SDK-managed card input field directly into your React Native application UI. Because the CFCard component captures and processes the card number entirely within the SDK, your application never receives the raw card number. This makes the integration suitable for non-PCI merchants, that is, merchants who are not certified to store, process, or transmit raw cardholder data, and who rely on the SDK to handle card data securely on their behalf.
This page covers the custom card component integration only. For the full React Native Element integration, including raw card, net banking, and UPI Intent, see React Native 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 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, set up the card component and open the payment page so the customer can provide their card 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:
For iOS, run the following commands:

2. Complete the payment

To complete the payment, follow these steps:
  1. Create a CFSession object.
  2. Set up the payment callback.
  3. Create a card number UI component (CFCard).
  4. Build an ElementCard object and call doPayment() on the card component reference.

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).

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.

Create a card number UI component

Pass a cfSession object and a cardListener callback to CFCard. Both parameters are mandatory. CFCard also accepts standard React Native TextInput props so you can style and control the input field.
Create a reference for the card component so you can call doPayment() later:
Add the CFCard component to your view:
Card listener response
The cardListener callback is invoked on every key press. Until the customer enters 8 digits, the response contains only Luhn status and card length, because a minimum of 8 digits is required to identify the card BIN (Bank Identification Number).
From the 8th digit onwards, the callback also includes tdr_info, card_bin_info, and card_network:
tdr_info, card_bin_info, and card_network are only present after the customer has entered at least 8 digits. Always check that these keys exist before you access them.
Use the card_network value from the listener to update your UI. The following example shows how to map common networks:
Sample card form UI
Collect the remaining card fields (holder name, expiry, and CVV) in your own UI. The SDK manages only the card number through CFCard.

Build the ElementCard object and initiate payment

When the customer enters all details and taps the pay button, create an ElementCard object and call doPayment() on the card component reference. ElementCard does not include the card number. The SDK retrieves the card number from the CFCard component, which keeps your application out of PCI scope for card data.
Call doPayment() on the creditCardRef object, not on CFPaymentGatewayService. This is different from the raw card flow described in the React Native Integration page.
If you cannot create the order before rendering the card component, pass an initial session to CFCard for rendering, then call doPaymentWithPaymentSessionId() with the updated session when the customer pays:

Sample code

The following example shows a complete custom card component payment flow, including session creation, card component setup, listener handling, and payment initiation.

Sample GitHub code

You can explore a working integration example on GitHub: GitHub sample

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 the custom card component, verify that it behaves as expected. Follow these steps to test:
  1. Enter a test card number in the CFCard field and confirm that cardListener returns BIN metadata after the 8th digit.
  2. Enter the holder name, expiry, and CVV in your own input fields, then tap the pay button.
  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.