Python SDK – Refund


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

Parameters:

Parameter NameData TypeMandatoryDescription
refund_requestRefundRequestyesThe request built using RefundRequest builder.

Refund Request Builder :

Parameter nameData TypeMandatoryDescriptionConstraints
merchant_refund_idstryesUnique merchant refund id generated by merchantMax Length = 63 characters
original_merchant_order_idstryes
Original merchant order id against which refund is required

amountintyesAmount in paisa to refundMin value = 1, Max value = order amount

Example :

from uuid 
import uuid4

from phonepe.sdk.pg.payments.v2.custom_checkout_client 
import CustomCheckoutClient

from phonepe.sdk.pg.common.models.request.refund_request 
import RefundRequest 
from phonepe.sdk.pg.env 
import Env
 
client_id = "<YOUR_CLIENT_ID>"
client_secret = "<YOUR_CLIENT_SECRET>"
client_version = 1  # Insert your client version here
env = Env.SANDBOX  # Change to Env.PRODUCTION when you go live
 
custom_checkout_client = CustomCheckoutClient.get_instance(client_id=client_id,
                                                              client_secret=client_secret,
                                                              client_version=client_version,
                                                              env=env)
unique_merchant_refund_id = str(uuid4())
original_merchant_order_id = "<YOUR_ORDER_ID_TO_REFUND>"
amount = 100
refund_request = RefundRequest.build_refund_request(merchant_refund_id=unique_merchant_refund_id,
                                                    original_merchant_order_id=original_merchant_order_id,
                                                    amount=amount)
refund_response = custom_checkout_client.refund(refund_request=refund_request)
refund_state = refund_response.state

Returns :

The function returns a RefundResponse Object

PropertyData TypeDescription
refund_idstrPhonePe generated internal refund id
statestrRefund state, initially it will be pending
amountlongAmount in paisa that will be refunded

It is used to retrieve the status of a refund.

Parameters

Parameter NameData TypeMandatoryDescription
refund_IdstryesRefund Id created by the merchant at the time of initiating the refund

Example :

from uuid 
import uuid4

from phonepe.sdk.pg.payments.v2.custom_checkout_client 
import CustomCheckoutClient

from phonepe.sdk.pg.env 
import Env
 
client_id = "<YOUR_CLIENT_ID>"
client_secret = "<YOUR_CLIENT_SECRET>"
client_version = 1  # Insert your client version here
env = Env.SANDBOX  # Change to Env.PRODUCTION when you go live
 
custom_checkout_client = CustomCheckoutClient.get_instance(client_id=client_id,
                                                              client_secret=client_secret,
                                                              client_version=client_version,
                                                              env=env)
unique_merchant_refund_id = "<INSERT_YOUR_REFUND_ID>"  # replace with your refund id
refund_response = custom_checkout_client.get_refund_status(merchant_refund_id=unique_merchant_refund_id)
refund_state = refund_response.state

Returns:

It returns a RefundStatusResponse Object

RefundStatusResponse

PropertyData TypeDescription
merchant_idstrMerchant Id who initiated the refund
merchant_refund_idstrRefund Id created by the merchant at the time of refund initiation
original_merchant_order_idstrOrder Id for which refund has initiated. Created by the merchant at the time of order creation
amountintAmount to refund
statestrState of the refund
payment_detailslistPaymentRefundDetailContains the list of details of each transaction attempt made corresponding to this particular order

PaymentRefundDetail :

PropertyData TypeDescription
transaction_IdstrTransaction Id generated by the PhonePe
payment_modestrMode of Payment. It can be anyone of the following modes:
1. UPI_INTENT
2. UPI_COLLECT
3. UPI_QR
4. CARD
5. TOKEN
6. NET_BANKING
timestampintTimestamp of the attempted transaction in epoch
statestrAttempted transaction state. It can be any one of the following states: 1. PENDING
2. COMPLETED
3. FAILED
error_codestrError code present only when the transaction state is Failed
detailed_error_codestrDetailed Error Code present only when transaction state is Failed
split_instrumentslist<InstrumentCombo>Type of transaction instrument. It can be any one of the following types:
1. ACCOUNT
2. CREDIT_CARD
3. DEBIT_CARD
4. NET_BANKING
response_codestrResponse Code for the refund status
Is this article helpful?