Python SDK – Callback Verification

This is used to verify whether the callback received is valid or not

You need to pass 4 parameters to the validate_Callback() function

Parameter NameData TypeMandatoryDescription
usernamestryesUnique username configured for the callback url.
passwordstryesUnique password configured for the callback url.
authorizationstryesValue of the Authorization header under the callback response.
responseBodystryesCallback response body as string.

Example usage :

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)
 
authorization_header_data = "ef4c914c591698b268db3c64163eafda7209a630f236ebf0eebf045460df723a"  # header value under `Authorization` key
phonepe_s2s_callback_response_body_string = """{"type": "PG_REFUND_COMPLETED","payload": {}}"""  # callback body as string
 
username_configured = "MERCHANT_USERNAME"
password_configured = "MERCHANT_PASSWORD"
 
callback_response = custom_checkout_client.validate_callback(username=username_configured,
                                                              password=password_configured,
                                                              callback_header_data=authorization_header_data,
                                                              callback_response_data=phonepe_s2s_callback_response_body_string)
callback_type = callback_response.callback_type
merchant_refund_id = callback_response.callback_data.merchant_refund_id
state = callback_response.callback_data.state

Returns :

The function returns a CallbackResponse if the callback is valid, otherwise throws a PhonePeException.

Callback Response:

PropertyData TypeDescription
callback_typeenumContains type of callback received at the merchant end.
callback_payloadObjectContains callback details.

Callback Types

Callback TypeContext
PG_ORDER_COMPLETEDOrder request is successfully completed
PG_ORDER_FAILEDOrder request failed
PG_REFUND_COMPLETEDRefund Completed for PG
PG_REFUND_ACCEPTEDRefund Accepted by PhonePe and will be initiated
PG_REFUND_FAILEDRefund Failed for PG

CallbackData Properties :

PropertyData TypeDescription
merchant_idstrThe merchant from which request was initiated.
order_idstrOrder id generated by PhonePe. (Only present in case of order callbacks)
merchant_order_idstrOrder id generated by merchant. (Only present in case of order callbacks)
original_merchant_order_idstrInternal transaction id for given payment attempt. (Only present in case of refund callback)
refund_idstrRefund id generated by PhonePe. (Only present in case of refund callback)
merchant_refund_idstrRefund id generated by merchant. (Only present in case of refund callback)
statestrState of the order/refund.
amountintAmount of the order/refund processed.
expire_atintExpiry in epoch.
error_codestrError code. (Only present when state is failed)
detailed_error_codestrDetailed error code. (Only present when state is failed)
meta_infoMetaInfoMetaInfo passed during the init of order.
payment_detailsList<PaymentDetail>Payment details.