PG Refund

This method is used to initiate a transaction refund.

Parameters

ParameterTypeMandatoryDescription
merchant_transaction_idstrYesThe merchant transaction ID for which the status is fetched
original_transaction_idstrYesMerchant transaction ID of the forward transaction to be reversed.
amountintYesReversal amount in paise, up to the maximum of the original payment transaction.
callback_urlstrNoURL for server-to-server callback. A POST request will be made.

For Python SDK Version <= 0.0.3, the imports should be:
from phonepe.sdk.pg.payments

For Python SDK Version > 0.0.3, the imports should be:
from phonepe.sdk.pg.payments.v1

Example (Refund)

from phonepe.sdk.pg.payments.v1.payment_client import PhonePePaymentClient
from phonepe.sdk.pg.env import Env

merchant_id = "<YOUR_MERCHANT_ID>"
salt_key = "<YOUR_SALT_KEY>"
salt_index = 1 # insert your salt index
env = Env.UAT
should_publish_events = True
phonepe_client = PhonePePaymentClient(merchant_id, salt_key, salt_index, env, should_publish_events)

unique_refund_transcation_id = str(uuid.uuid4())[:-2]
transaction_id_to_refund = "<TRANSACTION_ID_TO_REFUND>"
s2s_callback_url = "https://www.merchant.com/callback"
amount = 100
refund_response = phonepe_client.refund(merchant_transaction_id=unique_refund_transaction_id,
                                        original_transaction_id=transaction_id_to_refund,
                                        amount=amount,
                                        callback_url=s2s_callback_url)

Returns

The function returns a PhonePeResponse object with the following properties:

ParameterTypeDescription
successbooleanSuccess/failure of the request processing
codestrResponse code explaining the result
messagestrAdditional information about the response
dataPgRefundResponseInformation about the refund

PgRefundResponse properties

Here is the response property table for the given model:

PropertyTypeDescription
merchant_idstrThe ID of the merchant associated with the transaction.
merchant_transaction_idstrThe unique identifier of the merchant transaction
transaction_idstrThe PhonePe unique identifier of the transaction.
amountintThe refunded amount
response_codestrThe response code indicating the status of the refund
statestrThe state of the refund transaction. Can be PENDING, COMPLETED, or FAILED.