Pay Order

Once you have created the order, you can use the order to initiate payment. You can either use Cashfree’s user interface to capture payment details. You will do this by redirecting the customer to a cashfree hosted page, which can be customized for your needs.

The merchants can also build their own interface to capture payment instrument details (card numbers, UPI id etc) and call this API to initiate the payment. This API can be safely called from any device and does not require any authentication.

Pre-built checkout page

If you want to use a pre-built checkout page, then you just need to use the payment_link parameter value from the create order response and redirect the customer to that page.

📘

create order response

...
"payment_link": "https://payments-test.cashfree.com/order/#BtJEHHxOB9bFpNsaHmEL"
...

Custom checkout page

If you want to build a custom checkout page you need to build your own UI and send the payment details to Cashfree. We will assume that you have built your own custom checkout page.

Cashfree expects you to send the payment instrument details to an endpoint like /orders/pay. The payload will change for every payment method - example cards, upi, net banking, apps etc.

Cards

To send card details from you UI just send the details to the below endpoint /orders/pay.

curl --request POST \
  --url https://sandbox.cashfree.com/pg/orders/pay \
  --header 'Content-Type: application/json' \
  --header 'x-version: 2021-05-21' \
  --data '{
    "order_token": "kAhvfP4q6US5cr6RnCBo",
    "payment_method" : {
        "card" : { 
            "channel": "link",
            "card_number": "4444333322221111",
            "card_holder_name": "rohit",
            "card_expiry_mm" : "02",
            "card_expiry_yy" : "22",
            "card_cvv" : "123"                      
        }
    }
}'
{
  "payment_method": "card",
  "channel": "link",
  "action": "link",
  "data": {
    "url": "https://sandbox.cashfree.com/pg/view/gateway/LGi51C905Z3uVgjzi1YSb7832c7d73d67f194164fd745dfdebdf",
    "payload": null,
    "content_type": null,
    "method": null
  }
}

The response for all card payments will require you to redirect the customer to the bank's OTP page for 2FA. In the response the value of action is what determines how you should parse the data. In case the action === link. You need to access the data.url and redirect the customer to that url. To accept cards you need to have PCI DSS certification

Card Vault

You can also use Cashfree's card vault to process card payments. To process vault payments, you just need to pass Cashfree's card id instead of the card number and expiry. You will still have to pass the cvv, as it should never be stored. Below is a sample request for using the card vault.
Use the following API to get the cards associated with a customer.

curl --location --request POST 'https://sandbox.cashfree.com/pg/orders/pay' \
--header 'Content-Type: application/json' \
--header 'x-api-version: 2021-05-21' \
--data-raw '{
    "order_token": "{{order_token}}",
    "payment_method": {
        "card": {
            "channel": "link",
            "card_holder_name": "Jal Goblad", 
            "card_cvv": "900",
            "card_alias": "{{card_alias}}"
        }
    }
}
'

UPI

There are multiple ways to perform a UPI payment. You can either use a upi intent link, a qrcode or send a payment collection request to the customers UPI app. Here is a brief snapshot of these payment methods.

Channel

Flow description

link

This channel is used for intent payments. If you send the channel as link, we will return you the intent links for different UPI applications.

qrcode

This channel is used to generate a UPI qrcode.

collect

This channel is used to send a payment collection notification to the customers UPI app. The customer should then approve the request to complete the payment.

{
    "order_token": "50d69USBiPF8i1PjRVk6",
    "payment_method" : {
        "upi" : { 
            "channel": "link"
        }
    }
}
{
  "payment_method": "upi",
  "channel": "link",
  "action": "custom",
  "data": {
    "url": null,
    "payload": {
      "bhim": "bhim://upi/[email protected]&pn=Cashfree&tr=244178447&am=2.00&cu=INR&mode=00&purpose=00&mc=5732&tn=Cashfree%20Payment",
      "default": "upi://[email protected]&pn=Cashfree&tr=244178447&am=2.00&cu=INR&mode=00&purpose=00&mc=5732&tn=Cashfree%20Payment",
      "gpay": "tez://upi/[email protected]&pn=Cashfree&tr=244178447&am=2.00&cu=INR&mode=00&purpose=00&mc=5732&tn=Cashfree%20Payment",
      "paytm": "paytm://upi/[email protected]&pn=Cashfree&tr=244178447&am=2.00&cu=INR&mode=00&purpose=00&mc=5732&tn=Cashfree%20Payment",
      "phonepe": "phonepe://[email protected]&pn=Cashfree&tr=244178447&am=2.00&cu=INR&mode=00&purpose=00&mc=5732&tn=Cashfree%20Payment"
    },
    "content_type": null,
    "method": null
  }
}
{
    "order_token": "50d69USBiPF8i1PjRVk6",
    "payment_method" : {
        "upi" : { 
            "channel": "qrcode"
        }
    }
}
{
  "payment_method": "upi",
  "channel": "qrcode",
  "action": "custom",
  "data": {
    "url": null,
    "payload": {
      "qrcode": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUAAAAFAAQMAAAD3XjfpAAAABlB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="
    },
    "content_type": null,
    "method": null
  }
}
{
    "order_token": "50d69USBiPF8i1PjRVk6",
    "payment_method" : {
        "upi" : { 
            "channel": "collect",
      "upi_id": "[email protected]"
        }
    }
}
{
  "payment_method": "upi",
  "channel": "collect",
  "action": "custom",
  "data": {
    "url": null,
    "payload": null,
    "content_type": null,
    "method": null
  }
}

Parsing response

The response for UPI will always have action as custom. This is because each payment flow needs to be handled differently.

  • Link: In the response we will send you a upi intent (or an app link). The default link will work on all android devices, since upi:// is a registered intent scheme in Android. If you want to override the default intent link with the custom link for every app, you just need to change the scheme prefix with the app prefix.

  • Qrcode: In this response we will share a custom payload with you. The payload will contain the qrcode parameter which can be used to present the QR code to the customer.

  • Collect: A successful response for a collect request will contain action as custom but the data payload will contain only null values. This is because, if you receive a successful (200) response, we would have already sent the app notification to the customers UPI application. Now you need to wait for the webhook, which will be invoked once the user completes the payment. If the user does not complete the payment within a specific time, you can cancel this order for the user.

Net banking

To initiate a net banking payment, you need to pass us the net banking parameter. In response Cashfree will return a redirect link to you.

{
    "order_token": "9dGxfNN4Ce62TUjxZhQg",
    "payment_method": {
            "netbanking": {
                    "channel": "link",
                    "netbanking_bank_code": 3009
        }
    }
}
{
  "payment_method": "netbanking",
  "channel": "link",
  "action": "link",
  "data": {
    "url": "https://www.cashfree.com/PaymentGateway/txnreq.pg?id=902f1351-1d5c-45ee-a71b-06c8f90b7436",
    "payload": null,
    "content_type": null,
    "method": null
  }
}

Apps

To initiate payment for a custom application like Airtel money, PhonePe, Google Pay etc. You will have to send us the customers phone number and the application name. In response we will return a https url using which the customer can pay using this app.

Valid app names are gpay, phonepe, ola, paytm, amazon, airtel, freecharge, mobikwik, jio

{
    "order_token": "9dGxfNN4Ce62TUjxZhQg",
    "payment_method": {
            "app": {
                    "channel": "jio",
                    "phone": "7709812345"
        }
    }
}
{
  "payment_method": "app",
  "channel": "jio",
  "action": "link",
  "data": {
    "url": "https://prod.cashfree.com/pgnextgenapi-test/api/v1/view/gateway/9dGxfNN4Ce62TUjxZhQg843317e97fef732632edf59b8e7144c2",
    "payload": null,
    "content_type": null,
    "method": null
  }
}

EMI

To process emi payments on a card you need to pass the card_bank_name and emi_tenure in the api request. If the card does not belong to the card_bank_name bank, the API will throw an error.

curl --request POST \
  --url https://api.cashfree.com/pg/orders/pay \
  --header 'Content-Type: application/json' \
  --header 'x-version: 2021-05-21' \
  --data '{
  "order_token": "t9qINHM625rHrx",
    "payment_method" : {
        "emi": {
            "channel": "link",
            "card_number": "41xxxxxxxxx150", 
            "card_expiry_mm": "11",
            "card_expiry_yy": "25",
            "card_cvv": "123",
            "card_bank_name": "Kotak",
            "emi_tenure": 3
        }
    }
}'

What’s Next

Once the customer has paid through their bank account, you still need to handle the thank you page and verify their response.

Did this page help you?