Initiate and Verify Refunds
Refunds can be initiated using the SDK by building a refund request and calling the refund() method.
To check the status of a refund, use the getRefundStatus() function with the refund ID. Responses include details like refund ID, amount, and current status.
This enables smooth and trackable refund handling within the application.
Initiate Refund
The refund() method is used to start the refund process by passing parameters through the RefundRequest.build_refund_request() function.
Initiating Refund Request
| Attribute | Data Type | Mandatory | Description | Constraints |
| String | Yes | Unique order ID generated by the merchant. | Max Length = 63 characters |
| String | Yes | Original merchant order ID for which the refund is requested. | |
amount | Int | Yes | Refund amount in paisa. | Min value = 100 (in paise), Max value = order amount. |
import uuid
from phonepe.sdk.pg.common.models.request.refund_request import RefundRequest
from phonepe.sdk.pg.subscription.v2.subscription_client import SubscriptionClient
client_id = "<client_id>"
client_secret = "<client_secret>"
client_version = <client_version> # insert your client version here
env = Env.SANDBOX # change to Env.PRODUCTION when you go live
subscription_client = SubscriptionClient.get_instance(client_id, client_secret, client_version, env)
merchant_refund_id = str(uuid.uuid4())
original_merchant_id = "<merchant_order_id>"
amount = 100
refund_request = RefundRequest.build_refund_request(merchant_refund_id, amount, original_merchant_id)
refund_response = subscription_client.refund(refund_request)
state = refund_response.stateRefund Initiation Response
The function returns a RefundResponse object with the following properties:
| Parameter Name | Data Type | Description |
| String | PhonePe generated internal refund id. |
| String | The status of the initiated refund. It will initially be “PENDING” |
amount | Long | The amount, in paisa, that will be refunded. |
Check Refund Status
The get_refund_status() method is used to check the current status of the initiated refund.
Refund Status Request
| Attribute | Data Type | Mandatory | Description |
| String | Yes | Refund ID created by the merchant when initiating the refund request. |
import com.phonepe.sdk.pg.Env;
import com.phonepe.sdk.pg.common.models.response.RefundStatusResponse;
import com.phonepe.sdk.pg.subscription.v2.SubscriptionClient;
String clientId = "<clientId>";
String clientSecret = "<clientSecret>";
Integer clientVersion = <clientVersion>; //insert your client version here
Env env = Env.SANDBOX; //change to Env.PRODUCTION when you go live
SubscriptionClient subscriptionClient = SubscriptionClient.getInstance(clientId, clientSecret,
clientVersion, env);
String refundId = "<REFUND_ID>";
RefundStatusResponse refundStatusResponse = subscriptionClient.getRefundStatus(refundId);
String state = refundStatusResponse.getState();Refund Status Response
The function returns a RefundStatusResponse object with the following properties:
| Parameter Name | Data Type | Description |
| String | The ID of the merchant who initiated the refund. |
| String | Refund ID created by the merchant when initiating the refund. |
| String | Order ID for which the refund was initiated, created by the merchant during order creation. |
amount | Long | The amount to be refunded. |
state | String | The current state of the refund process. |
| List<PaymentRefundDetail> | A list containing details of each transaction attempt made for this specific refund order. |
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.
| Parameter Name | Data Type | Description |
| String | Unique transaction ID generated by PhonePe. |
| String | The mode of payment used for the transaction. It can be one of the following: • UPI_INTENT • UPI_COLLECT • UPI_QR • CARD • TOKEN • NET_BANKING |
timestamp | Long | The timestamp of the transaction attempt, provided in epoch (in milliseconds) |
| String | The state of the attempted transaction. Possible values include: • COMPLETED • FAILED • PENDING |
| String | The error code present only when the transaction state is “FAILED.” |
detailed_error_code | String | A detailed error code present when the transaction state is “FAILED.” |
| rail | PaymentRail | Contains the processing rail details under which the transaction attempt was made. |
instrument | PaymentInstrumentV2 | Contains the instrument details for that particular transaction. |
| split_instruments | List<InstrumentCombo> | Types of transaction instruments involved. It can be one of the following: • 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.