CluPilotCloud/app/Services/Billing
nexxo 048e5ba81f Subtract only what was counted, not everything a singleton adopted
A figure may only subtract what it counted as an intent in the first place. The
family loop counts a Product before knowing whether it will be adopted or
minted, so an adoption there could honestly be subtracted back out — but
syncModules() has never counted a module's own Product as an intent at all; it
only counts a module's Prices. Reading AdoptStripeProduct::adoptions as one
run-wide delta could not tell the two apart, so a module Product adopted from
an interrupted run silently inflated "adopted" and shrank "created" by exactly
one, for a Product the command never claimed to have made in the first place.

The fix counts the family side locally, at the one call site that already
counts the intent, and leaves a module's Product out of both figures entirely —
adopted or minted, it was never counted, so neither number may move for it.
AdoptStripeProduct::$adoptions is gone with it: nothing reads a singleton-wide
total that cannot be attributed to one side or the other, and keeping it around
unread would be exactly the kind of state this codebase does not leave lying
about.

The duplicate-product report had the same shape of bug one line down: it read
straight off the singleton's list with no before/after snapshot, so a second
handle() call in one process would reprint a duplicate an earlier run already
named. Sliced to what this run itself added, the same way the counters beside
it already were.

Also: the unread `$charged` line in the adoption test that TDD had already
exercised as dead weight, and its now-unused PlanPrices import.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-30 18:20:27 +02:00
..
AddonCatalogue.php Ask whether they are a consumer, and let one change their mind 2026-07-29 21:06:06 +02:00
AddonPrices.php Recognise the product Stripe already has 2026-07-30 17:39:15 +02:00
AdoptStripePrice.php Say what was adopted, not that it was created 2026-07-30 17:56:13 +02:00
AdoptStripeProduct.php Subtract only what was counted, not everything a singleton adopted 2026-07-30 18:20:27 +02:00
CustomDomainAccess.php Serve the custom domain, not just announce it 2026-07-29 16:44:52 +02:00
DowngradeCheck.php Deliver the storage a customer actually buys 2026-07-29 19:13:10 +02:00
InvoiceArchive.php Leave the archive readable by whoever collects from it 2026-07-29 03:48:03 +02:00
InvoiceDocument.php Say the same thing to the customer, the register and the bank 2026-07-30 01:30:24 +02:00
InvoiceMath.php Charge the price the website shows, and hand a withdrawal back in full 2026-07-29 22:42:02 +02:00
InvoiceNumbers.php Lay the foundation for self-issued invoices: series, numbers, frozen documents 2026-07-29 00:57:06 +02:00
InvoiceRenderer.php Say the same thing to the customer, the register and the bank 2026-07-30 01:30:24 +02:00
IssueInvoice.php Stop charging VAT to the customers who owe us none 2026-07-30 02:15:41 +02:00
PlanCatalogue.php Sell the year as well as the month, and say what it saves 2026-07-30 15:44:35 +02:00
PlanChange.php Book a downgrade for a date that cannot move, and sell a module once 2026-07-29 17:51:37 +02:00
PlanPrices.php Put the price recognition back, all 3526 lines of it 2026-07-30 16:35:55 +02:00
SampleInvoice.php Print every line at full price and take the discount off once, in euros 2026-07-29 01:59:56 +02:00
SetupFee.php Stop charging VAT to the customers who owe us none 2026-07-30 02:15:41 +02:00
StorageAllowance.php Deliver the storage a customer actually buys 2026-07-29 19:13:10 +02:00
StripeInvoiceLines.php Stop charging VAT to the customers who owe us none 2026-07-30 02:15:41 +02:00
TaxTreatment.php Stop charging VAT to the customers who owe us none 2026-07-30 02:15:41 +02:00
WithdrawalRight.php Charge the price the website shows, and hand a withdrawal back in full 2026-07-29 22:42:02 +02:00