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 name | Data Type | Mandatory | Description | Constraints |
---|---|---|---|---|
| String | Yes | Unique merchant refund id generated by merchant | Max Length = 63 characters |
originalMerchantOrderId | String | Yes | Original merchant order id against which refund is required | |
amount | Long | Yes | Amount in paisa to refund | Min 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
Property | Data Type | Description |
---|---|---|
refundId | String | PhonePe generated internal refund id |
state | String | The state of the refund initiated. Initially it will be PENDING |
amount | Long | The refund amount in paisa. |