Skip to content

Add express buttons

Add Apple Pay, Google Pay and PayPal express buttons to a product or cart page, and choose who creates the order — createOrder, orderId or orderLines.

The wallet collects the customer’s address and payment, Kustom prices shipping and completes the order, then your code redirects to confirmation. To connect the buttons to an order, initialize the element using one of the three options below.

  • Elements installed on a registered domain — see Install Kustom Elements.
  • The Express buttons setup in the Portal. Under Elements, open Express buttons and fill in the push URL and confirmation URL (the validation URL is optional). They’re required whichever way you create the order. Without them the element renders nothing.
  • Shipping Assistant configured on your Merchant ID. The wallet sheet’s shipping options come from it.
  • For PayPal, a connected PayPal account. Without one the PayPal button never appears; the others are unaffected.

Put the element where the buttons should appear:

<kustom-express-buttons id="express" locale="sv-SE"></kustom-express-buttons>
AttributeRequiredWhat it does
localeYes, in practiceThe market, as language-COUNTRY. The country picks the purchase country and filters the wallets to those enabled for that market. Left out, it defaults to a bare en with no market at all.
reveal-modeNoprogressive (the default) shows each button as it becomes ready; full holds a loading placeholder until all of them are.

The id isn’t special — it’s only what the selector in initialize points at. Any CSS selector works, and only the first element it matches is initialized.

Buttons appear for methods selected in the Portal, enabled for the market and supported by the customer’s browser.

Initialize with these shared fields and add createOrder, orderId or orderLines, as described below:

window.kustomElements('express.initialize', '#express', {
currency: 'SEK',
shippingAddressRequired: true,
// + createOrder, orderId or orderLines
onConfirm: (result) => {
window.location.href = result.redirectUrl;
},
onError: (error) => {
console.error(error.code, error.message);
},
});

Leave shippingAddressRequired set to true. It’s what brings Shipping Assistant’s options into the wallet sheet, and the createOrder hook depends on it.

You can call initialize again on the same element — when the cart changes, for instance. A changed configuration rebuilds the buttons; an identical one only swaps in the new callbacks.

Send the customer to your confirmation page

Section titled “Send the customer to your confirmation page”

On completion, onConfirm receives { orderId, status, redirectUrl }. Redirect to redirectUrl, the order’s confirmation URL with placeholders resolved. The element keeps a “finalizing your purchase” overlay visible until your code navigates.

Handle push, acknowledgment and fulfillment as for embedded Checkout. See Confirmation and push.

onError receives { code, message }:

codeMeans
NO_EXPRESS_METHODSNo wallet could be shown for this market, configuration and browser. Hide whatever surrounds the buttons. Also fired as an expressError DOM event on the element.
MERCHANT_ABORTEDYour createOrder called reject. The purchase stops.
MERCHANT_HOOK_INVALID_RESPONSEYour createOrder resolved without an orderId.
PAYMENT_SUBMIT_FAILED, PAYMENT_FAILEDThe wallet payment didn’t go through.
DEPENDENCY_LOAD_FAILEDThe wallet provider’s script couldn’t load in the browser.

onError only fires after the buttons exist. If initialization fails because of an unregistered domain, missing Portal setup, unknown orderId or unmatched selector, the element stays empty and the kustomElements(...) promise never settles. Don’t block the rest of the page on it.

Errors appear only in the browser. Forward them from onError if you need server logs.

The creation option determines the order’s URLs, source of prices and creation time.

no order yetan order existsPayPal is a step earlier: its popup can't open without an order
Your server, at pay timeYour server, before the page loadsKustom, from the browser
You passcreateOrderorderIdorderLines only
FitsA product page “buy now”, a cart or mini cartBeside a checkout you have already created an order forA prototype with no backend
The order’s merchant_urlsYours, from your create callYours, from your create callThe URLs in the Portal’s Express buttons setup
Prices and tax come fromYour serverYour serverThe browser — anyone can change them
An order existsOnly once the customer starts payingFor every page view, whether anyone pays or notOnly once the customer starts paying
When the cart changesThe order is built fresh at pay time; only the displayed total can go staleReplace the element and initialize it againInitialize again with the new lines

Use createOrder for server-controlled prices and URLs at pay time. Kustom’s platform add-ons use this option. If Kustom creates the order from browser lines instead, it uses the Portal’s URLs, including the confirmation page.

If you pass more than one, orderId wins over createOrder, and createOrder over plain orderLines.

Your server creates the order from its cart when the customer starts paying. Browser prices aren’t used in the order.

In the browser, add orderLines for the sheet to show and a createOrder hook:

window.kustomElements('express.initialize', '#express', {
currency: 'SEK',
shippingAddressRequired: true,
// Shown in the wallet sheet until the real order exists. Not sent to the order.
orderLines: [
{ name: 'Wool sweater', type: 'physical', totalAmount: 79900, taxAmount: 15980,
productUrl: 'https://my-shop.com/p/wool-sweater' },
],
createOrder: (resolve, reject) => {
fetch('/express/order', { method: 'POST' })
.then((res) => (res.ok ? res.json() : Promise.reject(res.status)))
.then((order) => resolve({ orderId: order.order_id }))
.catch(reject);
},
onConfirm: (result) => {
window.location.href = result.redirectUrl;
},
onError: (error) => {
console.error(error.code, error.message);
},
});

On your server, /express/order builds the order from the customer’s cart and creates it with POST /checkout/v3/orders, exactly as for the embedded checkout, then returns its order_id. The browser sends no prices.

Hook requirements:

  • Call resolve({ orderId }) — don’t return it. The hook is run as a promise executor, so returning an id, including from an async function, leaves the purchase waiting indefinitely. There is no timeout. Call reject to abort.
  • It runs on the address, not the tap — except for PayPal. Apple Pay, Google Pay, Klarna and Amazon Pay share one wallet sheet, which opens without an order and calls createOrder when the customer first chooses an address — so without shippingAddressRequired: true they never call it at all. PayPal runs on its own SDK, and its popup can’t open until it has an order, so it calls createOrder on the tap: before any address, and whether or not the customer goes on to pay.
  • orderLines are for display only. The sheet shows their total until the order exists, then switches to the order’s real total with shipping, so make them as close to the final amount as you can. Amounts are in minor units and include tax. The fields are exactly the five above; anything else on a line, such as quantity, is ignored, so put the quantity into totalAmount.
  • Create a fresh order on every call. If the customer closes one wallet and opens another, the hook runs again. Reusing an order from an earlier attempt fails once that order has moved on.

Create the order under the same Merchant ID as the Elements script. Set these order options for the wallet flow:

  • Limit shipping_countries to the purchase country. Your server isn’t told when the customer picks an address in the sheet, so anything you priced by country — tax, your own shipping_options — is only right for the country you created the order for.
  • Leave options.date_of_birth_mandatory off. A wallet sheet can’t collect a date of birth, so an order that requires one can’t complete, and the purchase fails with PAYMENT_FAILED.

On a product page, create the order from the selected product and quantity. Keep the customer’s existing cart unchanged. When the selection changes, initialize again with new orderLines to update the displayed total.

Your server creates it before the page loads

Section titled “Your server creates it before the page loads”

If an order exists before the page renders — typically the one behind an embedded checkout on the same page — hand the buttons its id. They read the lines and currency from the order, so they always show what the order holds.

window.kustomElements('express.initialize', '#express', {
orderId: checkoutOrderId,
currency: 'SEK',
shippingAddressRequired: true,
onConfirm: (result) => {
window.location.href = result.redirectUrl;
},
});

The order must belong to the same Merchant ID as the Elements script, and must not already be completed. Any createOrder you pass alongside is ignored.

The element reads the order only at initialization. After an order update, replace the element and initialize the new one. Reinitializing the existing element with the same id is ignored as an identical configuration.

Pass the lines and nothing else, and Kustom creates the order from them when the customer starts paying. Your server isn’t involved until the push arrives.

window.kustomElements('express.initialize', '#express', {
currency: 'SEK',
shippingAddressRequired: true,
orderLines: [
{ name: 'Wool sweater', type: 'physical', totalAmount: 79900, taxAmount: 15980,
productUrl: 'https://my-shop.com/p/wool-sweater' },
],
onConfirm: (result) => {
window.location.href = result.redirectUrl;
},
});

Use this option for prototypes, not real orders:

  • The order takes the Portal’s URLs. Push and confirmation go to the URLs in the Express buttons setup, not to anything you choose per order, and the order belongs to the Merchant ID the Elements script belongs to.
  • The amounts come from the browser. Order lines in a page can be edited by anyone with developer tools, so check the amount against your own cart on push before you fulfill.
  • You hear about the order only from the push. Nothing on your server created it.

When the cart changes, initialize again with the new lines. merchantReference1 and shippingOptions (fallback shipping options for when Shipping Assistant can’t supply any) are only used in this option.

On a registered domain, load the page in a browser that supports at least one of your wallets, with Playground credentials:

  1. At least one button renders. If the element stays empty, see Troubleshooting.
  2. Open the wallet sheet and choose an address. With createOrder, your server receives the request at that point (on the tap, for PayPal). The sheet’s total changes to include shipping.
  3. Pay. onConfirm fires, the browser lands on the confirmation page and the push arrives.

The element stays empty. In this order: the domain isn’t registered in the Portal, the Express buttons setup has no URLs, the locale has no country or names a market none of your methods cover, or the selector passed to initialize matches nothing. None of these reach onError — check the browser console for an unhandled rejection.

The sheet opens but your server never sees createOrder. shippingAddressRequired isn’t true, or the customer hasn’t chosen an address yet. Only PayPal calls the hook on the tap.

The purchase sits on “finalizing” forever. Your createOrder returned a value instead of calling resolve, or the request it made never finished.

One wallet is missing. Apple Pay needs a browser and device that offer it; PayPal needs a connected PayPal account; and every method has to be both chosen in the Portal and enabled for the market the locale names.

This page is also available as Markdown — append .md to its URL — and is indexed in llms.txt.