Skip to main content
The Cashfree Payment Gateway Element SDK lets you build a fully custom payment experience within your Android 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 four payment methods: card, net banking, wallet, and UPI Intent.
This page describes the raw card flow, where your application collects the card number directly and is responsible for PCI DSS compliance. To avoid handling raw card numbers, use the Android Custom Card Component instead, which captures the card number inside an SDK-managed view.

Prerequisites

Complete the following tasks before you start the integration: 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 Cashfree Android SDK is available on Maven Central. The latest version is 2.5.0. The SDK requires Android API level 19 or higher. Add the following dependency to your app-level build.gradle file:

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 Android Custom Card Component instead.

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. Optionally, customise the theme.
  5. Initiate the payment using doPayment().

Set up the payment callback

The SDK exposes an interface CFCheckoutResponseCallback to receive callbacks from the SDK once the payment flow ends. This interface consists of two methods:
Register the callback in your activity’s onCreate method. This configuration also handles activity restart cases correctly.
The following example shows how to implement the callback in your activity:

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 (.SANDBOX or .PRODUCTION).

Create a payment object

The SDK provides a dedicated payment builder for each supported payment method. Build only the object that corresponds to the payment method your customer has selected.
Use the following builders to create a card payment object. This is the raw card flow — your application passes the full card number to the SDK using setCardNumber.
setChannel is a required field on the card builder. The SDK uses this value to determine how to process the card payment. Contact Cashfree Support to confirm the correct channel value for flows that require native OTP authentication.

Customise the theme (optional)

Apply a custom theme to the payment screen to match your application’s visual design. Use the CFTheme builder to set colours for the navigation bar, buttons, and text, then apply the theme to your payment object before you call doPayment().

Initiate the payment

Call doPayment() to open the Cashfree payment screen for the selected method. The example below uses cfCardPayment. Replace it with cfNetBankingPayment, cfWalletPayment, or cfupiPayment for your selected payment method.

Sample code

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

Sample GitHub code

Step 3: Confirm the payment Server-side

After the SDK delivers a callback via onPaymentVerify, 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’ve integrated.
  2. Confirm that the SDK opens the correct payment screen for the method (Cashfree’s hosted card, net banking, or wallet screen, or the selected UPI app).
  3. Confirm that onPaymentVerify or onPaymentFailure 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 Android application, you can view the error codes exposed by the SDK.
The SDK validation errors are grouped by category as follows:

Session errors

Card errors

Net banking errors

Wallet errors

UPI errors

Callback and general errors

Other options

The following optional configurations let you customise SDK behaviour and enable logging for troubleshooting.
If you want to initialise the SDK yourself, follow these steps. Initialise the SDK in your Application class to avoid runtime issues.
1

Add the following to your values.xml file

<bool name="cashfree_pg_core_auto_initialize_enabled">false</bool>
2

Initialise the SDK yourself before attempting payment

To enable SDK logging, add the following entry to your values.xml file:<integer name="cashfree_pg_logging_level">3</integer>The following logging levels are available, listed from least to most verbose:

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.