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:
@@ -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 = {
|
||||
|
||||
@@ -19,6 +19,37 @@ export const TIERS: Tier[] = [
|
||||
/** Licence plans offered on a licence: the tiers, plus a trial. */
|
||||
export const PLANS = ["Trial", ...TIERS.map(t => t.name)];
|
||||
|
||||
// Hub 2.0: the other products' prices (ROADMAP-v3 §10), the same as backend/src/utils/billing/tiers.js.
|
||||
|
||||
/** Church Website: one price, 5 GB of uploads included. */
|
||||
export const WEBSITE_PLAN = { name: "Website", monthly: 99, founding: 64 };
|
||||
|
||||
export type AppTier = { name: string; band: string; monthly: number | null; founding: number | null };
|
||||
|
||||
/** Church App tiers, on active members in the last 90 days. */
|
||||
export const APP_TIERS: AppTier[] = [
|
||||
{ name: "Mustard Seed", band: "0–100", monthly: 99, founding: 64 },
|
||||
{ name: "Small Group", band: "101–300", monthly: 249, founding: 162 },
|
||||
{ name: "Congregation", band: "301–750", monthly: 399, founding: 259 },
|
||||
{ name: "Gathering", band: "751–2 000", monthly: 649, founding: 422 },
|
||||
{ name: "Multitude", band: "2 001–5 000", monthly: 999, founding: 649 },
|
||||
{ name: "Network", band: "over 5 000", monthly: null, founding: null },
|
||||
];
|
||||
|
||||
/** Plans offered on a licence, per product (Accounts has none: it's free). */
|
||||
export const PLANS_BY_PRODUCT = {
|
||||
events: PLANS,
|
||||
website: [WEBSITE_PLAN.name],
|
||||
app: ["Trial", ...APP_TIERS.map(t => t.name)],
|
||||
accounts: [] as string[],
|
||||
};
|
||||
|
||||
/** Extra website storage: R20 a month per 5 GB above the 5 GB included. Never discounted. */
|
||||
export const STORAGE_ADDON = { includedGb: 5, stepGb: 5, monthly: 20 };
|
||||
|
||||
/** Bundles: % off the products (not add-ons) by how many are billed. */
|
||||
export const BUNDLE_PERCENT: Record<number, number> = { 2: 15, 3: 25 };
|
||||
|
||||
/** The highest rand amount in a band label ("R100 001–R150 000" → 150000; "over R10 000 000" → Infinity). */
|
||||
function bandTop(band: string): number | null {
|
||||
if (/^over /i.test(band)) return Infinity;
|
||||
|
||||
Reference in New Issue
Block a user