CluPilotCloud/app/Services/Billing
nexxo 3cf16ecd63 Name every property that decides what a price charges
The money gate compared amount, currency and interval and left the rest to a
filter that excluded two fields. A recurring, licensed, monthly price with
transform_quantity divide_by 10, at our exact figure, on our product, carrying
our addon key passed all five conditions. Modules bill BY quantity — a pack is
one item at quantity n — so a customer holding three would have been charged
one. A tiered price was excluded only by accident: Stripe reports unit_amount
null for it and we read that as 0, which fails the amount match unless the
caller's own figure is 0, and PlanPrices::ensure() has no zero guard.

activePricesFor() now also skips a non-empty transform_quantity and any
billing_scheme other than per_unit. Absent keys stay Stripe's defaults, which
is the direction that matters: read the other way round the filter would refuse
every legitimate price and turn recognition into a permanent no-op. The
contract docblock names the four properties instead of claiming to cover all of
them, and says the list is not everything Stripe can put on a price — only
what is known to change what one charges.

And a comment that says a gap is covered is worse than the gap. The sync said a
crash between Stripe creating a product and us storing its id gives back the
same product next run: true for twenty-four hours, false afterwards, and the
exact claim this branch was written to refute. There is no recognition step for
products at all, so an interrupted run leaves an orphan and the next run past
the expiry mints a second one — worse than a duplicate price, because
activePricesFor() then looks at the wrong product and recognition goes blind
for the whole family. Written down as a known gap at both createProduct call
sites, with the trade this branch chose: folding name and metadata into the key
means a renamed family now mints a second product where it used to answer 400,
and a blockade reaches a paying customer while a duplicate product does not.

The sweep no longer reports "created" for what it adopted — the count is taken
before ensure() runs, and telling those two apart is the whole point.

The test named after 2026-07-29 could not reproduce it: the fake's key ledger
was empty, so createPrice() could not have thrown and the test could not tell
"adoption prevented the 400" from "no 400 was possible". Seeded now with the
key today's call sends and a fingerprint over the metadata the pre-9da1358 call
sent. Remove the adopt() call from AddonPrices::ensure() and the test dies with
Stripe's own sentence instead of an assertion.

Also: the plan document still instructed migrate:fresh --env=testing. There is
no .env.testing here, so it targets the live development database; struck
through with the reason, not deleted, and a Korrekturen section records the
five defects the plan's own reviews found in it. Four comments corrected —
"below" that meant above, a counter claimed unable to tie that ties with a
planted price, the unique index's second meaning for remember()'s catch, and
that MariaDB DDL is not transactional so the dedupe commits before the index.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-30 13:50:20 +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 Name every property that decides what a price charges 2026-07-30 13:50:20 +02:00
AdoptStripePrice.php Make the money gate compare the whole recurrence 2026-07-30 11:15:16 +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 Paketversionen: Verkauf wieder aufnehmen und saubere Übergabe 2026-07-29 14:58:11 +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 Restore the key's own reason and pin the plan-side identifying key 2026-07-30 12:34:08 +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