Handle events
The SDK provides several events you can listen to control the payment flow:
| Event | Description | Handler Signature |
|---|---|---|
onReady | Called when checkout is initialized and ready | (event: CheckoutReadyEvent) => void |
onSubmit | Called when user submits payment. Call event.resolve() to continue | (event: PaymentSubmitEvent) => void |
onSuccess | Called when payment succeeds. Call event.resolve() to complete | (event: PaymentSuccessEvent) => void |
onError | Called when payment fails. Call event.resolve() to allow retry | (event: PaymentErrorEvent) => void |
onInfoUpdated | Called when info (e.g., cart contents) is updated | (event: InfoUpdatedEvent) => void |
onShippingUpdated | Called when shipping selection changes | (event: ShippingUpdatedEvent) => void |
Using Events for Custom Logic
You can use the onSubmit event to run async logic before payment is processed:
onSubmit: async (event) => {
// Perform async merchant logic
// e.g., create internal order, freeze stock, validate inventory
try {
await merchantApi.createOrder({
items: cartItems,
customer: customerInfo
});
// Async done - continue with payment
event.resolve();
} catch (error) {
// Cancel payment if order creation fails
event.reject(error);
}
}You can use the onSuccess event to handle post-payment logic:
onSuccess: async (event) => {
// Log the transaction
console.log('Transaction ID:', event.transaction?.transactionId);
console.log('Order ID:', event.orderId);
// Redirect to return URL or show success page
window.location.href = event.returnUrl;
event.resolve();
}Updated about 1 month ago