Cashfree Web Integration Guide
✅ Simplified Checkout: Cashfree Checkout is a pre-built Checkout Page by Cashfree Payments to provide the most optimal payment experience. Accept payments from 120+ payment methods easily, and securely. Your customers are redirected to Cashfree Checkout to complete the Payment. ✅ Secure and PCI Compliant: Cashfree Checkout collects the data and submits to Cashfree servers securely, so, no PCI compliance requirements are required at your end. ✅ Personalised: Customise payment methods, branding, and much more to match the theme of your company.Requirements
- Create a Cashfree Merchant Account.
- Log in to the merchant dashboard and generate test keys from Cashfree Dashboard.
- Generate API Keys - Client ID & Secret Key.
- Ensure you have whitelisted your website domain for integration. Read more about Domain Whitelisting.
Step 1: Creating an Order
To integrate the Cashfree Payment Gateway, the first step is to create an Order. This must be done before any payment processing can occur. Set up an endpoint on your server to handle order creation as you cannot call this api from 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. You can find the SDKs here.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 Checkout Page
This step requires you to whitelist your domain with Cashfree. Read more here
1. Include JS SDK in your client code
To integrate the Cashfree Checkout, you must include our JavaScript SDK within your JS file.2. Initialize the SDK
You need to initialise the variable using the Cashfree() function. There are two modes applicable for this -sandbox
or production
.
Sandbox is used for test environment, whereas production is used for production mode.
3. Open Cashfree Checkout
To open the checkout, you can usecashfree.checkout()
method. This method can take in following parameters -
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. |
Step 3: Confirming the Payment
Once the payment is completed, you need to confirm whether the payment was successful by checking the order status.We recommend you to 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 customer has returned on
this url.
cashfree.checkout()
function returns a promise which should be handled by the merchant
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.
Testing
You should now have a working checkout button that opens Cashfree hosted payment page. If your integration isn’t working:- Open the Network tab in your browser’s developer tools.
- Click the button and check the console logs.
- Ensure correct environment and payment session id is being passed.
- Use console.log() inside your button click listener to confirm whether the data is being passed correctly or not.
💻 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
- Instant activation, go live in minutes.
- Industry-best success rate across all payment modes.
- Effortlessly accept international payments in 140+ currencies