Skip to main content

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

Step 1: Creating an Order

The first step in the Cashfree Payment Gateway integration is to create an Order. You need to do this before any payment can be processed. You can add an endpoint to your server which creates this order and is used for communication with your frontend.
Order creation must happen from your backend (as this API uses your secret key). Please do not call this 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. 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. Cashfree Android SDK offer below payment flow.
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.
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:
  1. Create a CFSession object.
  2. Create a CFTheme object.
  3. Create a CFWebCheckoutPayment/CFUPIIntentCheckoutPayment object.
  4. Set payment callback.
  5. Initiate the payment using the payment object created from [step 3]
We go through these step by step below.

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).

Customize Theme (Optional)

You can customize the appearance of the checkout screen using CFTheme. This step is optional but can help maintain consistency with your app’s design.

Create Checkout Payment Object

This object combines all the configurations (session, theme) into a single checkout configuration. Finally, call doPayment() to open the Cashfree web checkout screen. This will present the user with the payment options and handle the payment process.
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.

Setup payment callback

The SDK exposes an interface CFCheckoutResponseCallback to receive callbacks from the SDK once the payment journey ends. This interface consists of 2 methods:
Make sure to set the callback at activity’s onCreate as this also handles the activity restart cases.

Open Checkout Screen

Finally, call doPayment() to open the Cashfree checkout screen. This will present the user with the payment options and handle the payment process.

Step 3: Sample Code

Github Sample

Step 4: Confirming the Payment

After 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 to your implementation of the CFCheckoutResponseCallback interface.
You must always verify payment status from your backend. Before delivering the goods or services, please ensure you call check the order status from your backend. Ensure you check the order status 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.

Testing

You should now have a working checkout button that redirects your customer to Cashfree Checkout. If your integration isn’t working:
  1. Open the Network tab in your browser’s developer tools.
  2. Click the button and check the console logs.
  3. Use console.log(session) inside your button click listener to confirm the correct error returned.

Error Codes

To confirm the error returned in your android application, you can view the error codes that are exposed by the SDK.

Other Options

If you require to initialise the SDK yourself then follow the steps below. Make sure to initialise the SDK in Application class to avoid any Runtime issues.
1

Add the following to your values.xml file

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

Initialize the SDK yourself before attempting payment

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
If you want to disable quick checkout flow in the payment journey you can add the following to your values.xml file.<bool name="cf_quick_checkout_enabled">false</bool>
Add the following to your values.xml file.<bool name="cashfree_pg_core_encrypt_pref_enabled">false</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