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.
- Set your application’s
minSdkVersionto API level 19 or higher.
Step 1
Step 2
Step 3
Step 1: Create an order Server-side
Create an order from your backend server before you process any payment.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.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-levelbuild.gradle file:
2. Select a payment method
The Element SDK supports the following payment methods:- Card
- Net banking
- Wallet
- UPI Intent
3. Complete the payment
To complete the payment, follow these steps:- Set up the payment callback.
- Create a
CFSessionobject. - Create the payment object for the selected payment method.
- Optionally, customise the theme.
- Initiate the payment using
doPayment().
Set up the payment callback
The SDK exposes an interfaceCFCheckoutResponseCallback to receive callbacks from the SDK once the payment flow ends. This interface consists of two methods:
Create a session
TheCFSession 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.- Card
- Net banking
- Wallet
- UPI Intent
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 theCFTheme 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
CalldoPayment() 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.Element checkout sample
Element checkout sample
Sample GitHub code
Android Element integration
Android Element integration
Step 3: Confirm the payment Server-side
After the SDK delivers a callback viaonPaymentVerify, 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.
order_status is PAID.Testing
After you integrate a payment method, verify that it behaves as expected. Follow these steps to test:- Trigger a payment using each method you’ve integrated.
- 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).
- Confirm that
onPaymentVerifyoronPaymentFailureis called when the payment flow ends.
Error codes
To confirm the error returned in your Android application, you can view the error codes exposed by the SDK.Show error codes
Show error codes
Other options
The following optional configurations let you customise SDK behaviour and enable logging for troubleshooting.(Optional) Custom initialisation of the SDK
(Optional) Custom initialisation of the SDK
Add the following to your values.xml file
<bool name="cashfree_pg_core_auto_initialize_enabled">false</bool>Initialise the SDK yourself before attempting payment
(Optional) Enable logging to debug issues
(Optional) Enable logging to debug issues
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.