Refund

It is used to initiate a refund using refund() function

Merchants can use the StandardCheckoutRefundRequestBuilder::builder() to create the refund request and the following are the attributes that merchant can pass.

Parameters:

Parameter nameData TypeMandatoryDescriptionConstraints
merchantRefundIdStringYesUnique merchant refund id generated by merchantMax Length = 63 characters
originalMerchantOrderIdStringYes
Original merchant order id against which refund is required
amountLongYesAmount in paisa to refundMin value = 100 (in paise), Max value = order amount

Example Usage:

<?php use PhonePe\payments\v2\models\request\builders\StandardCheckoutRefundRequestBuilder; $merchantRefundId = "REFUND_" . time(); // Unique refund ID from your system $originalMerchantOrderId = "YOUR_ORIGINAL_MERCHANT_ORDER_ID"; // The order ID you are refunding $amount = 500; // Amount to refund in paisa (e.g., 500 = ₹5.00) $refundRequest = StandardCheckoutRefundRequestBuilder::builder() ->merchantRefundId($merchantRefundId) ->originalMerchantOrderId($originalMerchantOrderId) ->amount($amount) ->build(); ?>

Call the refund() Method

<?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 = 2; // Replace with your Client Version $clientSecret = "YOUR_CLIENT_SECRET"; // Replace with your Client Secret $env = Env::PRODUCTION; $standardCheckoutClient = StandardCheckoutClient::getInstance( $clientId, $clientVersion, $clientSecret, $env ); try { $refundResponse = $standardCheckoutClient->refund($refundRequest); // Handle the response echo "Refund ID: " . $refundResponse->getRefundId() . "\n"; echo "Refund Amount: " . $refundResponse->getAmount() . "\n"; echo "Refund State: " . $refundResponse->getState() . "\n"; } catch (\PhonePe\common\exceptions\PhonePeException $e) { // Handle exceptions (e.g., log the error) echo "Error initiating refund: " . $e->getMessage(); } ?>

Returns :

The function returns a StandardCheckoutRefundResponse Object

PropertyData TypeDescription
refundIdStringPhonePe generated internal refund id
stateStringThe state of the refund initiated. Initially it will be PENDING
amountLongThe refund amount in paisa.