Guide

Tokenization webhooks

Every webhook event fired during card-saving and saved-card lifecycle, with payload shape and a minimal handler.

When events fire

Saving a card produces a short, predictable sequence of events on your webhook endpoint. Most are informational; the bolded event is the one you act on.

When you vault a card on its own with a hosted setup-mode Checkout Session:

OrderEventWhat it means
1payment_method.attachedThe card is now attached to the Customer.
2mandate.createdConsent to reuse the card was recorded.
3setup_intent.succeededCard vaulted and ready to charge — act here.

When you charge and save in one step (a Checkout Session with setup_future_usage), the sequence is the same except the final, headline event is payment_intent.succeeded — the card is vaulted and the money is captured.

Everything above is delivered to your endpoint. Treat the bolded event as your signal to fulfill and persist; the rest are useful for refreshing UI, audit logs, and recovery.

Verifying every event

Same signature scheme as the rest of webhooks. See Webhooks. All examples below assume you've already verified.

JavaScript
1function handle(event) {
2 switch (event.type) {
3 case "setup_intent.succeeded":
4 return onSetupSucceeded(event.data); // pass event.data; handlers access .object
5 case "payment_intent.succeeded":
6 return onPaymentSucceeded(event.data);
7 case "payment_method.detached":
8 return onPmDetached(event.data);
9 case "payment_method.expired":
10 return onPmExpired(event.data);
11 case "mandate.revoked":
12 return onMandateRevoked(event.data);
13 // ...
14 }
15}

Always dedupe by event.id. Webhooks may be redelivered.

Setup Intent events

setup_intent.requires_action

The customer hit a 3DS challenge. The hosted page handles it, and there is no URL to send the customer to; your job is to show "verifying…" if you have a custom dashboard, then wait for setup_intent.succeeded or setup_intent.setup_failed. The event, like the SetupIntent's next_action, carries the action's type only.

setup_intent.succeeded

Card vaulted. The most important SI event. The event gives you the paymentMethodId; GET/v1/payment-methods/{id} to read the card details and mandate, then persist them on your customer record.

JSON
1{
2 "id": "evt_01JQX...",
3 "object": "event",
4 "type": "setup_intent.succeeded",
5 "created": 1744054500,
6 "createdAt": "2026-04-07T18:35:00.000Z",
7 "apiVersion": "2026-01-01",
8 "livemode": false,
9 "merchantOrgId": "morg_01JQX...",
10 "data": {
11 "object": {
12 "setupIntentId": "seti_01JQX...",
13 "customerId": "cus_01JQX...",
14 "paymentMethodId": "pm_01JQX...",
15 "paymentMethodTypes": ["card"],
16 "usage": "off_session",
17 "status": "succeeded",
18 "description": null,
19 "metadata": {}
20 }
21 }
22}
JavaScript
1async function onSetupSucceeded(data) {
2 const seti = data.object;
3 // GET the PaymentMethod to read card details + mandate
4 const pm = await cxpay.paymentMethods.retrieve(seti.paymentMethodId);
5 await db.customers.update(seti.customerId, {
6 last_saved_pm: pm.id,
7 last_saved_mandate: pm.mandate,
8 });
9}

setup_intent.setup_failed

A confirm attempt was rejected by the network. The SetupIntent stays open — the customer can try again with a different card. Inspect last_setup_error.code to surface a reason.

setup_intent.canceled

The SetupIntent expired or was canceled. Inspect cancellation_reason. No fulfillment action; close any "saving…" UI you may have shown.

setup_intent.updated

A field on an open SetupIntent changed through an update. data.object.previousAttributes holds the earlier value of each changed field, or null where it had none.

Payment Method events

payment_method.attached

A PM was attached to a customer (during a SI/PI+SFU success or via direct /attach).

JSON
1{
2 "id": "evt_01JQX...",
3 "object": "event",
4 "type": "payment_method.attached",
5 "created": 1744054500,
6 "createdAt": "2026-04-07T18:35:00.000Z",
7 "apiVersion": "2026-01-01",
8 "livemode": false,
9 "merchantOrgId": "morg_01JQX...",
10 "data": {
11 "object": {
12 "paymentMethodId": "pm_01JQX...",
13 "type": "card",
14 "card": { "brand": "visa", "last4": "4242", "expMonth": 12, "expYear": 2030 },
15 "customerId": "cus_01JQX...",
16 "billingDetails": null,
17 "metadata": {}
18 }
19 }
20}

Use this to invalidate any cached "saved cards" view in your UI.

payment_method.detached

The card was detached from its customer. The PM is no longer chargeable and outstanding active mandates were revoked. Detach is permanent: the card cannot be attached again, so the customer has to save it again.

payment_method.deleted

A DELETE/v1/payment-methods/:id was issued. The PM is purged — the stored card token is destroyed and card data redacted. Use to satisfy your own GDPR/CCPA logging.

payment_method.expired

The card is past its exp_month/exp_year. The PM moved to expired; off-session charges will fail until the customer re-enters.

JavaScript
1async function onPmExpired(data) {
2 const pm = data.object;
3 await sendEmail({
4 to: pm.billingDetails?.email,
5 subject: "Update your payment method",
6 body: `Your ${pm.card.brand} •• ${pm.card.last4} has expired.`,
7 });
8}

payment_method.compromised

You (or our risk system) flagged the PM as compromised. Charges blocked. Detach + ask the customer to re-add a fresh card. The body does not carry the reason for the flag.

payment_method.automatically_updated

The card network pushed an update — new expiry, sometimes a new last4 — via the Account Updater service. The PM is still chargeable; no customer action needed.

payment_method.vault_failed

A PaymentIntent with setup_future_usage succeeded, but the card data we got back was incomplete, so the card was not saved. The payment is not affected. No PaymentMethod exists, so data.object carries paymentIntentId, customerId and reason (card_data_incomplete). Collect the card again before you charge it off-session.

Mandate events

mandate.created

A new Mandate authorized a saved card. Always fires alongside setup_intent.succeeded or payment_intent.succeeded (when SFU was set). This is the "chargeable" signal: until it fires, an off-session charge on the card is refused with MANDATE_REQUIRED.

JSON
1{
2 "id": "evt_01JQX...",
3 "object": "event",
4 "type": "mandate.created",
5 "created": 1744054500,
6 "createdAt": "2026-04-07T18:35:00.000Z",
7 "apiVersion": "2026-01-01",
8 "livemode": false,
9 "merchantOrgId": "morg_01JQX...",
10 "data": {
11 "object": {
12 "mandateId": "mdt_01JQX...",
13 "paymentMethodId": "pm_01JQX...",
14 "customerId": "cus_01JQX...",
15 "type": "multi_use",
16 "status": "active",
17 "customerAcceptance": {
18 "type": "online",
19 "acceptedAt": "2026-04-07T18:30:00.000Z",
20 "online": { "ipAddress": "203.0.113.42", "userAgent": "..." }
21 }
22 }
23 }
24}

mandate.updated

Not currently sent; reserved. Do not build on this event.

mandate.revoked

The mandate is inactive. Either you called /revoke, the cardholder filed a chargeback that triggered automatic revocation, or the underlying PM was detached.

JavaScript
1async function onMandateRevoked(data) {
2 const mdt = data.object;
3 // Stop scheduling future charges
4 await db.subscriptions.markCanceled(mdt.mandateId);
5}

PaymentIntent events (cross-reference)

Already documented in the main webhooks guide:

  • payment_intent.succeeded — money captured. The headline event.
  • payment_intent.payment_failed: declined. For a saved-card charge, read last_payment_error on the PaymentIntent: code, retryable and advice_code.
  • payment_intent.processing: the outcome of a charge is not known. Do not charge again under a new Idempotency-Key. See Charging saved cards. A PaymentIntent that never resolves moves to uncertain, then requires_review, with no webhook: read its status from the API.
  • payment_intent.requires_action: a payer step on the hosted page. An off-session charge never emits it: when the bank wants the cardholder, the charge fails with authentication_required.

A saved-card charge refused before anything is charged (no mandate, a revoked mandate, a detached card) emits no event. The API call answers with the error.

When setup_future_usage is in flight, payment_intent.succeeded fires. The data.object contains paymentIntentId and customerId. To read the saved card and mandate, use the payment_method.attached event that fires alongside (it carries paymentMethodId) and GET/v1/payment-methods/{id}.

Idempotency

Every handler must be idempotent. We make up to 8 attempts (the first delivery, then up to 7 retries) with exponential backoff on non-2xx or timeout, at about 5s → 30s → 2m → 10m → 1h → 4h → 12h (~17h total window). These delays are approximate: a retry can run up to about 5 minutes after its scheduled time. Your endpoint must start responding within 5 seconds. With no 2xx by then we retry, so the same event can arrive again. Delivery order is not guaranteed. Use event.id as your dedupe key — store it before any side-effect.

JavaScript
1async function handleWebhook(event) {
2 if (await db.processed_events.exists(event.id)) return; // skip
3 await db.processed_events.insert(event.id);
4 await handle(event);
5}

Powered by CX Pay