Handle Return URL

Once the customer enters the OTP on the payment page, they will return back to the return url.

There are two broad types of payment flows -

  1. Where customer is redirected to a third party page (bank OTP page, app login page, etc.)
  2. Where customer needs to approve the payment through an asynchronous process (example - by approving a payment request on their phone).

While the former requires a redirection to the third party page, the latter does not. In case the customer is redirected from your website to a third party page, you would also want them to return back to your application. The return_url provided in the create order API call is used for this.

🚧

Return URL

Once the customer has completed the payment on the banks OTP page, we will redirect them back to your return_url. This will be a link based redirection, so if you have provided a return_url of the format - https://b8af79f41056.eu.ngrok.io?order_id={order_id}&order_token={order_token} - the customer will be redirected to the url - https://b8af79f41056.eu.ngrok.io?order_id=order_271vfuhh1o4h6bQIigqyOx74YiJ1T&order_token=LGi51C905Z3uVgjzi1YS

Once you receive a request on this URL, you must first confirm if the order_token and the order_id belong to the same order. You must then check the status of the order in your system. If the system is already paid, you do not need to fulfil the order again. However, if the order is still in an ACTIVE state, you need to fetch the order status from Cashfree. You must fetch the order status from your backend using the /orders/:orderID API call as below.

curl --request GET \
  --url https://sandbox.cashfree.com/pg/orders/order_271vWwzSQOHe01ZVXpEcguVxQSRqr \
  --header 'Content-Type: application/json' \
  --header 'x-api-version: 2021-05-21' \
  --header 'x-client-id: <appID>' \
  --header 'x-client-secret: <secret Key>'
{
  "cf_order_id": 1539553,
  "created_at": "2021-07-19T16:13:35+05:30",
  "customer_details": {
    "customer_id": "7112AAA812234",
    "customer_name": null,
    "customer_email": "[email protected]",
    "customer_phone": "9908734801"
  },
  "entity": "order",
  "order_amount": 5.01,
  "order_currency": "INR",
  "order_expiry_time": "2021-08-18T16:13:34+05:30",
  "order_id": "order_271vWwzSQOHe01ZVXpEcguVxQSRqr",
  "order_meta": {
    "return_url": "https://b8af79f41056.eu.ngrok.io?order_id={order_id}&order_token={order_token}",
    "notify_url": "https://b8af79f41056.eu.ngrok.io/webhook.php",
    "payment_methods": null
  },
  "order_note": null,
  "order_status": "PAID",
  "order_token": "BtJEHHxOB9bFpNsaHmEL",
  "payment_link": "https://payments-test.cashfree.com/order/#BtJEHHxOB9bFpNsaHmEL",
  "payments": {
    "url": "https://sandbox.cashfree.com/pg/orders/order_271vWwzSQOHe01ZVXpEcguVxQSRqr/payments"
  },
  "refunds": {
    "url": "https://sandbox.cashfree.com/pg/orders/order_271vWwzSQOHe01ZVXpEcguVxQSRqr/refunds"
  },
  "settlements": {
    "url": "https://sandbox.cashfree.com/pg/orders/order_271vWwzSQOHe01ZVXpEcguVxQSRqr/settlements"
  }
}

What’s Next

Now that you have completed the sandbox integration, go through the final checklist once before pushing things to production.

Did this page help you?