Handle events

The SDK provides several events you can listen to control the payment flow:

EventDescriptionHandler Signature
onReadyCalled when checkout is initialized and ready(event: CheckoutReadyEvent) => void
onSubmitCalled when user submits payment. Call event.resolve() to continue(event: PaymentSubmitEvent) => void
onSuccessCalled when payment succeeds. Call event.resolve() to complete(event: PaymentSuccessEvent) => void
onErrorCalled when payment fails. Call event.resolve() to allow retry(event: PaymentErrorEvent) => void
onInfoUpdatedCalled when info (e.g., cart contents) is updated(event: InfoUpdatedEvent) => void
onShippingUpdatedCalled 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();
}