subscriptions.stripe-state
Folds Stripe's subscription and invoice webhook events into one normalised subscription state, in any order.
1.0.0 · published 2026-10-10 by charlie · Anterra
Pinned by 33 tests, run in TypeScript, Python and Rust.
What it does
Keep one row per subscription in your database, up to date from Stripe's webhooks, without trusting the order they arrive in. Verify each webhook (the event is `{ id, type, created, object }`, exactly what `payments.stripe-checkout`'s `verifyWebhook` returns, so pass that straight in; `object` is the event's `data.object`), load the stored state for its subscription (or null), fold the event in, and store what comes back:
import { verifyWebhook } from "#fune/payments.stripe-checkout@^1";
import { applyStripeEvent } from "#fune/subscriptions.stripe-state@^1";
const event = verifyWebhook(await req.text(), req.headers.get("stripe-signature") ?? "");
const subId = subscriptionIdOf(event); // yours: object.id, or the invoice's subscription
const next = applyStripeEvent(await db.load(subId), event);
if (next) await db.save(next); // unchanged state saves the same row
For example
applyStripeEvent(—, id evt_1, type customer.subscription.created, created 1,772,323,200, object …)→ subscription id sub_1Pz, customer id cus_9, status trialing, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period… customer.subscription.created starts the state from the snapshotapplyStripeEvent(—, id evt_1, type customer.subscription.created, created 1,772,323,200, object …)→ subscription id sub_1Pz, customer id cus_9, status active, price id price_team, quantity 3, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period … expanded customer and latest_invoice objects give their idsapplyStripeEvent(—, id evt_1, type customer.subscription.updated, created 1,772,323,200, object …)→ subscription id sub_1Pz, customer id cus_9, status active, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period e… newer API versions: the period is read from the subscription item
The function
The same function in TypeScript, Python and Rust, pinned by the same tests. Pick your language; the choice follows you around the registry.
export function applyStripeEvent(state: SubscriptionState | null, event: unknown): SubscriptionState | null
| state | SubscriptionState? | what the last event left, as stored; null before the first event for this subscription |
| event | json | a verified webhook event: id, type, created (Unix seconds) and object (its data.object), as payments.stripe-checkout's verifyWebhook returns it |
| returns | SubscriptionState? | the new state to store; the same state when the event changes nothing; null while nothing is known |
The types it declares, generated into your project
export type StripeSubscriptionStatus = "incomplete" | "incomplete_expired" | "trialing" | "active" | "past_due" | "canceled" | "unpaid" | "paused";
/** One subscription as your app stores it, kept from the webhooks. */
export interface SubscriptionState {
/** sub_... */
readonly subscriptionId: string;
/** cus_... */
readonly customerId: string;
/** Stripe's status, moved on by invoice events between snapshots */
readonly status: StripeSubscriptionStatus;
/** the first item's price, price_...; null until a subscription event says */
readonly priceId: string | null;
/** the first item's quantity */
readonly quantity: number;
/** Unix seconds */
readonly currentPeriodStart: number | null;
/** Unix seconds; access runs to here when cancelAtPeriodEnd */
readonly currentPeriodEnd: number | null;
/** the customer cancelled and it ends at currentPeriodEnd */
readonly cancelAtPeriodEnd: boolean;
/** a scheduled cancellation time */
readonly cancelAt: number | null;
/** when it was cancelled */
readonly canceledAt: number | null;
/** when it ended */
readonly endedAt: number | null;
/** when the trial ends or ended */
readonly trialEnd: number | null;
/** in_... */
readonly latestInvoiceId: string | null;
/** the latest invoice event was a failed payment */
readonly paymentFailed: boolean;
/** whether to give access: active, trialing or past_due (a grace period while Stripe retries) */
readonly entitled: boolean;
/** created of the last subscription snapshot applied; 0 for none */
readonly subscriptionEventAt: number;
/** created of the last invoice event applied; 0 for none */
readonly invoiceEventAt: number;
/** the last event applied, so a redelivery changes nothing */
readonly lastEventId: string;
}
Your code names it in one line, in the file that uses it
import { applyStripeEvent } from "#fune/subscriptions.stripe-state@^1";
import type { StripeSubscriptionStatus, SubscriptionState } from "./subscriptions_stripe_state_types.ts";
const STATUSES: readonly string[] = ["incomplete", "incomplete_expired", "trialing", "active", "past_due", "canceled", "unpaid", "paused"];
const SUBSCRIPTION_EVENTS: readonly string[] = [
"customer.subscription.created",
"customer.subscription.updated",
"customer.subscription.deleted",
"customer.subscription.paused",
"customer.subscription.resumed",
"customer.subscription.trial_will_end",
];
const PAID_EVENTS: readonly string[] = ["invoice.paid", "invoice.payment_succeeded"];
const FAILED_EVENT = "invoice.payment_failed";
type Obj = Readonly<Record<string, unknown>>;
function isObj(v: unknown): v is Obj {
return typeof v === "object" && v !== null && !Array.isArray(v);
}
function field(o: unknown, key: string): unknown {
return isObj(o) ? o[key] : undefined;
}
// An id Stripe sends either as a string or, when expanded, as an object with one.
function idOf(v: unknown): string | null {
if (typeof v === "string" && v !== "") return v;
const id = field(v, "id");
return typeof id === "string" && id !== "" ? id : null;
}
function optInt(o: Obj, key: string): number | null {
const v = o[key];
if (v === undefined || v === null) return null;
if (typeof v !== "number" || !Number.isInteger(v)) throw new Error(`subscription field ${key} must be a whole number or null`);
return v;
}
function entitledFor(status: string): boolean {
return status === "active" || status === "trialing" || status === "past_due";
}
// Where an invoice event happened after this snapshot was taken, the snapshot
// does not know about the payment yet: keep the invoice's effect on top of it.
function withInvoiceEffect(status: string, paymentFailed: boolean): string {
if (!paymentFailed && (status === "incomplete" || status === "past_due" || status === "unpaid")) return "active";
if (paymentFailed && status === "active") return "past_due";
return status;
}
function invoiceSubscription(invoice: Obj): string | null {
const direct = idOf(invoice.subscription);
if (direct !== null) return direct;
// API versions from 2025 move it under parent.subscription_details.
return idOf(field(field(invoice.parent, "subscription_details"), "subscription"));
}
/**
* Folds one verified Stripe webhook event into the stored state of one
* subscription. Stripe does not promise delivery order or delivery once, so
* subscription snapshots and invoice events each keep their own clock and an
* older one is ignored, a redelivered event changes nothing, and a cancelled
* subscription stays cancelled.
*/
export function applyStripeEvent(state: SubscriptionState | null, event: unknown): SubscriptionState | null {
if (!isObj(event)) throw new Error("event must be a JSON object");
if (typeof event.id !== "string" || event.id === "") throw new Error("event id must be a non-empty string");
if (typeof event.type !== "string" || event.type === "") throw new Error("event type must be a non-empty string");
if (typeof event.created !== "number" || !Number.isInteger(event.created) || event.created < 0) {
throw new Error("event created must be a whole number of seconds");
}
if (!isObj(event.object)) throw new Error("event object must be a JSON object");
if (state !== null && event.id === state.lastEventId) return state;
const obj = event.object;
if (SUBSCRIPTION_EVENTS.includes(event.type)) {
const id = idOf(obj.id);
const customer = idOf(obj.customer);
const rawStatus = obj.status;
if (id === null || customer === null || typeof rawStatus !== "string") {
throw new Error("subscription object needs id, customer and status");
}
if (!STATUSES.includes(rawStatus)) throw new Error(`unknown subscription status "${rawStatus}"`);
if (state !== null && id !== state.subscriptionId) throw new Error(`event is for subscription ${id}, not ${state.subscriptionId}`);
const snapshotStatus = event.type === "customer.subscription.deleted" ? "canceled" : rawStatus;
// Cancelled is final in Stripe: a late snapshot never revives it, though a
// later cancelled one (the deletion after the update) may fill in endedAt.
if (state !== null && state.status === "canceled" && snapshotStatus !== "canceled") return state;
if (state !== null && event.created < state.subscriptionEventAt) return state;
const items = field(obj.items, "data");
const item: Obj = Array.isArray(items) && isObj(items[0]) ? items[0] : {};
const quantity = optInt(item, "quantity") ?? 1;
const periodStart = optInt(obj, "current_period_start") ?? optInt(item, "current_period_start");
const periodEnd = optInt(obj, "current_period_end") ?? optInt(item, "current_period_end");
const cape = obj.cancel_at_period_end;
if (cape !== undefined && cape !== null && typeof cape !== "boolean") throw new Error("subscription field cancel_at_period_end must be true or false");
const paymentFailed = state?.paymentFailed ?? false;
const invoiceEventAt = state?.invoiceEventAt ?? 0;
let status: string = snapshotStatus;
if (invoiceEventAt > event.created) status = withInvoiceEffect(status, paymentFailed);
return {
subscriptionId: id,
customerId: customer,
status: status as StripeSubscriptionStatus,
priceId: idOf(field(item, "price")),
quantity,
currentPeriodStart: periodStart,
currentPeriodEnd: periodEnd,
cancelAtPeriodEnd: cape === true,
cancelAt: optInt(obj, "cancel_at"),
canceledAt: optInt(obj, "canceled_at"),
endedAt: optInt(obj, "ended_at"),
trialEnd: optInt(obj, "trial_end"),
latestInvoiceId: idOf(obj.latest_invoice) ?? state?.latestInvoiceId ?? null,
paymentFailed,
entitled: entitledFor(status),
subscriptionEventAt: event.created,
invoiceEventAt,
lastEventId: event.id,
};
}
const paid = PAID_EVENTS.includes(event.type);
if (paid || event.type === FAILED_EVENT) {
const sub = invoiceSubscription(obj);
if (sub === null) return state;
const invoiceId = idOf(obj.id);
if (state === null) {
const customer = idOf(obj.customer);
if (customer === null) throw new Error("invoice object needs customer");
const status = paid ? "active" : "incomplete";
return {
subscriptionId: sub,
customerId: customer,
status,
priceId: null,
quantity: 1,
currentPeriodStart: null,
currentPeriodEnd: null,
cancelAtPeriodEnd: false,
cancelAt: null,
canceledAt: null,
endedAt: null,
trialEnd: null,
latestInvoiceId: invoiceId,
paymentFailed: !paid,
entitled: entitledFor(status),
subscriptionEventAt: 0,
invoiceEventAt: event.created,
lastEventId: event.id,
};
}
if (sub !== state.subscriptionId) throw new Error(`event is for subscription ${sub}, not ${state.subscriptionId}`);
if (event.created < state.invoiceEventAt) return state;
const status = withInvoiceEffect(state.status, !paid);
return {
...state,
status: status as StripeSubscriptionStatus,
latestInvoiceId: invoiceId ?? state.latestInvoiceId,
paymentFailed: !paid,
entitled: entitledFor(status),
invoiceEventAt: event.created,
lastEventId: event.id,
};
}
return state;
}Install
fune build
With that line in your source, in a TypeScript project (language typescript in fune.project), fune build resolves it and nothing else, pins them in fune.lock, downloads only the TypeScript package of each, and builds the code above into your project’s .fune/build, one readable file per capability with a header linking back here. Or pin a range in fune.project and build in one step:
fune add subscriptions.stripe-state
The manifest, vectors and README with only the TypeScript implementation. Install it without the registry with fune add ./subscriptions.stripe-state-1.0.0-typescript.fune, or fetch it from a terminal with fune pull subscriptions.stripe-state@1.0.0:typescript.
The whole function, every language, is one file too: subscriptions.stripe-state-1.0.0.fune, 79,658 bytes, sha256 bbaf14bffdc2c8c8e9aabb126b79bd59b5bc42d690449941bcc1bd7711ab72bf. It installs into a project of any language.
Customise it in your app
The seams this capability offers. Put a marker directly above a function of your own and fune build wires it into the built code; the package on the registry is not changed, the built file’s header lists it under CUSTOMISED, and fune hooks lists every hook in the project. How hooks work.
before — your function gets the arguments and returns them, changed or not, or throws to refuse the call.
// fune: before subscriptions.stripe-state
after — your function gets the result and the arguments, and returns the final result.
// fune: after subscriptions.stripe-state
replace — it requires no other capability, so there is no dependency to replace.
step — your function runs at a numbered point inside the function’s body, receives the in-scope values it names as parameters, and may return replacements. List the points with fune show subscriptions.stripe-state --steps.
// fune: step subscriptions.stripe-state after <n|label>
Tests
A version published now needs at least 8 tests for every function, and one that expects the error for each function that throws; the registry refuses it otherwise. fune verify --all runs each case in TypeScript, Python and Rust, and a project runs them again with fune verify. This page lists the cases; it does not run them. The exact JSON is vectors.json.
| Case | Arguments | Expected | |
|---|---|---|---|
| customer.subscription.created starts the state from the snapshot | —, id evt_1, type customer.subscription.created, created 1,772,323,200, object … | → | subscription id sub_1Pz, customer id cus_9, status trialing, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period… |
| expanded customer and latest_invoice objects give their ids | —, id evt_1, type customer.subscription.created, created 1,772,323,200, object … | → | subscription id sub_1Pz, customer id cus_9, status active, price id price_team, quantity 3, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period … |
| newer API versions: the period is read from the subscription item | —, id evt_1, type customer.subscription.updated, created 1,772,323,200, object … | → | subscription id sub_1Pz, customer id cus_9, status active, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period e… |
| the customer cancels at the period end: still entitled until then | subscription id sub_1Pz, customer id cus_9, status active, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period e… | → | subscription id sub_1Pz, customer id cus_9, status active, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period e… |
| customer.subscription.deleted is cancelled and not entitled, whatever status it carries | subscription id sub_1Pz, customer id cus_9, status active, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period e… | → | subscription id sub_1Pz, customer id cus_9, status canceled, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period… |
| cancelled is final: a later snapshot saying active does not revive it | subscription id sub_1Pz, customer id cus_9, status canceled, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period… | → | subscription id sub_1Pz, customer id cus_9, status canceled, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period… |
| a snapshot older than the one applied is ignored | subscription id sub_1Pz, customer id cus_9, status active, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period e… | → | subscription id sub_1Pz, customer id cus_9, status active, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period e… |
| a redelivered event changes nothing | subscription id sub_1Pz, customer id cus_9, status active, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period e… | → | subscription id sub_1Pz, customer id cus_9, status active, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period e… |
| invoice.payment_failed moves active to past_due, still entitled while Stripe retries | subscription id sub_1Pz, customer id cus_9, status active, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period e… | → | subscription id sub_1Pz, customer id cus_9, status past_due, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period… |
| a failed payment during a trial leaves it trialing | subscription id sub_1Pz, customer id cus_9, status trialing, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period… | → | subscription id sub_1Pz, customer id cus_9, status trialing, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period… |
Show the other 23 tests
| Case | Arguments | Expected | |
|---|---|---|---|
| invoice.paid after a failure moves past_due back to active | subscription id sub_1Pz, customer id cus_9, status past_due, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period… | → | subscription id sub_1Pz, customer id cus_9, status active, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period e… |
| newer API versions: invoice.payment_succeeded finds the subscription under parent, and unpaid becomes active | subscription id sub_1Pz, customer id cus_9, status unpaid, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period e… | → | subscription id sub_1Pz, customer id cus_9, status active, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period e… |
| an invoice event older than the last one applied is ignored | subscription id sub_1Pz, customer id cus_9, status past_due, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period… | → | subscription id sub_1Pz, customer id cus_9, status past_due, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period… |
| invoice.paid before any subscription event starts an active state | —, id evt_1, type invoice.paid, created 1,772,323,260, object … | → | subscription id sub_1Pz, customer id cus_9, status active, price id —, quantity 1, current period start —, current period end —, cancel at period end false, cancel at —, canceled … |
| the subscription.created that arrives after its paid invoice fills the plan in and stays active | subscription id sub_1Pz, customer id cus_9, status active, price id —, quantity 1, current period start —, current period end —, cancel at period end false, cancel at —, canceled … | → | subscription id sub_1Pz, customer id cus_9, status active, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period e… |
| invoice.payment_failed before any subscription event starts an incomplete state, not entitled | —, id evt_1, type invoice.payment_failed, created 1,772,323,260, object … | → | subscription id sub_1Pz, customer id cus_9, status incomplete, price id —, quantity 1, current period start —, current period end —, cancel at period end false, cancel at —, cance… |
| a one-off invoice with no subscription changes nothing | subscription id sub_1Pz, customer id cus_9, status active, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period e… | → | subscription id sub_1Pz, customer id cus_9, status active, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period e… |
| an event this reducer does not read leaves no state as no state | —, id evt_9, type checkout.session.completed, created 1,772,700,000, object … | → | — |
| customer.updated leaves the state unchanged | subscription id sub_1Pz, customer id cus_9, status active, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period e… | → | subscription id sub_1Pz, customer id cus_9, status active, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period e… |
| customer.subscription.paused: paused is not entitled | subscription id sub_1Pz, customer id cus_9, status active, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period e… | → | subscription id sub_1Pz, customer id cus_9, status paused, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period e… |
| a snapshot at the same second as the last one applies | subscription id sub_1Pz, customer id cus_9, status active, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period e… | → | subscription id sub_1Pz, customer id cus_9, status active, price id price_pro, quantity 5, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period e… |
| trial_will_end with no items: no price, quantity 1 | —, id evt_1, type customer.subscription.trial_will_end, created 1,773,273,600, object … | → | subscription id sub_1Pz, customer id cus_9, status trialing, price id —, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period end fal… |
| an event for another subscription is an error | subscription id sub_1Pz, customer id cus_9, status active, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period e… | → | error: event is for subscription sub_other, not sub_1Pz |
| an invoice for another subscription is an error | subscription id sub_1Pz, customer id cus_9, status active, price id price_pro, quantity 1, current period start 1,772,323,200, current period end 1,775,001,600, cancel at period e… | → | error: event is for subscription sub_other, not sub_1Pz |
| an unknown status is an error | —, id evt_1, type customer.subscription.updated, created 1,772,800,000, object … | → | error: unknown subscription status "expired" |
| a subscription without its customer is an error | —, id evt_1, type customer.subscription.created, created 1,772,800,000, object … | → | error: subscription object needs id, customer and status |
| an empty event id is an error | —, id , type invoice.paid, created 1,772,800,000, object … | → | error: event id must be a non-empty string |
| a fractional created time is an error | —, id evt_1, type invoice.paid, created 1,772,800,000.5, object … | → | error: event created must be a whole number of seconds |
| an object that is not a JSON object is an error | —, id evt_1, type invoice.paid, created 1,772,800,000, object in_2 | → | error: event object must be a JSON object |
| a period end that is text is an error | —, id evt_1, type customer.subscription.created, created 1,772,800,000, object … | → | error: subscription field current_period_end must be a whole number or null |
| a first invoice without its customer is an error | —, id evt_1, type invoice.paid, created 1,772,800,000, object … | → | error: invoice object needs customer |
| an event that is not an object is an error | —, evt_1 | → | error: event must be a JSON object |
| an event without a type is an error | —, id evt_1, created 1,772,800,000, object … | → | error: event type must be a non-empty string |
Verification
Verified by the operator, not the sandbox 33 test vectors declared; none run by the registry.
Verified locally by the registry's operator, not by the sandbox. This version was published with FUNE_VERIFY_MODE=inline-dev (the operator's import of the first-party registry, or a development server): the server validated the package - its manifest, signatures, imports, safety lint and test rules - but the registry did not run its test vectors in its sandbox. The operator runs them with `fune verify --all` before importing.
Signed by the registry with key fw-9dc887227da47575 (ed25519), over its integrity and this report's digest. The full report · JSON
More from the author
What it reads:
- `customer.subscription.created`, `.updated`, `.deleted`, `.paused`, `.resumed` and `.trial_will_end` carry the whole subscription: a snapshot. The status, the first item's price and quantity, the current period (top level on older API versions, on the item since 2025), the cancellation fields, trial end and latest invoice are taken from it. `.deleted` is always `canceled`. - `invoice.paid` and `invoice.payment_succeeded` clear `paymentFailed` and move `past_due`, `unpaid` or `incomplete` to `active`; `invoice.payment_failed` sets `paymentFailed` and moves `active` to `past_due` (a trial stays `trialing`). The subscription is `object.subscription`, or `object.parent.subscription_details.subscription` on newer API versions, as a string or an expanded object. An invoice without a subscription (a one-off) is ignored. - Every other event type returns the state unchanged (and null stays null).
Ordering. Stripe neither promises order nor delivers exactly once, so:
- snapshots and invoice events each keep their own clock (`subscriptionEventAt`, `invoiceEventAt`, the events' `created`): an older one than the last applied is ignored, one at the same second applies; - the same event id as `lastEventId` changes nothing; - when a snapshot is older than the last invoice event (a paid invoice arriving before `customer.subscription.created`), the invoice's effect is kept on top of the snapshot's status, so the paid subscription does not fall back to `incomplete`; - an invoice event with no state yet starts one (`active` when paid, `incomplete` when failed), with no price and `subscriptionEventAt` 0, so the first snapshot to arrive still fills it in; - `canceled` is final, as in Stripe: a later snapshot with another status does not revive it (a later cancelled one may still fill in `endedAt`).
`entitled` is the access decision: true for `active`, `trialing` and `past_due`. Counting `past_due` is a deliberate grace period while Stripe retries the card (see `subscriptions.dunning-schedule`); an app that wants to cut access at the first failure checks `status == "active" || "trialing"` itself. A customer who cancels at the period end stays `active` with `cancelAtPeriodEnd` true until Stripe sends the deletion.
Errors: a malformed event (not an object, no id or type, `created` not a whole number, `object` not an object, a subscription without id, customer or status, an unknown status, a non-integer time field) and an event for a different subscription than the state's (`event is for subscription sub_x, not sub_y`) throw: look the state up by the event's subscription id.
Out of scope: several items per subscription (only the first item's price and quantity are kept), schedules, and checkout sessions (store the customer id from `checkout.session.completed` yourself).
Files
| Path | Bytes |
|---|---|
| README.md | 3,809 |
| impl/python.py | 8,117 |
| impl/rust.rs | 11,760 |
| impl/typescript.ts | 7,430 |
| vectors.json | 37,114 |