deriveBillingLifecycleEvents (billing/lifecycle-events.ts)

open-seo · src/server/billing/lifecycle-events.ts · typescript · MIT
payments

Derives billing lifecycle events and state from customer snapshots for email triggers and analytics.

// Source: https://github.com/every-app/open-seo | License: MIT | Copyright 2026 Ben Senescu
// Provided via justclaw.it.com; keep this notice with the code.
import { AUTUMN_PAID_PLAN_ID, AUTUMN_YC_PLAN_ID } from "@/shared/billing";
import type { BillingCustomerStatusSnapshot } from "./customer-status-model";

// Leaf module (no runtime imports) so the transition rules are unit-testable.

// Plans that charge money. A plan can grant `paid_plan` without a price
// (friends and family), and those customers are not thanked for subscribing.
const PRICED_PLAN_IDS: ReadonlySet<string> = new Set([
  AUTUMN_PAID_PLAN_ID,
  AUTUMN_YC_PLAN_ID,
]);

export type BillingLifecycleEvent = {
  name: "subscription_started" | "payment_failed" | "subscription_canceled";
  planId: string;
};

type LifecycleSn

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key