{"object":"doc","slug":"billing-events","title":"Billing events reference","summary":"Every billing event type, when it fires, what data.object holds, and what your handler should do with it, including invoice.upcoming three days before a renewal. ZeroPoint sends no email to your customers; your app sends its own from these events.","tags":["guide","billing","webhooks","events","subscriptions","reference"],"body":"# Billing events reference\n\nBilling events use the same signed envelope as payment events: `id` (`evt_...`), `type`, `created`, `livemode`, `merchant_id`, `api_version` and `data` (`object`, `object_version`, and `previous_attributes` on updates). `data.object` is the Stripe-shaped object as committed by the change that fired the event: integer cents, Unix seconds. How to subscribe, verify the `ZeroPoint-Signature` header and catch up after an outage: [Billing webhooks](billing-webhooks.md).\n\nBilling events are opt-in. An endpoint with an empty `event_types` receives payment events only; list the types below, or `[\"*\"]`.\n\nZeroPoint sends no email to your customers: no receipts, reminders or failed-payment notices. Your app sends its own from these events, in its own name.\n\n## Handler rules\n\n1. Verify the signature over the raw body, then deduplicate by `event.id` in durable storage. Deliveries repeat and can arrive in any order.\n2. Overwrite your stored copy of an object only when `data.object_version` is greater than or equal to the one you hold. Never use it to skip a handler: one change can send two events at the same version.\n3. Decide access from your stored copy of the subscription's `status`, never from `current_period_end` and never from the event in hand alone.\n4. Answer 2xx within 10 seconds; do slow work after answering.\n5. A `customer.subscription.updated` whose only change is `payment_hold` means a charge is being confirmed: do nothing.\n6. A `customer.subscription.updated` may carry `data.reason`, beside `data.object`, when it reports a change your code did not make. On billing events `data.reason` is always an object with a `code` and the ids it names: `{\"code\": \"scheduled_change_not_restored\", \"change\": \"sch_...\", \"price\": \"price_...\", \"subscription\": \"sub_...\"}` (a failed upgrade did not bring back the downgrade it replaced, because another subscription of the buyer holds that price) or `{\"code\": \"scheduled_change_refused_subscription_exists\", ...}` (a scheduled change fell due onto a price, or under the `product` and `customer` guards a product, that another subscription of the buyer holds, with `subscription_guard` not `off`: it was canceled and the subscription renews on its current price). `subscription` names the one that holds the price. Before that renewal the subscription object already says so: `scheduled_change.blocked_by` carries the same code while the change would be refused as things stand (it can change with no event on that subscription: see [Upgrades, downgrades and cancel](upgrades-downgrades-and-cancel.md)). Note: `payment.needs_attention` has its own `reason`, a string; that one is unchanged.\n7. Skip any event whose `data.sample` is true (samples from `send_sample_event`).\n\n## Subscription events\n\n| Type | Fires when | Do |\n|---|---|---|\n| `customer.subscription.created` | A subscription was created: by `POST /v1/subscriptions` (status `incomplete` until the first payment captures) or by checkout (already `active`) | Store it and its `status`, and grant by `status` (rule 3). A checkout sends it already `active`, and no `customer.subscription.updated` follows at purchase: subscribe to this type |\n| `customer.subscription.updated` | Any public field changed: `status`, the period, the price, `cancel_at_period_end`, `scheduled_change`, `pending_update`, `default_payment_method`, `payment_hold`, `latest_invoice`, discount, metadata. One event per change, with `previous_attributes` | Overwrite your copy (rule 2) and grant or revoke by `status` |\n| `customer.subscription.deleted` | The subscription ended (`status: canceled`, `ended_at` set): cancel now, the end of a period after `cancel_at_period_end`, or the final action after failed retries | Revoke access |\n\n## Invoice events\n\n| Type | Fires when | Do |\n|---|---|---|\n| `invoice.paid` | An invoice was paid: the first payment, a renewal, a retry, a manual payment, a plan change charged now, or a zero total | Send your receipt. Re-check the subscription is `active` before extending access |\n| `invoice.payment_succeeded` | With `invoice.paid`, at the same `object_version`, when a payment paid it | Handle `invoice.paid` or this one, not both, or both idempotently |\n| `invoice.payment_failed` | A charge on the invoice was proven declined. Never for an unknown outcome or the processor's duplicate screen. `billing_reason` says which charge: `subscription_cycle` (a renewal or its retry), `subscription_update` (a plan change: the plan is unchanged and `invoice.voided` follows), `subscription_create` (a first payment: the subscription is `incomplete`). `attempt_count`, `next_payment_attempt` (null when no retry follows, always null for the last two) and `last_payment_error` (`code`, `decline_code`, `requires_new_payment_method`) say what next | By `billing_reason`: a renewal, ask for a new card; a plan change, say it did not go through; a first payment, ask for another card and pay `latest_invoice`. See [Failed renewals and retries](failed-renewals-and-retries.md) |\n| `invoice.upcoming` | 3 days before a renewal by default (the merchant's `upcoming_days`, 0 to 30; 0 turns it off), for an `active` subscription that is not ending at period end. Once per period. A subscription created inside the window gets none for its first period | Send your renewal reminder, with a link to your account page (which opens the portal). `data.object` has no `id` and no `object_version`: deduplicate by `event.id`. A plan change after it does not resend it, so say \"about\" or read `POST /v1/invoices/create_preview` |\n| `invoice.voided` | An open invoice was voided: an expiring incomplete subscription, a cancel now, a plan change that did not go through, or `POST /v1/invoices/{invoice_id}/void` | Nothing is owed on it. A voided renewal forgives that period |\n| `invoice.marked_uncollectible` | Retries are over and the final action ran, or an `unpaid` invoice's period ended | Always followed by `customer.subscription.deleted` |\n\n## Checkout, customer and card events\n\n| Type | Fires when | Do |\n|---|---|---|\n| `checkout.session.completed` | A session was paid (or a zero total confirmed). In subscription mode it names an `active` `subscription`, a paid `invoice`, the `customer` and the saved `payment_method` | Provision here, once per session id |\n| `checkout.session.expired` | A session ended unpaid. Never while a payment's outcome is unknown | Optional cleanup |\n| `customer.created`, `customer.updated`, `customer.deleted` | A customer was created, changed or deleted. `customer.deleted` never cancels anything: a customer with a live subscription cannot be deleted | Keep your copy in step |\n| `payment_method.attached` | A card was saved for a customer: by `POST /v1/payment_methods`, by checkout in subscription mode, or on the portal | Optional |\n| `payment_method.detached` | A saved card was deleted. Not sent when a card merely becomes unusable | If it was the subscription's default card, ask for a new one |\n\nEvery billing payment also sends the payment events (`payment.succeeded`, `payment.failed` and the rest) for its `pay_...` row. A billing handler can ignore them.\n\n## One renewal, in order\n\nA paid renewal sends `invoice.upcoming` (3 days before), then `customer.subscription.updated` when the renewal invoice is created (`latest_invoice` names it; the period has not moved yet), then at the capture `invoice.paid`, `invoice.payment_succeeded` and `customer.subscription.updated` (the new period). A declined renewal sends `invoice.payment_failed` and `customer.subscription.updated` (`status: past_due`); each failed retry another `invoice.payment_failed`. The last declined retry sends its `invoice.payment_failed` (`next_payment_attempt: null`) in the same change as `invoice.marked_uncollectible` and `customer.subscription.deleted` (final action `cancel`), so send your last-chance notice on the failure before it. A retry skipped by a per-card ceiling sends no event; a skipped last slot still sends the final three.\n\n## Customer emails\n\nZeroPoint sends no email to your customers. Send each one yourself, in your own name, from its event:\n\n| Email | Event | Notes |\n|---|---|---|\n| Renewal reminder | `invoice.upcoming` | 3 days before the renewal by default (`upcoming_days`). The renewal is charged at `period_start` (also `next_payment_attempt`); `period_end` is the end of the period it buys. Show the date in the merchant's billing `timezone` (`GET /v1/billing_settings`). Skip it if your copy of the subscription is no longer `active` or is set to cancel at period end |\n| Receipt | `invoice.paid` | `amount_paid`, `status_transitions.paid_at`, `billing_reason` |\n| Failed payment | `invoice.payment_failed` | Decide the wording by `billing_reason` (see Invoice events): a declined renewal, a declined first payment, or a plan change that did not go through |\n\nNever put a billing portal link in an email. A portal link works once and stops working 5 minutes after it is created, and whoever holds an unused one can open that customer's portal. Link to a route of your own instead, for example `https://example.com/billing/manage`: it signs the user in your usual way, creates a portal session with `POST /v1/billing_portal/sessions` and redirects to its `url` at once. The `zeropoint.node.subscriptions` snippet has both parts (`sendBillingEmails` and `createManageRoute` in `emails.mjs`).\n\n## See it in the sandbox\n\n`send_sample_event` (or `POST /v1/webhooks/{webhook_id}/test` with `event_type`) sends one sample of a type to an endpoint that subscribes to it. Real events come from the flows: [Sell a subscription in five calls](build-subscriptions.md) and [Test your billing with test clocks and failure injection](test-billing-with-test-clocks.md). `GET /v1/events` (MCP `list_events`) lists them with `types` filters.","updated":1795275945}