Callbacks
resultCallback
The result callback is invoked when the payment handle is successfully created and is in the PAYABLE state or when there is an error in the checkout. It also passes an instance of the Checkout object. Using the functions provided in the instance object, the merchant can control the checkout experience.
The resultCallback contains the following elements.
Parameter | Type | Required | Description |
---|---|---|---|
instance | object | Yes | This is the Paysafe Payments Checkout instance. |
error | object | No | This object contains error information and is present if payment handle creation fails. |
result | object | Yes | This is the result that contains the payment token. |
{return} | undefined | false |
instance
Parameter | Type | Required | Description |
---|---|---|---|
isOpen | function | Yes | Checks if the overlay is still open. |
close | function | Yes | Closes the overlay without displaying result from payment. |
showSuccessScreen | function | Yes | Changes Checkout layout to success screen. |
showFailureScreen | function | Yes | Changes Checkout layout to failure screen. |
error
Parameter | Type | Required | Description |
---|---|---|---|
message | string | Yes | Provides an error that can be displayed to users. |
detailedMessage | string | Yes | Provides a detailed error message that can be logged. |
correlationId | string | Yes | This is a unique ID that can be provided to the Paysafe Support team as a reference for investigation. |
result
Parameter | Type | Required | Description |
---|---|---|---|
paymentHandleToken | string | Yes | This is the Payment Handle token to be included in the Payments API call. |
paymentMethod | string | Yes | This is the payment method used by the customer. |
customerOperation | string | Yes | This is the customer operation for the card. Possible values are:
|
amount | number | Yes | This is the amount used to create the Payment Handle. This is required because the user might change the amount in the Checkout. |
An example is shown below:
function(instance, error, result) {
if (result.token) {
// Successfully tokenized card, use result.token to process a payment
console.log(result.token);
// add AJAX code to send token to your merchant server
instance.showSuccessScreen("Your goods are now purchased. Expect them to be delivered in next 5 business days.");
} else {
// tokenization failed
instance.showFailureScreen("The payment was declined. Please, try again with the same or another payment method.");
}
}
closeCallback
The close callback This notifies the merchant script when the Checkout gets closed. The following actions invoke the closeCallback:
- When the customer closes the Checkout.
- When Merchant closes the Checkout using instance.close() method in the result callback after payments call.
The closeCallback contains the following elements.
Parameter | Type | Required | Description |
---|---|---|---|
stage | string | Yes | Stage during which the Checkout overlay is closed. Possible values are: PAYMENT_HANDLE_NOT_CREATED, PAYMENT_HANDLE_CREATED, PAYMENT_HANDLE_REDIRECT, PAYMENT_HANDLE_PAYABLE
|
expired | boolean | Yes | This indicates whether the close event was triggered after the Checkout expired. |
{return} | undefined | false |
riskCallback
Applicable to only Cards, PaySafe Cash, VIPP and Sightline.
This notifies the merchant with Amount and Payment method when user clicks the Pay/withdrawal button in checkout. The following actions invoke the riskCallback:
-
When the customer clicks the Pay/Withdraw button in checkout.
The riskCallback contains the following elements.
Parameter | Type | Required | Description | |
---|---|---|---|---|
amount | String | Yes | This is the amount which customer wants to pay. | |
paymentMethod | String | Yes | This is the payment method used by the customer. | |
instance | Object | Yes | This is the Paysafe Payments Checkout instance.. | |
decline | function | When this is invoked, checkout will consider callback risk-check as failed & render the message which you pass as a parameter in this function. Please refer example. | ||
accept | function | When this is invoked, checkout will consider callback risk-check as passed & proceed with payment handle creation. Please refer example. |