Confirm Status

Once the payment has reached a terminal state you need to check the status from your backend.

The last step is to check the status of the order in Cashfree's system and update the order at your end. You can do it through a simple GET request as below.
There are few things you should ensure

  1. Only make successful orders which are still active in your system. If an order is already PAID, you do not want to fulfil it again.
  2. Make sure that you always check the order status. The order_status can be one of ACTIVE, PAID or EXPIRED.
<?php

$orderId = "order_HDUp8wlq";
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://sandbox.cashfree.com/pg/orders/$orderId",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => array(
    'x-client-id: {{appId}}',
    'x-client-secret: {{secretKey}}',
    'x-api-version: 2021-05-21'
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if(!$err) {
	$result = json_decode($response, true);
	if($result["order_status"] == 'PAID'){
		echo "This order is paid!";
	} else {
		echo "Order has not been paid!";
	}
} else {
	echo  $err;
}

?>
curl --request GET \
  --url https://sandbox.cashfree.com/pg/orders/order_1471yUGAj97hSGoOB \
  --header 'Content-Type: application/json' \
  --header 'x-api-version: 2021-05-21' \
  --header 'x-client-id: {{appId}}' \
  --header 'x-client-secret: {{secretKey}}'
  
  // response
  {
  "cf_order_id": 594193729,
  "created_at": "2021-09-22T13:46:51+05:30",
  "customer_details": {
    "customer_id": "P9999711",
    "customer_name": null,
    "customer_email": "[email protected]",
    "customer_phone": "9899049110"
  },
  "entity": "order",
  "order_amount": 1.00,
  "order_currency": "INR",
  "order_expiry_time": "2021-10-22T13:46:51+05:30",
  "order_id": "order_1471yUGAj97hSGoOB",
  "order_meta": {
    "return_url": "http://localhost:1774/resp.php?order_id={order_id}&order_token={order_token}",
    "notify_url": "https://b8af79f41056.eu.ngrok.io/webhook.php",
    "payment_methods": null
  },
  "order_note": null,
  "order_splits": [],
  "order_status": "PAID",
  "order_tags": null,
  "order_token": "9AtvrNXIXgQqFsJbaRVc",
  "payment_link": "https://payments.cashfree.com/order/#9AtvrNXIXgQqFsJbaRVc",
  "payments": {
    "url": "https://api.cashfree.com/pg/orders/order_1471yUGAj97hSGoOB/payments"
  },
  "refunds": {
    "url": "https://api.cashfree.com/pg/orders/order_1471yUGAj97hSGoOB/refunds"
  },
  "settlements": {
    "url": "https://api.cashfree.com/pg/orders/order_1471yUGAj97hSGoOB/settlements"
  }
}

Ask a question about Integration

You can ask questions, and participate in discussions about Cashfree PG API in the Cashfree Discord channel.