Key benefits
The Android SDK offers the following advantages for your payment integration:- Multiple checkout flows: Provides web checkout and UPI Intent checkout options to suit different integration needs.
- Native Android support: Optimised for Android SDK version 19 and above with native UI components for UPI payments.
- Customisable UI: Allows customisation of themes, colours, and fonts to match your app’s design.
- Secure and compliant: Securely handles payment processing with built-in security measures managed by the SDK.
Prerequisites
Ensure you complete the following tasks before starting 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.
- 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.
Step 1
Step 2
Step 3
Step 1: Create an order Server-side
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.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 checkout page Client-side
Once the order is created, the next step is to open the payment page so the customer can make the payment.1. Set up the SDK
The Cashfree Android SDK is hosted on Maven Central. You can download the latest version 2.4.0. The Android SDK supports Android SDK version 19 and above. Add the following dependency to your app’sbuild.gradle file:
2. Select a payment flow
The Android SDK offers the following payment flows:Web Checkout
Web Checkout
UPI Intent Checkout
UPI Intent Checkout
3. Complete the payment
To complete the payment, follow these steps:- Create a
CFSessionobject. - Create a
CFThemeobject. - Create a
CFWebCheckoutPaymentorCFUPIIntentCheckoutPaymentobject. - Set up payment callback.
- Initiate the payment using the payment object.
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).
Customise theme (optional)
You can customise the appearance of the checkout screen using CFTheme. This step is optional but can help maintain consistency with your app’s design.Web Checkout
Web Checkout
UPI Intent Checkout
UPI Intent Checkout
Create checkout payment object
Web Checkout
Web Checkout
doPayment() to open the Cashfree web checkout screen. This will present the user with the payment options and handle the payment process.UPI Intent Checkout
UPI Intent Checkout
CFUPIIntentCheckoutPayment to create the payment object for UPI Intent flow. This object accepts a CFSession and theme configuration.Set up payment callback
The SDK exposes an interfaceCFCheckoutResponseCallback to receive callbacks from the SDK once the payment journey ends.
This interface consists of 2 methods:
Initiate the payment
Finally, calldoPayment() to open the Cashfree checkout screen. This will present the user with the payment options and handle the payment process.
Web Checkout
Web Checkout
UPI Intent Checkout
UPI Intent Checkout
Sample code
Web Checkout Sample code
Web Checkout Sample code
UPI Intent Checkout Sample code
UPI Intent Checkout Sample code
Sample GitHub code
Android Integration
Android Integration
Step 3: Confirm the payment Server-side
After the customer completes the payment, you must confirm the payment status. Once the payment finishes, the user redirects back to your activity. 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 the checkout functionality, verify that it opens the Cashfree-hosted payment page. Follow these steps to test:- Click the checkout button.
- Verify you’re redirected to the Cashfree Checkout payment page.
Error codes
To confirm the error returned in your Android application, you can view the error codes that are exposed by the SDK.Show error codes
Show error codes
Other options
(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 debugging issues
(Optional) Enable logging to debugging issues
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
<bool name="cf_quick_checkout_enabled">false</bool>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.