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
+22
View File
@@ -110,6 +110,28 @@ describe('licences', () => {
await expect(checkReopen(mockDb, old, 'revoked')).resolves.toBeUndefined();
});
test('a product added to a customer that is billed already starts after its free month', async () => {
mockDb.customer = { findUnique: jest.fn(async () => ({ id: 'c1', billingCycle: 'monthly' })) };
try {
const { licence, accounts } = await generateLicence(mockDb, { customerId: 'c1', product: 'app', data: {}, now: new Date('2026-11-04T10:00:00Z') });
expect(licence.billedFrom.toISOString().slice(0, 10)).toBe('2026-12-04');
// Accounts is free: never charged.
expect(accounts.billedFrom).toBeUndefined();
} finally {
delete mockDb.customer;
}
});
test('a customer not billed yet: the product waits until billing is set up', async () => {
mockDb.customer = { findUnique: jest.fn(async () => ({ id: 'c1', billingCycle: 'none' })) };
try {
const { licence } = await generateLicence(mockDb, { customerId: 'c1', product: 'events', data: {} });
expect(licence.billedFrom).toBeUndefined();
} finally {
delete mockDb.customer;
}
});
test('unknown products are refused', async () => {
await expect(createLicence(mockDb, { customerId: 'c1', product: 'shop' })).rejects.toMatchObject({ status: 400 });
});