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.

The refund() method is used to start the refund process by passing parameters through the RefundRequest.build_refund_request() function.

AttributeData TypeMandatoryDescriptionConstraints
merchant_refund_idStringYesUnique order ID generated by the merchant.Max Length = 63 characters

original_merchant_order_idStringYesOriginal merchant order ID for which the refund is requested.
amountIntYesRefund amount in paisa.Min value = 100 (in paise), Max value = order amount.
Code Reference
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.state

The function returns a RefundResponse object with the following properties:

Parameter NameData TypeDescription
refund_idStringPhonePe generated internal refund id.
stateStringThe status of the initiated refund. It will initially be “PENDING”
amountLongThe amount, in paisa, that will be refunded.

The get_refund_status() method is used to check the current status of the initiated refund.

AttributeData TypeMandatoryDescription
refund_idStringYesRefund ID created by the merchant when initiating the refund request.
Code Reference
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();

The function returns a RefundStatusResponse object with the following properties:

Parameter NameData TypeDescription
merchant_idStringThe ID of the merchant who initiated the refund.
merchant_refund_idStringRefund ID created by the merchant when initiating the refund.
original_merchant_order_idStringOrder ID for which the refund was initiated, created by the merchant during order creation.
amountLongThe amount to be refunded.
stateStringThe current state of the refund process.
payment_detailsList<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 NameData TypeDescription
transaction_idStringUnique transaction ID generated by PhonePe.
payment_modeStringThe mode of payment used for the transaction. It can be one of the following:
UPI_INTENT
UPI_COLLECT
UPI_QR
CARD
TOKEN
NET_BANKING
timestampLongThe timestamp of the transaction attempt, provided in epoch (in milliseconds)
stateStringThe state of the attempted transaction. Possible values include:
COMPLETED
FAILED
PENDING
error_codeStringThe error code present only when the transaction state is “FAILED.”
detailed_error_codeStringA detailed error code present when the transaction state is “FAILED.”
railPaymentRailContains the processing rail details under which the transaction attempt was made.
instrumentPaymentInstrumentV2Contains the instrument details for that particular transaction.
split_instrumentsList<InstrumentCombo>Types of transaction instruments involved. It can be one of the following:
ACCOUNT
CREDIT_CARD
DEBIT_CARD
NET_BANKING

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.

Is this article helpful?