fix(billing): end the first period before the first provider charge #165
Inga granskare
Etiketter
Inga etiketter
area/backups
area/ci
area/control-panel
area/identity
area/infra
area/observability
area/payments
area/security
area/storage
area/web
blocked
needs-info
needs-triage
priority
high
priority
low
priority
medium
ready-for-implementation
type
bug
type
chore
type
docs
type
epic
type
feature
type
task
wontfix
Ingen milstolpe
Inget projekt
Inga tilldelade
1 deltagare
Notiser
Förfallodatum
Inget förfallodatum satt.
Beroenden
Inga beroenden satta
Referens
bitborg/bitborg-payment!165
Läser in…
Hänvisa till i nytt ärende
Ingen beskrivning angiven.
Ta bort grenen "fix/first-period-end"
Borttagning av en gren är permanent. Även om den borttagna grenen kan fortsätta existera en kort tid innan den faktiskt tas bort, kan det INTE ångras i de flesta fall. Vill du fortsätta?
What
The first period of an auto-renewing subscription now ends 1 ms before Amsterdam midnight of the first provider charge day. The Mollie
startDateis unchanged.Why
The first period ended one interval after payment (
addInterval), while Mollie charges on the next Amsterdam day. Seen on staging: paid 2026-10-12 18:19 UTC, period end 2026-11-12 18:19 UTC, Mollie start 2026-11-13. The portal showed "renews on 12 November". Renewals already end 1 ms before the charge day. Only the first period broke that rule.How
applyFirstPayment, whenrenewal = "auto", a payment method exists and no provider subscription exists yet,periodEnd = amsterdamMidnight(renewalStartDate(addInterval(periodStart, interval))) - 1 ms.startDatestill usesrenewalStartDateof the unaligned end, so the Mollie schedule does not move.renewalStartDate(periodEnd)returns the same day.renewal = "none") and purchases that reuse an existing provider subscription keep the plain interval. An extension of a running period with an existing subscription must not re-anchor it.charge.periodEnd, invoice period, reminders,nextCharge.on, renewal anchor) already derive the charge day withrenewalStartDate. They return the same day as before.Side effect: the first period is up to one day longer. Withdrawal refunds prorate over the period, so the refund can differ by a minor unit or so. The existing withdrawal test now accepts 13500 or 13501.
How tested
New table test in
src/billing.test.ts: monthly and annual, a late-evening Stockholm checkout, a checkout before and a period end after the late-October DST change, and a 31 January checkout clamped to 28 February. Each asserts the period end on the subscription and the charge row,renewalStartDate(periodEnd), and thestartDatesent to the provider. It failed before the fix.pnpm test(473 passed with a Postgres),pnpm typecheckandpnpm lintpass.Closes #163
Version 0.11.3.
5b053791c25960dd738e