Embedded Checkout Element
The Embedded Checkout Element lets you embed the full Airwallex-hosted checkout experience directly within your web page (via an iframe), allowing shoppers to complete their payment or subscriptions setup without being redirected to a separate Airwallex-hosted payment page.
Browser support
Embedded Checkout supports Google Chrome 102+, Microsoft Edge 102+, and Safari 26.2+.
createElement('embeddedCheckout', options)
Parameters
type
required'embeddedCheckout'options
requiredEmbeddedCheckoutOptionsembeddedCheckout Element.client_secret
requiredstringThe client_secret of the Billing Checkout that the element should render.
Obtain this value by calling the Airwallex Billing Checkout API from your server.
Returns
EmbeddedCheckoutElement | null
1import { init, createElement } from '@airwallex/components-sdk';23const { billing } = await init({4 env: 'demo', // Choose the Airwallex environment ('demo' or 'prod')5 enabledElements: ['billing'],6});78const element = await createElement('embeddedCheckout', {9 client_secret: 'replace-with-your-checkout-client-secret',10});1112element.mount('embedded-checkout');1314element.on('success', () => {15 // Navigate the merchant page to its post-checkout state.16});1718element.on('error', ({ code, message }) => {19 // Surface or log the error.20 console.error('Embedded Checkout error:', code, message);21});
destroy()
Permanently destroys the Element instance. The instance cannot be reused afterwards. Call createElement() again if you want to render the Embedded Checkout later.
1element.destroy();
mount(domElement)
Mounts the Element to your HTML DOM. Safe to call once per element instance; mounting the same instance twice has no effect.
Parameters
domElement
requiredstring | HTMLElement1// Ensure the container has a resolvable height, e.g.2// <div id="checkout" style="height: 720px"></div>34// 1. mount by container id5element.mount('checkout');67// 2. mount by container element8const container = document.getElementById('checkout');9element.mount(container);
on('ready', handler)
Parameters
type
required'ready'handler
requiredfunction1element.on('ready', () => {2 // The embedded checkout is ready; hide your own loading state.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
requiredfunction1element.on('success', () => {2 // Navigate the merchant page to its post-checkout state.3});
on('error', handler)
Parameters
type
required'error'handler
requiredfunctionCallback invoked every time the event fires.
The handler receives an object with the following properties:
code
requiredenumsecretExpired
invalidSecret
serviceUnavailable
paymentFailed
unsupportedBrowser
unsupportedElement
unknown
invalidContainer
invalidUiMode
message
optionalstringtype
optional'embeddedCheckout'1element.on('error', ({ code, message }) => {2 // Surface or log the error.3 console.error('Embedded checkout error:', code, message);4});
unmount()
Removes the Element from the DOM while keeping the instance available for remounting. Use this when you want to temporarily hide the checkout and display it again later. To permanently remove the Element and release its resources, call destroy() instead.
1element.unmount();