Integrate the Cashfree Payment Gateway Cordova SDK to add web checkout and UPI Intent flows to your hybrid Cordova or Capacitor app on Android and iOS.
Cashfree’s Cordova SDK provides a payment solution that integrates the payment gateway into your Cordova and Capacitor applications, supporting both Android and iOS platforms. The SDK offers multiple checkout flows including web checkout and UPI Intent checkout.
This document includes instructions for both Cordova and Capacitor SDK integrations.
Ensure your application complies with Cashfree’s Integrity standards. Applications that don’t meet the required integrity standards may be restricted from using production services.
The Cordova integration consists of three essential steps:
Step 1
Create an order
Step 2
Open the checkout page
Step 3
Confirm the payment
The step-by-step guide for each step of the integration process is as follows:
To integrate the Cashfree Payment Gateway, you must first create an order. Complete this step before you process any payments. Configure an endpoint on your server to handle order creation. You can’t call this API from the client-side.
Create orders through your server as this API requires your secret key. Don’t call it 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.
import { Cashfree, CFEnvironment } from "cashfree-pg";const cashfree = new Cashfree( CFEnvironment.PRODUCTION, "{Client ID}", "{Client Secret Key}");function createOrder() { var request = { order_amount: "1", order_currency: "INR", customer_details: { customer_id: "node_sdk_test", customer_name: "", customer_email: "example@gmail.com", customer_phone: "9999999999", }, order_meta: { return_url: "https://test.cashfree.com/pgappsdemos/return.php?order_id=order_123", }, order_note: "", }; cashfree .PGCreateOrder(request) .then((response) => { var a = response.data; console.log(a); }) .catch((error) => { console.error("Error setting up order request:", error.response.data); });}
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 /ordershere.
The Cordova SDK is hosted on npm. You can download the latest version 1.0.12. The Cordova SDK supports Android SDK version 19 and above and iOS minimum deployment target of 11 and above.
Capacitor SDK: The code snippet below also includes Capacitor SDK integration instructions.
Navigate to your project and run the following command:
npm install cordova-plugin-cashfree-pg# or install with latest tagnpm install cordova-plugin-cashfree-pg@latest# Add Plugincordova plugin add cordova-plugin-cashfree-pg# With Ionic Cordova platformionic cordova plugin add cordova-plugin-cashfree-pg
# Install with capacitor tagnpm install cordova-plugin-cashfree-pg@capacitor# Ionic Capacitor setup# Install Core library (once per project)npm install @awesome-cordova-plugins/core# Install Awesome Cordova Plugins TypeScript wrapper for CashFree PGnpm install @awesome-cordova-plugins/cashfree-pg# Update native platform project(s) to include newly added pluginionic cap sync
The Cordova SDK offers the following payment flows:
Web Checkout
In this flow, the SDK provides a webview-based checkout implementation to facilitate a quick integration with the payment gateway. Your customers can fill in the necessary details in the web page and complete the payment.
This mode handles all the business logic and UI components to make the payment smooth and easy to use.
UPI Intent Checkout
This flow is for merchants who want to provide UPI Intent functionality using Cashfree’s mobile SDK. In this flow, the SDK provides a pre-built native Android screen to facilitate integration with the payment gateway. Your customers see a list of UPI apps installed on 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 you to customise the UI in terms of colour coding and fonts.
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).
let session = { payment_session_id: "payment_session_id", orderID: "order_id", environment: "SANDBOX", //"SANDBOX" or "PRODUCTION"};
Cashfree doesn’t currently provide a dedicated SDK for the Capacitor framework. However, a Capacitor plugin has been developed that acts as a wrapper over the Cordova SDK. See the sample Capacitor app.
Once the payment is completed, you need to confirm whether the payment was successful by checking the order status. Once the payment finishes, the user will be redirected back to your activity.
You must always verify payment status from your server. Before delivering the goods or services, ensure you check the order status from your server and verify it from your server endpoint.
To verify an order you can call our /pg/orders endpoint from your backend. You can also use our SDK to achieve the same.
To confirm the error returned in your application, you can view the error codes that are exposed by the SDK.
Click to show error codes
The following are some of the error codes that are exposed by the SDK:
Error codes
Message
MISSING_CALLBACK
The callback is missing in the request.
ORDER_ID_MISSING
The “order_id” is missing in the request.
CARD_EMI_TENURE_MISSING
The “emi_tenure” is missing or invalid (It has to be greater than 0).
INVALID_UPI_APP_ID_SENT
The id sent is invalid. The value has to be one of the following: “tez://”,“phonepe://”,“paytm://”,“bhim://. Please refer the note in CFUPI class for more details
INVALID_PAYMENT_OBJECT_SENT
The payment object that is set doesn’t match any payment mode. Please set the correct payment mode and try again.
WALLET_OBJECT_MISSING
The CFWallet object is missing in the request
NETBANKING_OBJECT_MISSING
The CFNetbanking object is missing in the request.
UPI_OBJECT_MISSING
The CFUPI object is missing in the request.
CARD_OBJECT_MISSING
The CFCard object is missing in the request.
INVALID_WEB_DATA
The url seems to be corrupt. Please reinstantiate the order.
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.
CHANNEL_MISSING
The “channel” is missing in the request.
CARD_NUMBER_MISSING
The “card_number” is missing in the request.
CARD_EXPIRY_MONTH_MISSING
The “card_expiry_mm” is missing in the request.
CARD_EXPIRY_YEAR_MISSING
The “card_expiry_yy” is missing in the request.
CARD_CVV_MISSING
The “card_cvv” is missing in the request.
UPI_ID_MISSING
The “upi_id” is missing in the request
WALLET_CHANNEL_MISSING
The “channel” is missing in the wallet payment request
WALLET_PHONE_MISSING
The “phone number” is missing in the wallet payment request