Skip to Content
Docs

Listen for checkout events

Register a callback for the events a checkout emits, from the form being ready to a payment's result.

The checkout.on() method registers a callback for an event the checkout emits, such as the form becoming ready or a payment succeeding. Use it to update your page as the checkout changes.

checkout.on(checkout.EVENT_TYPES.PAYMENT_SUCCESS, (payment) => {
  console.log('Paid:', payment.transaction)
})

Parameters

ParameterTypeRequiredDescription
eventNamecheckout.EVENT_TYPES valueYesThe event to listen for. Each value is the event's name. For example, checkout.EVENT_TYPES.PAYMENT_SUCCESS is 'payment_success'. In TypeScript, pass the EVENT_TYPES value.
callback(payload) => voidYesCalled each time the event is emitted, with the event's payload when it has one.

checkout.once() takes the same parameters and calls the callback only the first time. checkout.removeListener(eventName, callback) removes a callback. Listeners stay registered for the page, across pay.checkout() calls, until you remove them.

Events

The checkout emits events for payments, setup sessions, the session, and the form.

Payments

Payment events follow each payment attempt, from its start to its result.

EVENT_TYPESEventPayloadWhen
PAYMENT_PROCESSINGpayment_processingNoneA payment starts. The customer submits the form or taps a wallet or payment method button, or you call checkout.headless() or checkout.pay().
PAYMENT_SUCCESSpayment_successThe PaymentResult object, matching what onSuccess receives.A payment succeeds.
PAYMENT_PENDINGpayment_pendingThe payment, as for payment_success.A payment was accepted but isn't final yet. Confirm its status with webhooks.
PAYMENT_FAILUREpayment_failureThe PaymentError object ({ message, data }), matching what onFailure receives.A payment attempt fails.
PAYMENT_PENDING_APPROVALpayment_pending_approvalThe payment, as the API returned it.In Universal checkout, a payment came back pending, and the form keeps checking until its status is final.

pay.checkout() describes PaymentResult and PaymentError. checkout.pay() doesn't call onSuccess, onPending, or onFailure, but it emits these events.

Setup sessions

A setup session saves a payment method without charging it. These events mark its progress.

EVENT_TYPESEventPayloadWhen
SETUP_PROCESSINGsetup_processingNoneIn a Universal checkout setup session, the customer submits the form.
SETUP_SUCCESSsetup_successThe setup result, matching what onSuccess receives.In a Universal checkout setup session, the payment method is saved.

The session

Both session events mean the session can't take another payment.

EVENT_TYPESEventPayloadWhen
SESSION_EXPIREDsession_expiredNoneIn Universal checkout, the session's client_secret expired, so the form can't take a payment anymore.
MAX_ATTEMPTS_REACHEDmax_attempts_reachedThe error of the last attempt.In Universal checkout, the session's last attempt failed, so the session can't be paid again. This event comes before that attempt's payment_failure.

The form

Form events report when the checkout loads, and when the form's validity, card funding type, or enabled state changes.

EVENT_TYPESEventPayloadWhen
CONTENT_READYcontent_readyNoneThe Universal checkout form has loaded. Call checkout.updateMetadata() after it.
HEADLESS_READYheadless_readyNoneHeadless checkout has loaded the session.
FORM_VALIDATION_UPDATEDform_validation_update{ validationResult }, where validationResult is true when every field is valid.The Universal checkout form becomes valid or invalid.
CARD_FUNDING_TYPE_UPDATEcard_funding_type_update{ fundingType }, for example 'debit', or null when unknown.In Universal checkout, the funding type of the card being entered or selected changes. The SDK looks it up only while you listen for this event, and then passes it to onValidateSession as fundingType.
SET_DISABLE_UIset_disable_ui{ data }, where data is true when the form was disabled and false when it was enabled.The Universal checkout form was disabled or enabled, for example by setDisabled() on the object checkout.universal() returns.

Events are browser-side, like onSuccess. Always confirm payments server-side using webhooks before you fulfill an order.

Example

checkout.on(checkout.EVENT_TYPES.PAYMENT_PROCESSING, () => {
  showSpinner()
})

checkout.on(checkout.EVENT_TYPES.PAYMENT_SUCCESS, (payment) => {
  hideSpinner()
  console.log('Paid:', payment.transaction)
})

checkout.on(checkout.EVENT_TYPES.PAYMENT_FAILURE, (error) => {
  hideSpinner()
  console.log('Payment failed:', error.message)
})
Was this page helpful?