Checkout Elements
createCheckout(options)
Creates an instance of the Checkout Element for the desired element type. The returned Checkout instance manages the shared iframe bridge.
You must call the Airwallex Billing Checkout API to obtain the client secret before initializing this element.
Parameters
options
requiredCheckoutOptionsclient_secret
requiredstringThe client_secret of the Billing Checkout that the elements should render.
Obtain this value by calling the Airwallex Billing Checkout API from your server.
Returns
Promise<Checkout>
1import { init } from '@airwallex/components-sdk';23const { billing } = await init({4 env: 'demo',5 enabledElements: ['billing'],6});78const checkout = await billing.createCheckout({9 client_secret: 'replace-with-your-checkout-client-secret',10});
createElement(type)
Create an element within this Checkout instance.
Currently only 'paymentForm' is supported.
Parameters
type
requiredpaymentForm'paymentForm').Returns
Promise<PaymentFormElement>
1const paymentForm = await checkout.createElement('paymentForm');2paymentForm.mount('payment-form');
destroy()
1paymentForm.destroy();
mount(domElement)
Parameters
domElement
requiredstring1paymentForm.mount('payment-form');
on('ready', handler)
Parameters
type
required'ready'handler
requiredfunction1paymentForm.on('ready', () => {2 // The payment form is ready for customer interaction.3});
on('success', handler)
Emitted when the checkout has been completed successfully. Please note that some local payment methods may trigger browser navigation before a success event can be delivered. As a result, the current page may no longer be available when the payment completes.
Parameters
type
required'success'handler
requiredfunction1paymentForm.on('success', () => {2 // Navigate the merchant page to its post-checkout state.3});
on('error', handler)
Parameters
type
required'error'handler
requiredfunctioncode
requiredenumapiError
customerFormValidationFailed
paymentFailed
unknown
invalidContainer
invalidUiMode
invalidCheckoutStatus
bundleLoadFailed
invalidSecret
unsupportedElement
message
optionalstringtype
optional'paymentForm'1paymentForm.on('error', ({ code, message }) => {2 // Surface or log the error.3 console.error('Payment form error:', code, message);4});
unmount()
1paymentForm.unmount();