Skip to Content
Docs

Render express checkout buttons

Render Apple Pay and Google Pay buttons anywhere on your site, outside the checkout form, and respond to shipping changes in the wallet sheet.

The checkout.express() method renders Apple Pay and Google Pay buttons in a container on your page, such as a product page or the cart, outside Universal checkout. Express checkout explains how to add the buttons and how a payment runs from the tap to the charge.

const buttons = checkout.express(options)

Express checkout amounts are decimal strings in major units, such as '18.00', because that's what the wallet sheets show. Pay.com API amounts are in minor units (1800 for the same $18.00).

Parameters

checkout.express() takes one options object. Only container is required.

ParameterTypeRequiredDescription
containerstringYesA CSS selector for the element the buttons go into, one per wallet, stacked.
wallets('applepay' | 'googlepay')[]NoWhich wallets to offer, in this order. Defaults to both.
request{ shipping?, email?, phone? }NoWhat the sheet asks the customer for. Each one defaults to the Apple Pay or Google Pay collection settings of your Pay.com account.
total{ amount, label? }NoWhat the sheet opens with. Defaults to the session amount, labeled with your merchant name.
lineItemsExpressLineItem[]NoItems to show ({ label, amount, kind? }). kind is item (default), subtotal, tax, discount, or shipping. Google Pay shows it, and Apple Pay ignores it.
shippingOptionsExpressShippingOption[]NoShipping options to open with before the customer picks an address ({ id, label, amount, detail? }). detail is, for example, the delivery estimate.
onClick(context) => void | boolean | updateNoRuns synchronously on the tap. Return false to keep the sheet closed, or return { total?, lineItems?, shippingOptions? } to set what the sheet opens with. Make network requests in the handlers below or in beforePay, not here.
onShippingAddressChange(address, context) => ExpressShippingUpdate | Promise<…>NoReturn { shippingOptions, total, lineItems? }, or return { error: { reason?, message? } }, where reason is address_unserviceable or address_invalid. The first option is preselected, so total must include its price.
onShippingOptionChange(option, context) => ExpressUpdate | void | Promise<…>NoReturn { total, lineItems? }. If the handler returns nothing, the total stays the same.
onCancel(context) => voidNoCalled when the customer closes the sheet without paying.
styleobjectNoSee Button style.

context is { wallet }, the wallet the customer is using. An address has name, line1, line2, city, state, postalCode, and country (ISO 3166-1 alpha-2, uppercase), all optional.

Button style

Set style to change the buttons' height and corner radius, and each wallet's button style and type.

OptionTypeDefault
style.heightnumber48 (px)
style.borderRadiusnumber4 (px)
style.applepay.buttonStyle'black' | 'white' | 'white-outline''black'
style.applepay.type'plain' | 'buy' | 'check-out' | 'continue' | 'order' | 'pay' | 'book' | 'donate''plain'
style.googlepay.buttonColor'default' | 'black' | 'white''default'
style.googlepay.buttonType'plain' | 'buy' | 'checkout' | 'order' | 'pay' | 'book' | 'donate''plain'

Returns

MemberTypeDescription
readyPromise<('applepay' | 'googlepay')[]>Resolves with the wallets that rendered. Empty when the browser or the session supports neither. Rejects when container matches nothing or the session can't load. The SDK only logs a console warning, so handle the rejection.
update(update)(update) => voidSets the total, line items, and shipping options for the next sheet, for example after a quantity change.
destroy()() => voidRemoves the buttons.

For the reasons a wallet's button might not render, see When buttons don't show.

Errors

A payment from an express checkout button reports its result the same way as any other payment method. When it's paid, the SDK calls onSuccess (or onPending) and emits payment_success (or payment_pending). When it fails, the SDK calls onFailure. Two failures are specific to express checkout. Both call onFailure and emit payment_failure, with data.code set to:

data.codeWhen
'amount_changed'The session's currency or amount differs from the total the customer approved, so the SDK doesn't start the payment. The sheet shows "The amount to pay changed. Please review your order and try again".
'timed_out'An Apple Pay payment didn't start within 20 seconds of the customer's approval. Nothing is charged, and the sheet tells the customer to try again.

If the checkout moves to another session before the charge, for example because your page called pay.checkout() again, nothing is paid and onFailure is called. When the amount check catches the change, onFailure gets data.prevSessionId and data.newSessionId. When the change comes after the check, it gets the message "The transaction was replaced by a new checkout session".

A payment that beforePay stops isn't a declined payment. The SDK emits no payment_failure event and doesn't call onFailure. See beforePay.

Example

const buttons = checkout.express({
  container: '#express-checkout',
  request: { shipping: true, email: true },
  lineItems: [{ label: 'Coffee beans', amount: '18.00' }],
  total: { amount: '18.00' },
})

const wallets = await buttons.ready   // ['applepay', 'googlepay'], or [] when neither can show
Was this page helpful?