Python SDK – Refund
It is used to initiate a refund using refund() function
Parameters:
| Parameter Name | Data Type | Mandatory | Description |
|---|---|---|---|
refund_request | RefundRequest | yes | The request built using RefundRequest builder. |
Refund Request Builder :
| Parameter name | Data Type | Mandatory | Description | Constraints |
|---|---|---|---|---|
merchant_refund_id | str | yes | Unique merchant refund id generated by merchant | Max Length = 63 characters |
original_merchant_order_id | str | yes | Original merchant order id against which refund is required | |
amount | int | yes | Amount in paisa to refund | Min 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.stateReturns :
The function returns a RefundResponse Object
| Property | Data Type | Description |
|---|---|---|
refund_id | str | PhonePe generated internal refund id |
state | str | Refund state, initially it will be pending |
amount | long | Amount in paisa that will be refunded |
Python SDK – Refund Status
It is used to retrieve the status of a refund.
Parameters
| Parameter Name | Data Type | Mandatory | Description |
|---|---|---|---|
refund_Id | str | yes | Refund 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.stateReturns:
It returns a RefundStatusResponse Object
RefundStatusResponse
| Property | Data Type | Description |
|---|---|---|
merchant_id | str | Merchant Id who initiated the refund |
merchant_refund_id | str | Refund Id created by the merchant at the time of refund initiation |
original_merchant_order_id | str | Order Id for which refund has initiated. Created by the merchant at the time of order creation |
amount | int | Amount to refund |
state | str | State of the refund |
payment_details | listPaymentRefundDetail | Contains the list of details of each transaction attempt made corresponding to this particular order |
PaymentRefundDetail :
| Property | Data Type | Description |
|---|---|---|
transaction_Id | str | Transaction Id generated by the PhonePe |
payment_mode | str | Mode 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 |
timestamp | int | Timestamp of the attempted transaction in epoch |
state | str | Attempted transaction state. It can be any one of the following states: 1. PENDING 2. COMPLETED 3. FAILED |
error_code | str | Error code present only when the transaction state is Failed |
detailed_error_code | str | Detailed Error Code present only when transaction state is Failed |
split_instruments | list<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_code | str | Response Code for the refund status |