{"object":"doc","slug":"billing-webhooks","title":"Billing webhooks: Stripe-shaped events, and where they differ","summary":"Billing events (checkout, invoice, subscription, customer, payment method) are opt-in, Stripe-shaped, and carry both Stripe period layouts. How to subscribe, verify, catch up, and port a Stripe handler, with the event mapping table.","tags":["guide","webhooks","billing","events","stripe"],"body":"# Billing webhooks\n\nBilling events use the same signed envelope as payment events (`webhooks`). Inside it, `data.object` is a Stripe-shaped object: Stripe's field names, amounts in cents, times in unix seconds. A handler written for Stripe's `event.type` and `event.data.object` reads them with few changes. This guide lists those changes.\n\nEvery billing type below can be subscribed to now. A type arrives once the feature that produces it is available in your account; `whats-available` says what is available today. To see a payload before then, send a sample (section 6).\n\n## 1. Billing events are opt-in\n\nAn endpoint with an empty `event_types` receives payment events only, never a billing event, and gets no error saying so. To receive billing events, list the types or use `[\"*\"]`:\n\n```\nPOST /v1/webhooks\n{\"url\":\"https://api.acme.test/zeropoint/billing\",\"event_types\":[\"checkout.session.completed\",\"invoice.paid\",\"invoice.payment_failed\",\"customer.subscription.created\",\"customer.subscription.updated\",\"customer.subscription.deleted\"]}\n```\nRegister billing on its own endpoint, apart from payment events. In live mode billing deliveries already have their own pauses after repeated failures, but in test mode they share the endpoint's pauses with payment events, and a separate endpoint keeps the two handlers' outages apart in both.\n\n## 2. Verify the signature\n\nThe scheme is the one Stripe uses: HMAC-SHA256 hex over `\"{t}.\" + raw_body`, a `t=...,v1=...` header, a 5-minute tolerance and a `whsec_` secret. What to know in a ported handler:\n\n- Every delivery carries `ZeroPoint-Signature`. With `stripe_signature_header: true` on the endpoint (`POST /v1/webhooks` or `PATCH /v1/webhooks/{webhook_id}`), it also carries `Stripe-Signature` with the same value. Leave that off for a URL that still receives real Stripe deliveries.\n- The secret is the `whsec_` value returned once by `POST /v1/webhooks` (or `register_webhook`), not your Stripe endpoint secret.\n- `stripe.webhooks.constructEvent(rawBody, header, whsec)` verifies either header with that secret. It is part of ZeroPoint's acceptance run for `stripe` 23.1.0 and 17.7.0 (Node); other versions are untested. The receiver kit's verifier below works without Stripe's library.\n- During a secret rotation the header carries two `v1=` values for 24 hours; accept either.\n\nNode, with the receiver kit (`get_snippet` with `zeropoint.node.webhook-receiver`):\n\n```js\nimport { createVerifier } from './zeropoint/verify.mjs';\nconst verify = createVerifier({ secrets: [process.env.ZP_WEBHOOK_SECRET] });\n\napp.post('/webhooks/zeropoint', express.raw({ type: 'application/json' }), async (req, res) => {\n  if (!verify(req.get('zeropoint-signature'), req.body)) return res.sendStatus(401);\n  const event = JSON.parse(req.body);\n  if (await seenEvent(event.id)) return res.sendStatus(200);  // retries repeat events\n  await handleBillingEvent(event);                            // your Stripe switch, unchanged\n  res.sendStatus(200);\n});\n```\n\nPython:\n\n```python\nimport hashlib, hmac, json, time\n\ndef construct_event(payload: bytes, header: str, secret: str, tolerance: int = 300) -> dict:\n    parts = [p.split(\"=\", 1) for p in header.split(\",\") if \"=\" in p]\n    ts = next((v for k, v in parts if k == \"t\"), None)\n    if ts is None or not ts.isdigit() or abs(time.time() - int(ts)) > tolerance:\n        raise ValueError(\"bad signature\")\n    expected = hmac.new(secret.encode(), f\"{ts}.\".encode() + payload, hashlib.sha256).hexdigest()\n    if not any(k == \"v1\" and hmac.compare_digest(expected, v) for k, v in parts):\n        raise ValueError(\"bad signature\")\n    return json.loads(payload)\n```\nPass the raw request bytes, never a re-serialized object. Stripe's Python library returns an object that allows `event.data.object.status`; this returns a plain dict, so read `event[\"data\"][\"object\"][\"status\"]`. Then prove the receiver with `POST /v1/webhooks/{webhook_id}/verify`.\n\n## 3. Where ZeroPoint differs from Stripe\n\n**The period advances only when the renewal is paid.** Stripe moves `current_period_start` and `current_period_end` forward when the renewal invoice is created, before payment. ZeroPoint moves them only in the change that proves the renewal charge was captured. A declined renewal shows `past_due` with the period that has ended; the period jumps forward in the same `customer.subscription.updated` that returns the subscription to `active`. Gate access on `status`, not on `current_period_end`: code that gates on the period cuts access at the first declined renewal.\n\n**An unknown charge outcome never sends a failure event.** When the processor's answer to a charge is unknown (a timeout, an answer it cannot confirm), nothing is declined until the outcome is proven. While it is unknown, ZeroPoint sends no `invoice.payment_failed`, no status change, no `invoice.voided` or `invoice.marked_uncollectible`, no `customer.subscription.deleted` and no `checkout.session.expired`, and the customer keeps access. It sends one `customer.subscription.updated` with no status change and `payment_hold` set (`previous_attributes` is `{\"payment_hold\": null}`), and one more when the outcome is proven and the hold is cleared. A change of `payment_hold` alone means a charge is being confirmed: do nothing. Once proven, the usual events follow: `invoice.paid` if it was captured, `invoice.payment_failed` if it was declined.\n\n**A hard decline is never retried on that card.** A decline the card issuer will never approve (for example `lost_card`, `stolen_card`, `pickup_card`, `invalid_account`, `revocation_of_authorization`) blocks that card at the merchant. The scheduler never sends it again, a pay through `POST /v1/invoices/{id}/pay` or the portal answers 402 `payment_method_blocked` with nothing sent, and for a lost, stolen or closed card a new subscription or an upgrade on that card answers the same. The same card saved again is still blocked; another card is charged at the next retry. A lost, stolen or closed card is blocked for every subscription of the merchant; a revoked authorization blocks that subscription. The retry schedule keeps running, as on Stripe: `next_payment_attempt` stays set and `attempt_count` counts retry slots, not charges, while `last_payment_error.requires_new_payment_method` is `true` and `last_payment_error.decline_code` names the decline. The last declined retry sends the final `invoice.payment_failed` (`next_payment_attempt: null`) in the same change as the final action, so send your last-chance notice on the failure before it. Never show `lost_card`, `stolen_card` or `pickup_card` to the cardholder: say the card was declined and ask for another card. Block scopes, the per-card ceilings and what a skipped slot does: [Failed renewals and retries](failed-renewals-and-retries.md), the one place these rules are kept.\n\n**Live billing deliveries retry for about 3 days.** A failed billing delivery to a live endpoint is retried after 1, 5 and 15 minutes, then 1, 3, 6, 12, 24 and 24 hours: ten attempts, the last about 70 hours after the first, and dead by 72 hours, close to Stripe's 3 days. Test mode keeps the short schedule, as payment events do everywhere: 1, 5 and 15 minutes, then dead (`webhooks` section 5 has the exact rules and limits). When live billing deliveries die we email your account's contact email, once per endpoint per day at most. A dead delivery is not sent again on its own, and a missed `customer.subscription.deleted` leaves a canceled customer with paid features. The event list is the catch-up path: poll `GET /v1/events` on startup and every few minutes, through the same handler, deduplicated by event id, with `since` set to the newest `created` you have handled minus 300 and one `types` per billing type you handle:\n\n```\n/v1/events?since=1797381700&types=invoice.paid&types=invoice.payment_failed&types=customer.subscription.created&types=customer.subscription.updated&types=customer.subscription.deleted\n```\nPage to the end (pass `next_cursor` as `cursor` until `has_more` is false) and keep the 300-second overlap; `webhooks` section 5 explains why.\n\n**Ordering and `object_version`.** Delivery order is not guaranteed, here or at Stripe. Billing events carry `data.object_version`, which rises with each change to the object. Use it only to decide whether to replace your stored copy (replace when the event's version is greater than or equal to the stored one); never use it to skip a handler, because one change can send two events at one version, such as `invoice.paid` with `invoice.payment_succeeded`. `webhooks` section 5 has the full rule.\n\n**Smaller differences.**\n\n- A renewal invoice's top-level `period_start` and `period_end` are the period it bills for, the same as its line's `period`. Stripe's renewal invoice shows the period that just ended at the top level.\n- `payment_intent` on an invoice or checkout session holds a ZeroPoint payment id (`pay_...`), not a `pi_` id. `GET /v1/payments/{payment_id}` reads it.\n- `invoice.upcoming` has no `id` and no `object_version`, as at Stripe: deduplicate it by `event.id`.\n- `customer.deleted` never cancels anything: a customer with a live subscription cannot be deleted.\n- `envelope.merchant_id` names the merchant; there is no Connect `account` field, no `request` and no `pending_webhooks`.\n- `api_version` is `2026-09-05`. Do not compare it with a Stripe version.\n\n## 4. Both Stripe field layouts, always\n\nStripe API `2025-03-31.basil` moved some subscription and invoice fields. ZeroPoint sends both the older location and the basil location on every billing object, always equal, so code written for either Stripe version reads the field it expects:\n\n| Field | Older location | Basil location |\n|---|---|---|\n| Period start and end | `subscription.current_period_start`, `.current_period_end` | `subscription.items.data[].current_period_start`, `.current_period_end` |\n| Invoice to subscription | `invoice.subscription` | `invoice.parent.subscription_details.subscription` |\n| Subscription metadata on the invoice | `invoice.subscription_details.metadata` | `invoice.parent.subscription_details.metadata` |\n| Line proration flag | `invoice.lines.data[].proration` | `invoice.lines.data[].parent.subscription_item_details.proration` |\n| Line's subscription item | `invoice.lines.data[].subscription_item` | `invoice.lines.data[].parent.subscription_item_details.subscription_item` |\n| Line price | `invoice.lines.data[].price` | `invoice.lines.data[].pricing.price_details.price` |\n\nWhen a period changes, `previous_attributes` on `customer.subscription.updated` carries both layouts too: `current_period_start`, `current_period_end` and `items`. To read either layout in one line:\n\n```js\nconst periodEnd = sub.items.data[0].current_period_end ?? sub.current_period_end;\nconst subId = inv.parent?.subscription_details?.subscription ?? inv.subscription;\n```\n\n## 5. Stripe event to ZeroPoint event\n\n| Stripe event | ZeroPoint event | What a handler can notice |\n|---|---|---|\n| `checkout.session.completed` | same | `payment` and `payment_intent` hold a `pay_` id. `url` is null in the event. |\n| `checkout.session.expired` | same | Not sent while a payment attempt's outcome is unknown. |\n| `checkout.session.async_payment_succeeded`, `_failed` | none | Cards are synchronous. |\n| `invoice.paid` | same | Also sent for a zero-total first invoice and an operator ruling, then without `invoice.payment_succeeded`. |\n| `invoice.payment_succeeded` | same | Sent with `invoice.paid`, at the same `object_version`. |\n| `invoice.payment_failed` | same | Never on an unknown outcome. Read `billing_reason`: `subscription_cycle` is a renewal; `subscription_update` a plan change that did not go through (the plan is unchanged, `invoice.voided` follows); `subscription_create` a declined first payment (`incomplete`). The last two carry `next_payment_attempt: null` while the subscription has not ended. `attempt_count` counts retry slots (a skipped slot counts). Retries follow the merchant's schedule, not Smart Retries. |\n| `invoice.voided`, `invoice.marked_uncollectible` | same | `invoice.marked_uncollectible` is always followed by `customer.subscription.deleted`. |\n| `invoice.upcoming` | same | No `id`. Sent 3 days before renewal by default; the merchant can change it. |\n| `invoice.created`, `invoice.finalized`, `invoice.updated` | none | Invoice changes arrive as the specific events above. |\n| `invoice.payment_action_required` | none | No 3D Secure flow. |\n| `customer.subscription.created`, `.updated`, `.deleted` | same | Both period layouts. The period advances only on a paid renewal. A hold is an `.updated` with `payment_hold` and no status change. No `trialing` or `paused` status. |\n| `customer.subscription.trial_will_end`, `.paused`, `.resumed`, `pending_update_applied`, `pending_update_expired` | none | A pending or scheduled change shows in `.updated`. |\n| `payment_method.attached`, `.detached` | same | `detached` is sent only when the saved card is deleted. Wallet payments are never attached. |\n| `payment_method.automatically_updated` | none | No card updater. |\n| `customer.created`, `.updated`, `.deleted` | same | `customer.deleted` never cancels a subscription. |\n| `payment_intent.*`, `charge.*` | `payment.*`, `refund.*` | Different names and shapes; these are the payment events. |\n| `Stripe-Signature` header | `ZeroPoint-Signature`, plus `Stripe-Signature` with `stripe_signature_header: true` | Same scheme and value; `stripe.webhooks.constructEvent` verifies either (section 2). |\n| Retries for up to 3 days | Retries for about 3 days in live mode, about 21 minutes in test mode | Poll `GET /v1/events` with `types` to catch up (section 3). |\n\n## 6. Try it in the sandbox\n\n`POST /v1/webhooks/{webhook_id}/test` with `{\"event_type\":\"invoice.paid\",\"merchant_id\":\"mch_...\"}` (or the `send_sample_event` tool) sends one sample of a billing type to that endpoint, test mode only. The endpoint must subscribe to the type. The sample is the documented payload with `\"sample\": true` beside `data.object` and ids that answer 404. Use it to build your parser; act on real events only, and skip any event whose `data.sample` is true.","updated":1795275945}