Skip to Content
Docs

Create a checkout

Bind a checkout to an authorized session and register callbacks that receive the payment result.

The pay.checkout() method binds a checkout to an authorized session and registers the callbacks that receive the result of the payment flow. Call this before rendering a form or submitting a payment.

const checkout = pay.checkout(options)

Parameters

ParameterTypeRequiredDescription
clientSecretstring | () => Promise<string>YesThe client_secret returned from creating a session on your server, or an async function that returns it. Authorizes the checkout on the client.
onSuccess(payment: PaymentResult) => voidNoCallback fired when the checkout flow completes successfully in the browser.
onFailure(error: PaymentError) => voidNoCallback fired when the checkout flow encounters an error.
onPending(payment: PaymentResult) => voidNoCallback fired instead of onSuccess when the payment is accepted but not final yet (for example, some alternative payment methods). Confirm the final status with webhooks.
localestringNoCheckout language, for example 'de-DE'. See Localization.
throwOnSubmitFailurebooleanNoWhen true, checkout.submit() rejects if the payment fails. Default: true.
mode'integrated' | 'modal'NoControls whether the form renders inline in the container passed to checkout.universal() ('integrated') or opens in a modal from a placed button ('modal'). Default: 'integrated'.
togglesobjectNoCheckout-wide display options. These are separate from the toggles of checkout.universal().
toggles.displayFailureMessagesbooleanNoShow a failed attempt's message in the form. The customer closes it to try again. Default: false.
toggles.displayEndOfSessionFailureMessagesbooleanNoShow a message in the form when the session expires or has no attempts left. Default: true.

The onSuccess and onPending callbacks receive a PaymentResult object:

FieldTypeDescription
amountnumberThe charged amount in minor units. 0 for setup sessions.
customerstringThe Pay.com customer ID.
paymentMethodstringStored payment method ID (pm_card_xxx). Present when setup_future_usage was set on the session.
statusstringTransaction status, for example succeeded for a charge, requires_capture for a hold, or pending (passed to onPending).
transactionstringThe charge (chrg_…), hold (hld_…), or setup session (ss_…) ID.

The onFailure callback receives a PaymentError object:

FieldTypeDescription
messagestringA human-readable description of the failure reason.
dataobjectAdditional failure details, when available.

onSuccess, onFailure, and onPending are browser-only callbacks. Always confirm payments server-side using webhooks. Never rely on client-side callbacks for order fulfillment.

Returns

A checkout instance used to render the form, validate fields, and submit payments.

Example

const checkout = pay.checkout({
  clientSecret: CLIENT_SECRET,
  onSuccess: (payment) => {
    console.log('Payment succeeded:', payment.transaction)
  },
  onFailure: (error) => {
    console.log('Payment failed:', error.message)
  },
})
Was this page helpful?