Why choose Cashfree?
- Simplified checkout: Provides a pre-built, easy-to-use checkout page that delivers an optimised payment experience. It accepts payments from over 120 payment methods easily and securely.
- Secure and PCI compliant: Securely collects payment details and submits them directly to Cashfree servers, removing the need for Payment Card Industry Data Security Standard (PCI DSS) compliance requirements at the merchant’s end.
- Personalised: Customise your payment methods, branding, and various other elements to align seamlessly with your company’s specific theme.
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.
- Whitelist your website domain for integration. Learn more about domain whitelisting.
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 cannot call this API from the client-side.Create orders through your backend as this API requires your secret key. Do not call it directly 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 all the complete API request and response for /orders here.
Step 2: Open the checkout page Client-side
1. Include JS SDK in your client code
Include our JavaScript SDK in your client-side code to integrate the Cashfree checkout.2. Initialise the SDK
Initialise the SDK using theCashfree() function. You can use one of two modes:
sandbox: Use this for a test environment.production: Use this for your live environment.
3. Open Cashfree checkout
Use thecashfree.checkout() method to open the checkout page. Use the following parameters with this method:
paymentSessionId: The ID you receive from the create order response.redirectTarget(optional): This parameter determines how the checkout page opens. Use one of the following values:
| Property Value | Description |
|---|---|
_self (default) | Opens the payment link in the same frame as it was clicked. |
_blank | Opens the payment link in a new window or tab. |
_top | Opens the linked document in the full body of the window. |
_modal | Opens the payment link in a pop-up window on the current page. |
| DOM element | Opens the payment link directly within a specified DOM element. |
Checkout variants
Cashfree supports the following checkout variants:- Redirect checkout: Use for
redirectTargetvalues_self,_blank, or_top. - Popup checkout: Use for
redirectTargetvalue_modal. - Inline checkout: Use for
redirectTargetas a DOM element.
The integration approach varies for pop-up and inline checkout. You must manage the promise that
cashfree.checkout() returns to execute additional code after the payment attempt.Step 3: Confirm the payment Server-side
After the customer completes the payment, you must confirm the payment status.Redirect checkout
When the payment process finishes, the user redirects to the return URL you provided when you created the order (Step 1). If you do not provide a return URL, customers redirect to a default Cashfree page.We recommend that you provide a return URL while creating an order. This will improve the overall user experience by ensuring your customers don’t land on
broken or duplicated pages. Also, remember to add context of the order in your return URL so that you can identify the order once the customer has returned to
this URL.
Popup and inline checkout
When the payment process finishes, thecashfree.checkout() function returns a promise. You must handle this promise to process the payment response.
Order status verification
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 before you deliver 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 the checkout button, verify that it opens the Cashfree-hosted payment page. If the integration does not work, follow these steps to troubleshoot:- Open the Network tab in your browser developer tools.
- Click the pay button and check the console logs.
- Ensure you pass the correct environment and
payment_session_id. - Use
console.log()in your button click listener to confirm that you pass data correctly.
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.