Initiate and Verify Refunds with .NET SDK
This section explains how to initiate a refund for a successful transaction using the Initiate Refund. You need to provide details like the original transaction ID, refund amount, and refund ID. After initiating the refund, you can use Refund Status to check whether the refund was successful, pending, or failed. These APIs help you manage the full refund lifecycle efficiently. Use them to ensure timely and transparent customer experiences.
Initiate Refund
Use the refund() function to initiate a refund. This ensures the amount is returned to the customer’s original payment method.
Initiating Refund Request
You can use the RefundRequest Builder to create the refund request and the following are the attributes that merchant can pass.
| Parameter Name | Data Type | Mandatory (Yes/No) | Description | Constraints |
merchantRefundId | String | Yes | Unique refund ID assigned by you | Max Length = 63 characters |
originalMerchantOrderId | String | Yes | The original order ID against which the refund is requested | |
amount | Long | Yes | Refund amount in paisa. | Min value = 100 (in paise), Max value = order amount. |
var refundId = $"Refund_{DateTime.UtcNow:yyyyMMddHHmmssfff}";
var originalMerchantOrderId = '<MERCHANT_ORDER_ID>'; //merchantOrderId for which order has to be initiated
var amount = 100 //amount to be refund
var refundRequest = RefundRequest.Builder()
.SetMerchantRefundId(refundId)
.SetAmount(100)
.SetMerchantOrderId(originalMerchantOrderId)
.Build();
RefundResponse response = await client.Refund(refundRequest);⚠️ Invalid Refund Amount!
The refund amount cannot exceed the initiated amount. It must always be less than or equal to the amount originally initiated.
Refund Initiation Response
The function returns a RefundResponse Object:
| Parameter Name | Data Type | Description |
refundId | String | Refund ID generated by PhonePe PG. |
state | String | The state of the refund initiated. Initially it will be PENDING. |
amount | Long | Refund amount in paisa. |
Check Refund Status
Refund Status is used to retrieve the current status and details of a refund request made against a payment. By calling the getRefundStatus() function with the refund ID, you can track whether the refund is pending, successful, or failed, enabling you to manage and update refund workflows accordingly.
Refund Status Request
Pass the below parameter to get the refund status in getRefundStatus() :
| Parameter Name | Data Type | Mandatory | Description |
refundId | String | Yes | Refund ID assigned by you at the time of refund initiation. |
var response = await client.GetRefundStatus(refundId);
logger.LogInformation("Refund Status Response:\n{Response}", JsonSerializer.Serialize(response, new JsonSerializerOptions { WriteIndented = true }));Refund Status Response
It returns a RefundStatusResponse Object:
| Properties | Data Type | Description |
merchantId | String | Merchant Id who initiated the refund. |
merchantRefundId | String | Refund Id created by you at the time of refund initiation. |
originalMerchantOrderId | String | The order ID for which the refund was initiated. |
amount | Long | Refund amount (in paisa). |
state | String | The status of the refund. |
paymentDetails | List<PaymentRefundDetail> | List of transaction attempts related to the refund. |
The PaymentRefundDetail 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:
| Property | Data Type | Description |
transactionId | String | The transaction ID generated by PhonePe PG. |
paymentMode | String | The payment method used • UPI_INTENT • UPI_COLLECT • UPI_QR • CARD • TOKEN • NET_BANKING |
| timestamp | Long | Timestamp of the attempted transaction in epoch. |
state | String | Attempted transaction state. It can be any one of the following states: • PENDING • COMPLETED • FAILED |
errorCode | String | Error code (only if the transaction failed). |
detailedErrorCode | String | A more detailed error code (only if the transaction failed). |
| rail | PaymentRail | Contains processing rail details under which transaction attempt is made. |
instrument | PaymentInstrumentV2 | Contains instrument details of that particular transaction ID. |
splitInstruments | list<InstrumentCombo> | Payment instruments used: • ACCOUNT • CREDIT_CARD • DEBIT_CARD • NET_BANKING |
What’s Next?
In this section, you’ve learned how to initiate a refund and check its status. In the next section, you’ll understand how payment verification is handled using Webhooks, and how to manually verify the payment in case the webhook callback fails.