Hub 2.0 step 4: billing per customer

- One invoice per customer per period for all its products; the schedule
  moves from Licence to Customer (migration copies it, so billing carries
  on unchanged); licences get billedFrom / billedUntil
- Website (R99, 5 GB) and App (on active members) prices next to the
  Events tiers; founding prices per product, then bundles (15% two, 25%
  three); extra website storage R20 per 5 GB, never discounted
- A product added to a billed customer starts after its free month; days
  before its first full period are prorated, never charged twice
- Annual review per product (Events income, App members), one notice of
  licence change per product; invoices, PDFs and emails name products
- Customer page: schedule, per-product billing, next-invoice preview
- Invoices from before 2.0 kept as they were (still recalculable)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-04 16:18:23 +02:00
co-authored by Claude Opus 5.5
parent 937c1fa38e
commit 7478e84e9d
21 changed files with 1081 additions and 316 deletions
+8 -3
View File
@@ -1,4 +1,5 @@
import React from "react";
import type { Product } from "./products";
// Billing (1.7.0): the shapes the billing API returns, and how they're shown.
@@ -6,7 +7,8 @@ export type InvoiceStatus = "draft" | "approved" | "sent" | "void";
export type InvoiceState = InvoiceStatus | "unpaid" | "part_paid" | "overdue" | "paid";
export type BillingCycle = "none" | "monthly" | "yearly";
export type Line = { description: string; quantity: number; unitCents: number; amountCents: number };
export type PlanChange = { from: string; to: string; fromMonthlyCents: number | null; toMonthlyCents: number | null; band?: string | null };
/** A tier change at the annual review (Hub 2.0: one per product). */
export type PlanChange = { licenceId?: string | null; product?: Product; from: string; to: string; fromMonthlyCents: number | null; toMonthlyCents: number | null; band?: string | null };
export type BillingTier = { name: string; upTo: number | null; monthly: number | null; founding: number | null };
export type Payment = {
@@ -18,13 +20,16 @@ export type Payment = {
export type Invoice = {
id: string; number: string; customerId: string; licenceId: string | null; status: InvoiceStatus; state: InvoiceState;
issueDate: string; dueDate: string; periodStart: string | null; periodEnd: string | null; cycle: BillingCycle;
plan: string | null; incomeBand: string | null; reviewed: boolean; founding: boolean; planChange: PlanChange | null;
plan: string | null; incomeBand: string | null; reviewed: boolean; founding: boolean;
/** The tier changes on this invoice (the API reads Hub 1.7's single change as a list of one). */
planChanges: PlanChange[];
lines: Line[]; totalCents: number; vatCents: number; paidCents: number; balanceCents: number;
notes: string | null; warnings: string[]; recipientEmail: string | null;
approvedAt: string | null; approvalEmailedAt: string | null; sentAt: string | null; sendError: string | null; voidedAt: string | null; voidReason: string | null;
createdAt: string; payments: Payment[];
customer?: { id: string; name: string; founding: boolean };
licence?: { id: string; key: string; plan: string; billingCycle: BillingCycle; installUrl: string | null } | null;
/** Before Hub 2.0 an invoice was for one licence; from 2.0 it's for the customer (null). */
licence?: { id: string; key: string; product: Product; plan: string; installUrl: string | null } | null;
};
export type LicenceChange = {