React Native Integration
Learn more about integrating Cashfree SDK in your react native app
Cashfree’s integrity standards
Before proceeding with the SDK integration, please ensure that your application complies with Cashfree’s Integrity. Applications that don’t meet the required integrity standards may be restricted from using production services.
For further guidance, refer to the Cashfree Integrity.
Setting up SDK
The React Native SDK is hosted on npm. You can get the sdk here.
Our React Native SDK supports Android SDK version 19 and above and iOS minimum deployment target of 10.3 and above.
Navigate to your project and run the following command:
iOS
Add this to your application’s info.plist
file.
Step 1: Creating an order
The first step in the integration is to create an Order. You can add an endpoint to your server which creates this order and integrate this server endpoint with your frontend.
Here’s a sample request for creating an order using your desired backend language. Cashfree offers backend SDKs to simplify the integration process.
You can find the SDKs here.
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 all the complete api request and response for /orders
here.
Step 2: Opening the payment page
Once the order is created, the next step is to open the payment page so the customer can make the payment. The React Native SDK offer below payment flow:
Web Checkout
Web Checkout
In this flow, SDK provides a webview based checkout implementation to facilitate a quick integration with our payment gateway. Your customers can fill in the necessary details in the web page and complete the payment. This mode also handles all the business logic and UI Components to make the payment smooth and easy to use.
UPI Intent Checkout
UPI Intent Checkout
This flow is for merchants who wants to quickly provide UPI Intent functionality using cashfree’s mobile SDK. In this flow, SDK provides a pre-built native Android screen to facilitate a quick integration with our payment gateway. Your customers will see a list of UPI apps installed in their phone which they can select to initiate payment. This mode handles all the business logic and UI Components to make the payment smooth and easy to use. The SDK allows the merchant to customize the UI in terms of color coding, fonts.
To complete the payment, we can follow the following steps:
- Create a
CFSession
object. - Set
payment callback
. - Initiate the payment
Create a session
This object contains essential information about the order, including the payment session ID (payment_session_id
) and order ID (order_id
) obtained from Step 1. It also specifies the environment (sandbox or production).
Set payment callback
The SDK exposes an interface CFCallback to receive callbacks from the SDK once the payment flow ends.
Initiate the payment
Web Checkout
Web Checkout
This object combines all the configurations into a single checkout configuration.
Finally, call doWebPayment()
to open the Cashfree checkout screen. This will present the user with the payment options and handle the payment process.
UPI Intent Checkout
UPI Intent Checkout
This flow is for merchants who wants to quickly provide UPI functionality using cashfree’s mobile SDK without handling other modes like Cards or Net banking.
Sample Code
Web checkout
Web checkout
UPI Intent Checkout
UPI Intent Checkout
Step 4: Confirming the payment
Once the payment is completed, you need to confirm whether the payment was successful by checking the order status. After payment user will be redirected back to your component.
To verify an order you can call our /pg/orders
endpoint from your backend. You can also use our SDK to achieve the same.
Testing
You should now have a working checkout button that redirects your customer to Cashfree Checkout.
- Click the checkout button.
- You’re redirected to the Cashfree Checkout payment page.
If your integration isn’t working:
Error codes
To confirm the error returned in your application, you can view the error codes that are exposed by the SDK.
Error Codes
Error Codes
ERROR CODES | MESSAGE | |
---|---|---|
MISSING_CALLBACK | The callback is missing in the request. | |
ORDER_ID_MISSING | The “order_id” is missing in the request. | |
SESSION_OBJECT_MISSING | The “session” is missing in the request | |
PAYMENT_OBJECT_MISSING | The “payment” is missing in the request | |
ENVIRONMENT_MISSING | The “environment” is missing in the request. | |
ORDER_TOKEN_MISSING | The “order_token” is missing in the request. |
Other options
(Optional) Enable logging to debugging issues
(Optional) Enable logging to debugging issues
If you are facing trouble while making a payment, you can take a look at the SDK debug logs to try and identify the issue. To enable SDK logging add the following to your values.xml file.
<integer name="cashfree_pg_logging_level">3</integer>
Following are the Logging levels.
- VERBOSE = 2
- DEBUG = 3
- INFO = 4
- WARN = 5
- ERROR = 6
- ASSERT = 7
(Optional) Disable Quick Checkout in Payment Page
(Optional) Disable Quick Checkout in Payment Page
If you want to disable quick checkout flow in Drop Payment flow you can add the following to your values.xml
file.
<bool name="cf_quick_checkout_enabled">false</bool>
(Optional) Add Custom Analytics subscriber
(Optional) Add Custom Analytics subscriber
From our Reacr SDK version 2.0.1 onwards, you can subscribe to the analytics events generated from our Drop checkout payment flow and push it to the analytics platform of your choice directly from your application.
If you want to enable this feature in Drop Payment flow you can add the following line to your values.xml file.
<bool name="cashfree_custom_analytics_subscriber_enabled">true</bool>
💻 Quick dev-to-dev talk
You clearly care about building better payment experiences for your clients, here’s a quick tip: Earn additional income doing exactly what you’re doing now!
Join the Cashfree Affiliate Partner Program and get rewarded every time your clients use Cashfree.
What’s in it for you?
- Earn up to 0.25% commission on every transaction
- Be more than a dev - be the trusted fintech partner for your clients
- Get a dedicated partner manager, your go-to expert
What’s in it for your clients?
- Instant activation, go live in minutes.
- Industry-best success rate across all payment modes.
- Effortlessly accept international payments in 140+ currencies
Ready to push to prod? 👉 Become a Partner now