This method is used to initiate a transaction refund.
Parameters
Parameter | Type | Mandatory | Description |
---|---|---|---|
merchant_transaction_id | str | Yes | The merchant transaction ID for which the status is fetched |
original_transaction_id | str | Yes | Merchant transaction ID of the forward transaction to be reversed. |
amount | int | Yes | Reversal amount in paise, up to the maximum of the original payment transaction. |
callback_url | str | No | URL 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:
Parameter | Type | Description |
---|---|---|
success | boolean | Success/failure of the request processing |
code | str | Response code explaining the result |
message | str | Additional information about the response |
data | PgRefundResponse | Information about the refund |
PgRefundResponse properties
Here is the response property table for the given model:
Property | Type | Description |
---|---|---|
merchant_id | str | The ID of the merchant associated with the transaction. |
merchant_transaction_id | str | The unique identifier of the merchant transaction |
transaction_id | str | The PhonePe unique identifier of the transaction. |
amount | int | The refunded amount |
response_code | str | The response code indicating the status of the refund |
state | str | The state of the refund transaction. Can be PENDING, COMPLETED, or FAILED. |