Check Order Status with PHP SDK


It is used to retrieve the status of an order using getOrderStatus() function.

The request parameters are as follows:

Parameter NameData TypeMandatory
(Yes/No)
Description
merchantOrderIdStringYesThe merchant order ID for which the status is fetched.
detailsStringNotrue → Returns all payment attempt details under the paymentDetails list.
false → Returns only the latest payment attempt details.
Sample Request
<?php
require_once "vendor/autoload.php"; // Include Composer autoloader

use PhonePe\payments\v2\standardCheckout\StandardCheckoutClient;
use PhonePe\Env;

$clientId = "YOUR_CLIENT_ID"; // Replace with your Client ID
$clientVersion = CLIENT_VERSION; // Replace with your Client Version
$clientSecret = "YOUR_CLIENT_SECRET"; // Replace with your Client Secret
$env = Env::PRODUCTION;

$client = StandardCheckoutClient::getInstance(
    $clientId,
    $clientVersion,
    $clientSecret,
    $env
);

$merchantOrderId = "YOUR_MERCHANT_ORDER_ID"; // Replace with the order ID you want to check

try {
    $statusCheckResponse = $client->getOrderStatus($merchantOrderId, true);

    // Process the status check response
    echo "Order ID: " . $statusCheckResponse->getMerchantId() . "\n";
    echo "Transaction ID: " . $statusCheckResponse->getTransactionId() . "\n";
    echo "State: " . $statusCheckResponse->getState() . "\n";
    echo "Amount: " . $statusCheckResponse->getAmount() . "\n";

    // You can access further details from $statusCheckResponse->getPaymentInstrument(), $statusCheckResponse->getPayResponseCode()
} catch (\PhonePe\common\exceptions\PhonePeException $e) {
    // Handle exceptions (e.g., log the error)
    echo "Error checking order status: " . $e->getMessage();
}
?>

The function returns a StatusCheckResponse object with the following properties:

PropertyData TypeDescription
orderIdStringOrder ID generated by PhonePe PG.
stateStringCurrent state of the order: Expected values:
PENDING
FAILED
COMPLETED
expireAtNumberExpiry time in epoch.
amountLongOrder amount in paisa.
metaInfoObjectA MetaInfo object containing additional metadata about the order.
errorCodeStringError code (only present when the transaction state is FAILED).
detailedErrorCodeStringDetailed error code (only present when the transaction state is FAILED).
paymentDetailsList<PaymentDetail>Contain list of details of each payment attempt made corresponding to this order.

The paymentDetails property contains a list of payment details for each payment attempt made against an order. The details of each payment are explained in the table below.

PropertyData TypeDescription
transactionIdStringThe transaction ID generated by PhonePe PG.
paymentModeStringThe payment method used
UPI_INTENT
UPI_COLLECT
UPI_QR
CARD
TOKEN
NET_BANKING
timestampLongTimestamp of the attempted transaction in epoch.
stateStringAttempted transaction state. It can be any one of the following states:
PENDING
COMPLETED
FAILED
errorCodeStringError code (only if the transaction failed)
detailedErrorCodeStringA more detailed error code (only if the transaction failed)
splitInstrumentslist<InstrumentCombo>Contains split instrument details of all the transactions made.

splitInstruments provides a list of InstrumentCombo objects. Details of each InstrumentCombo object are explained in the table below.

PropertyData TypeType
instrumentPaymentInstrumentV2Instrument used for the payment.
railsPaymentRailRail used for the payment.
amountIntegerAmount transferred using the above instrument and rail.

You’ve understood how to retrieve the status of an order using the getOrderStatus() function. Now, let’s move on to learn how to process refunds, which allows you to return funds to the customer for eligible transactions.

Is this article helpful?