fix(billing): buy again after the provider stops a subscription; report the current card #176

Sammanfogat
supernaut sammanfogade 4 incheckningar från fix/rebuy-after-stop in i main 2026-10-13 11:52:40 +00:00
Ägare

Rebuy after the provider stops a subscription (#156)

A past due subscription the provider has cancelled or suspended will never renew. Checkout used to refuse it with already_subscribed until the grace ended.

  • Checkout is accepted when the latest subscription is past_due, auto-renewing, not cancelled by the customer, and the provider reports it canceled or suspended. A past_due one the provider still retries is refused, so a retry and a new purchase cannot both charge.
  • When the new first payment completes, it locks the stopped predecessor, re-checks it at the provider, and closes it: status canceled, no grace, provider subscription cancelled, mandate queued for revoke unless the new subscription shares it. No revoke of access: the grant for the new subscription keeps the tier.
  • The new period starts at the old period end when that is still ahead of the payment, else at the payment. No gap, no overlap.
  • Replays and reconcile re-fetch change nothing: the charge is no longer pending, and the old subscription is already closed.
  • Race with a late renewal on the old subscription: if the new payment lands first, the renewal is refunded as a renewal after cancellation. If the renewal lands first, the old subscription is active again and the new payment is refunded as a duplicate checkout.

Withdrawal: the 14-day window and the requested_before_purchase check now run from the contract time (the payment, or the period start if earlier), also in the status withdrawalDeadline. The refund arithmetic still uses the period start, so nothing used means a full refund. A withdrawal of a rebuy that has not started revokes nothing and does not cut the old paid days: the new subscription stays live with its end set to the old period end, and the sweep revokes then. The provider subscription is cancelled at once.

Card on the status

subscriptionStatus now reports card (brand, last four digits) for any live subscription, past due included, and null for a one-time payment. It follows a card replacement. The field is optional in the contract, so the current portal keeps working. Contract 0.14.0.

Tests

17 new tests in billing.test.ts and 4 in the contract tests: refusal while retrying, acceptance for canceled and suspended, continuity before and inside the grace, shared and separate mandate, replay and reconcile, both race orders plus a concurrent run, a withdrawal of an unstarted rebuy, no revoke when the old grace ends, and the card cases.

Version 0.15.0.

## Rebuy after the provider stops a subscription (#156) A past due subscription the provider has cancelled or suspended will never renew. Checkout used to refuse it with `already_subscribed` until the grace ended. - Checkout is accepted when the latest subscription is `past_due`, auto-renewing, not cancelled by the customer, and the provider reports it `canceled` or `suspended`. A `past_due` one the provider still retries is refused, so a retry and a new purchase cannot both charge. - When the new first payment completes, it locks the stopped predecessor, re-checks it at the provider, and closes it: status `canceled`, no grace, provider subscription cancelled, mandate queued for revoke unless the new subscription shares it. No revoke of access: the grant for the new subscription keeps the tier. - The new period starts at the old period end when that is still ahead of the payment, else at the payment. No gap, no overlap. - Replays and reconcile re-fetch change nothing: the charge is no longer pending, and the old subscription is already closed. - Race with a late renewal on the old subscription: if the new payment lands first, the renewal is refunded as a renewal after cancellation. If the renewal lands first, the old subscription is active again and the new payment is refunded as a duplicate checkout. Withdrawal: the 14-day window and the `requested_before_purchase` check now run from the contract time (the payment, or the period start if earlier), also in the status `withdrawalDeadline`. The refund arithmetic still uses the period start, so nothing used means a full refund. A withdrawal of a rebuy that has not started revokes nothing and does not cut the old paid days: the new subscription stays live with its end set to the old period end, and the sweep revokes then. The provider subscription is cancelled at once. ## Card on the status `subscriptionStatus` now reports `card` (brand, last four digits) for any live subscription, past due included, and null for a one-time payment. It follows a card replacement. The field is optional in the contract, so the current portal keeps working. Contract 0.14.0. ## Tests 17 new tests in `billing.test.ts` and 4 in the contract tests: refusal while retrying, acceptance for `canceled` and `suspended`, continuity before and inside the grace, shared and separate mandate, replay and reconcile, both race orders plus a concurrent run, a withdrawal of an unstarted rebuy, no revoke when the old grace ends, and the `card` cases. Version 0.15.0.
supernaut lade till 4 incheckningar 2026-10-13 11:49:41 +00:00
supernaut schemalade den här ändringsförfrågan för automatisk sammanfogning när alla kontroller lyckas 2026-10-13 11:51:07 +00:00
supernaut sammanfogade incheckning 652951d4ed till main 2026-10-13 11:52:40 +00:00
supernaut tog bort grenen fix/rebuy-after-stop 2026-10-13 11:52:41 +00:00
Logga in för att delta i denna konversation.
Inga granskare
Ingen milstolpe
Inget projekt
Inga tilldelade
1 deltagare
Notiser
Förfallodatum
Förfallodatumet är ogiltigt eller utanför gränserna. Använd formatet "åååå-mm-dd".

Inget förfallodatum satt.

Beroenden

Inga beroenden satta

Referens
bitborg/bitborg-payment!176
Ingen beskrivning angiven.