Callbacks
In the Checkout SDK, callback functions are essential for providing real-time updates on the status of payment transactions.
These callbacks improve the user experience by enabling seamless and efficient handling of different payment scenarios, including:
Successful payments
Transaction cancellations
Errors encountered during the payment process
All the callbacks described below can be triggered for any type of payment.
The errorCallback function is triggered when an issue occurs during the payment process. Proper error handling is essential to ensure a smooth user experience.
Best Practice for Handling Errors
In the event of an error, the recommended approach is to restart the checkout process by generating a new session_id through the Checkout API.
Defining the errorCallback Function
The errorCallback function can be defined using the data-error attribute on the Checkout script tag. This attribute allows the specification of a global function to handle errors.
When an error occurs, the errorCallback function is invoked with a data JSON object, where data.status is set to error.
Params Available in data JSONObject for errorCallback
messagemandatoryform_of_paymentmandatorystatusmandatorychallenge_occurredoptionalsession_idoptionalorder_nooptionalreference_numberoptional
The cancelCallback function in the Checkout SDK is triggered when a payment is canceled.
Defining the cancelCallback Function
The cancelCallback function can be defined using the data-cancel attribute on the Checkout script tag. This attribute allows the specification of a global function to handle cancellations.
Invocation of cancelCallback
If a customer cancels a payment, the cancelCallback function is invoked with a data JSON object, where data.status is set to canceled.
Params Available in data JSONObject for cancelCallback
messagemandatoryform_of_paymentmandatorychallenge_occurredoptionalsession_idoptionalstatusmandatoryorder_nooptionalreference_numberoptionalpayment_gateway_infooptional
In both cancelCallback and errorCallback, the SDK must be reinitialized, either on the same session or on a new session.
In the Checkout SDK, the successCallback function is triggered upon the successful completion of the payment process.
Defining the successCallback Function
The successCallback function is defined and assigned as the value of the data-success attribute within the Checkout script tag.
Invocation of successCallback
When a payment is successfully processed, the successCallback function is invoked with a data JSON object, where data.status is set to success.
Params Available in data JSONObject for successCallback
messagemandatoryform_of_paymentmandatorychallenge_occurredoptionalsession_idoptionalstatusmandatoryorder_nooptionalreference_numberoptionalredirect_urloptionalpayment_gateway_infooptional
Last updated