The script
Shoppex.supports.mount.
HTML block
data-shoppex-element="checkout" it finds, also ones your page adds later. Only checkout is supported as a value.
JSON the script cannot read is named in the console as
Invalid data-shoppex-appearance JSON and left out. The HTML block sends its events as DOM events on the <div>. See DOM events.
Mount with JavaScript
defer, so Shoppex exists only after the page is parsed. Call Shoppex.mount from a type="module" script, which runs after it, or from your own code that runs after load.
Shoppex.mount(target, options) takes a CSS selector or an element and returns the block.
Options the script cannot use do not throw. The block shows “Checkout didn’t load”, and your page gets the
invalid_options error with the reason in the console.
The block
An error from
mount itself, like invalid_options or already_mounted, arrives after mount returns, so a listener you add right away hears it.
One block per page
A page holds one Elements checkout. A secondShoppex.mount reports already_mounted and leaves the first block working. Call destroy() on the first block before you mount another.
In a single-page app, call destroy() when the route leaves. A block whose element was removed from the page without destroy() is cleaned up by the next mount.
React
Checkout.tsx
<ShoppexInlineCheckout> renders a <div> and mounts the block into it with the same script. It takes every option above as a prop, plus onReady, onSuccess, onError, onEvent (every event), className and style. A new appearance restyles the block in place. A change to any other prop mounts a new block. It needs @shoppexio/checkout-js 0.9.0 or later.
Without React, the package exports mount(target, options) with the same options and block methods. It loads the script for you.
Global settings
Shoppex.init sets values for every block and buy button on the page: