CluPilotCloud/tests/Feature/Billing
nexxo 8f1630ba91 Bill a booked module every month, and put it on the invoice
A module was never an item on the Stripe subscription, so it was charged in
the month it was booked and never again. And the renewal document was written
from our own contract snapshot, so it would not have said so even if the money
had been taken. Two halves of one fault, closed together.

Modules are items now. stripe:sync-catalogue mirrors a Product and a Price per
module on both terms — a Stripe Price carries its own interval, and a booking
frozen at an older figure needs its own Price, so they are keyed by module,
amount, currency and interval in stripe_addon_prices. Booking adds an item with
always_invoice: prorated by days AND charged there and then, which is the
invoice the owner wants for a module booked mid-term. A second storage pack is
a quantity on one item, not a second item. Cancelling takes the item off with
no proration — no credit, and the next cycle is simply smaller — while the
module itself is kept until the period end on subscription_addons.cancels_at
and ended by clupilot:end-cancelled-addons.

Documents are built from Stripe's own invoice lines. Stripe is what charged the
customer; a document assembled from our figures would state a sum that is not
the one taken. So every paid Stripe invoice gets one document with one number,
idempotent on stripe_invoice_id — a cycle carrying package and every module
together, a mid-period booking carrying just its prorated line, an upgrade
carrying its proration. Only the wording is ours: each line is named from the
catalogue rather than printed as a Price id, and a line nobody can name stays on
the document under Stripe's own description and is logged. The checkout's own
invoice is still the one exception; that purchase already has a document.

Stripe being away never undoes a booking that has already reached the machine.
The failure is parked on the contract in stripe_addon_sync and swept by the
same clupilot:sync-stripe-subscriptions that retries a plan change, which finds
its work from the bookings themselves rather than from the marker. A granted
contract has no Stripe subscription and is not touched at all.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-29 20:22:02 +02:00
..
AddonEntitlementTest.php Book a downgrade for a date that cannot move, and sell a module once 2026-07-29 17:51:37 +02:00
ApplyPlanChangeTest.php Book a downgrade for a date that cannot move, and sell a module once 2026-07-29 17:51:37 +02:00
ArchivePullAccessTest.php Mint the archive collection key from the console instead of by hand 2026-07-29 10:08:32 +02:00
CustomDomainAccessTest.php Decide who may have their own domain, and decide it in one place 2026-07-29 15:59:04 +02:00
ExportTargetFormTest.php Keep the SFTP credential on the row it belongs to, encrypted 2026-07-29 02:46:06 +02:00
FinanceSettingsTest.php Decide the VAT rate in one place, before the two disagree 2026-07-29 02:03:29 +02:00
GrantAddonTest.php Let a subscription or add-on be opened for free, with who and why on the row 2026-07-29 12:41:06 +02:00
GrantInvoiceTest.php Skip the invoice for a full gift, keep it out of revenue, hide its price 2026-07-29 12:41:32 +02:00
GrantSubscriptionTest.php Let a subscription or add-on be opened for free, with who and why on the row 2026-07-29 12:41:06 +02:00
InvoiceArchiveTest.php Leave the archive readable by whoever collects from it 2026-07-29 03:48:03 +02:00
InvoiceListTest.php List issued invoices in the console, with no way to change one 2026-07-29 02:21:15 +02:00
InvoiceMailTest.php Send the invoice with the invoice attached 2026-07-29 02:13:41 +02:00
InvoiceMathTest.php Print every line at full price and take the discount off once, in euros 2026-07-29 01:59:56 +02:00
InvoiceNumberTest.php Lay the foundation for self-issued invoices: series, numbers, frozen documents 2026-07-29 00:57:06 +02:00
IssueInvoiceTest.php Issue an invoice from what somebody bought, and freeze it there 2026-07-29 02:09:05 +02:00
PendingPlanChangeTest.php Book a downgrade for a date that cannot move, and sell a module once 2026-07-29 17:51:37 +02:00
PlanCatalogueTest.php Paketversionen: Verkauf wieder aufnehmen und saubere Übergabe 2026-07-29 14:58:11 +02:00
PlanChangeTest.php feat(billing): the plan catalogue becomes three tables, and config stops selling 2026-07-26 12:05:56 +02:00
ProofRegisterTest.php feat(billing): a proof register, and modules frozen at their booked price 2026-07-26 13:07:34 +02:00
RenewalInvoiceTest.php Bill a booked module every month, and put it on the invoice 2026-07-29 20:22:02 +02:00
StorageAllowanceTest.php Deliver the storage a customer actually buys 2026-07-29 19:13:10 +02:00
StripeAddonBillingTest.php Bill a booked module every month, and put it on the invoice 2026-07-29 20:22:02 +02:00
StripeBillingTest.php Bill a booked module every month, and put it on the invoice 2026-07-29 20:22:02 +02:00
StripePlanChangeTest.php Invoice every renewal, and tell Stripe when the package changes 2026-07-29 19:35:15 +02:00