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 Name | Data Type | Mandatory | Description |
---|---|---|---|
username | str | yes | Unique username configured for the callback url. |
password | str | yes | Unique password configured for the callback url. |
authorization | str | yes | Value of the Authorization header under the callback response. |
responseBody | str | yes | Callback 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:
Property | Data Type | Description |
---|---|---|
callback_type | enum | Contains type of callback received at the merchant end. |
callback_payload | Object | Contains callback details. |
Callback Types
Callback Type | Context |
---|---|
PG_ORDER_COMPLETED | Order request is successfully completed |
PG_ORDER_FAILED | Order request failed |
PG_REFUND_COMPLETED | Refund Completed for PG |
PG_REFUND_ACCEPTED | Refund Accepted by PhonePe and will be initiated |
PG_REFUND_FAILED | Refund Failed for PG |
CallbackData Properties :
Property | Data Type | Description |
---|---|---|
merchant_id | str | The merchant from which request was initiated. |
order_id | str | Order id generated by PhonePe. (Only present in case of order callbacks) |
merchant_order_id | str | Order id generated by merchant. (Only present in case of order callbacks) |
original_merchant_order_id | str | Internal transaction id for given payment attempt. (Only present in case of refund callback) |
refund_id | str | Refund id generated by PhonePe. (Only present in case of refund callback) |
merchant_refund_id | str | Refund id generated by merchant. (Only present in case of refund callback) |
state | str | State of the order/refund. |
amount | int | Amount of the order/refund processed. |
expire_at | int | Expiry in epoch. |
error_code | str | Error code. (Only present when state is failed) |
detailed_error_code | str | Detailed error code. (Only present when state is failed) |
meta_info | MetaInfo | MetaInfo passed during the init of order. |
payment_details | List<PaymentDetail> | Payment details. |