Events & Callbacks
The legacy Card Enrollment SDK's onConnect, onSuccess, onError and onCancel callbacks, their payloads, and closing the SDK on a specific error.
Callbacks
Callbacks provide information about events that occur during the card enrollment process.
| What happens in the SDK | Callback |
|---|---|
| The cardholder submits the card form and verification begins | onConnect |
| The card is enrolled and the SDK shows "You're all set!" | onSuccess |
| Creating the card subscription or verifying the card fails, and the SDK shows a failure screen | onError |
The cardholder closes the SDK with the exit button, a click outside its frame or the ESC key. On a card form that is not empty, the SDK asks "Are you sure?" first; when you pass no terms, it asks on an untouched card form too | onCancel |
Each callback is described below, with what it passes to your function.
| Event | Description |
|---|---|
onConnect | Triggered when the cardholder submits the card form and verification begins. |
No payload.
| Event | Description |
|---|---|
onSuccess | Triggered when the customer successfully enrolls a card and activates a card subscription. |
Example Payload:
{
"subscriptionId": "1c6db37a-333a-4379-8ac5-0f819f2c0bf7",
"cardId": "8309b5f8-d5d8-49bb-9001-38bf1bb0f1e4",
"enrollmentGuidance": {
"availableEnrollmentMethods": [
"cardholder-single"
]
},
"authenticationFlow": "frictionless"
}
onSuccessalso returns the enrolledcardIdand the 3DSauthenticationFlow(challenge,frictionless, ornull). To retrieve card details as well as the latest subscriptionstatus, you can use thesubscriptionIdto call the GET Card Subscription endpoint.
| Event | Description |
|---|---|
onError | Indicates an error during the card enrollment process, such as failure to create a card subscription or verify the card. |
Example Payload (Server Error):
{
"type": "server",
"error": {
"detail": "Card verification step with id=d397da41-95ac-4bb0-82da-cd78d10d06ff for card verification with id=ed146b4a-8e48-4c7f-b284-62eb64dca7bb can not be completed at this state",
"title": "Bad Request"
},
"verificationId": "ed146b4a-8e48-4c7f-b284-62eb64dca7bb",
"cardId": "8309b5f8-d5d8-49bb-9001-38bf1bb0f1e4",
"subscriptionId": "1c6db37a-333a-4379-8ac5-0f819f2c0bf7"
}Example Payload (Client Error):
{
"type": "client",
"error": {
"detail": "Card subscription data is undefined."
}
}When the failure happens after the card subscription and verification exist,
onErroralso includes the discreteverificationId,cardId, andsubscriptionIdfields (all optional, omitted for pre-create rejections such as an invalid CVC or an ineligible card). PassverificationIdto GET Card Verification to read the verification'sfailureReason.
| Event | Description |
|---|---|
onCancel | Indicates that the customer canceled the enrollment flow, typically by clicking on the exit button, outside the SDK's frame, or by pressing the ESC key on the keyboard. |
No payload.
Handling specific errors and closing the SDK
In some scenarios, it may be necessary to close the SDK when a specific error occurs to allow the client to proceed with an alternative flow. For example, when the subaccount does not accept the card's type, the create fails with card_subscription.subaccount_blocking_card_type.
In such cases, the client can intercept the onError callback, close the SDK, and allow you to proceed with your own custom logic.
The following example demonstrates how to handle this use case:
CardEnrollmentSdk.openForm({
...
onSuccess: (data) => console.log(data),
onError: (data) => {
const cardTypeBlocked = "card_subscription.subaccount_blocking_card_type";
const { errorCode } = data.error;
if (errorCode == cardTypeBlocked) {
CardEnrollmentSdk.closeForm();
}
},
onCancel: onCancel,
...
});Updated about 1 hour ago
