fix(billing): detect a subscription mollie cancelled or suspended #157

Sammanfogat
supernaut sammanfogade 2 incheckningar från fix/142-detect-mollie-cancelled-sub in i main 2026-10-12 14:56:55 +00:00
Ägare

What

Mollie sends no webhook when a subscription changes status. Revoking a mandate cancels its subscriptions without creating a payment, and a subscription can become suspended. Locally the subscription stayed active, nextCharge kept promising a charge, and access ended silently after period end plus grace.

  • New PaymentProvider.getSubscription(providerSubRef) returns status and nextPaymentDate. Implemented in the Mollie adapter, the disabled provider and the test fake.
  • Once an hour (the sweep that starts in the first 10 minutes of the hour), the sweep reads the Mollie subscription of each active auto-renew subscription. Reading starts at the portal's first renewal reminder: 30 days before an annual period end, 7 before a monthly one. It continues past the period end until the grace ends.
  • canceled or suspended marks the subscription past_due. nextCharge is then null and graceEndsAt is set. The normal grace and end path follows.
  • The write is guarded on status, cancelAtPeriodEnd and periodEnd, so a renewal or cancellation that lands after the read wins.
  • This also covers a lost failure webhook: reconcile replays only paid payments.

No version bump: the release bump comes with the batch.

API

For past_due, subscriptionStatus returns status: "past_due", nextCharge: null, paidUntil and currentPeriodEnd set to the period end, and graceEndsAt = period end + 8 days (null if cancelAtPeriodEnd). No shape change. A provider-stopped subscription can be past_due before its period end, with no failed charge. The graceEndsAt contract comment says so.

Tests

  • Cancelled and suspended provider subscriptions become past_due with no next charge, then end after the grace.
  • Annual and monthly subscriptions are read only inside their window, and only in the first sweep of the hour.
  • A cancellation seen after the period end (lost failure webhook) marks past_due.
  • A renewal that lands during the read keeps the subscription active.
  • Adapter: getSubscription reads under the customer and maps status and next payment date.

Closes #142

## What Mollie sends no webhook when a subscription changes status. Revoking a mandate cancels its subscriptions without creating a payment, and a subscription can become `suspended`. Locally the subscription stayed `active`, `nextCharge` kept promising a charge, and access ended silently after period end plus grace. - New `PaymentProvider.getSubscription(providerSubRef)` returns `status` and `nextPaymentDate`. Implemented in the Mollie adapter, the disabled provider and the test fake. - Once an hour (the sweep that starts in the first 10 minutes of the hour), the sweep reads the Mollie subscription of each active auto-renew subscription. Reading starts at the portal's first renewal reminder: 30 days before an annual period end, 7 before a monthly one. It continues past the period end until the grace ends. - `canceled` or `suspended` marks the subscription `past_due`. `nextCharge` is then null and `graceEndsAt` is set. The normal grace and end path follows. - The write is guarded on status, `cancelAtPeriodEnd` and `periodEnd`, so a renewal or cancellation that lands after the read wins. - This also covers a lost failure webhook: reconcile replays only paid payments. No version bump: the release bump comes with the batch. ## API For `past_due`, `subscriptionStatus` returns `status: "past_due"`, `nextCharge: null`, `paidUntil` and `currentPeriodEnd` set to the period end, and `graceEndsAt` = period end + 8 days (null if `cancelAtPeriodEnd`). No shape change. A provider-stopped subscription can be `past_due` before its period end, with no failed charge. The `graceEndsAt` contract comment says so. ## Tests - Cancelled and suspended provider subscriptions become `past_due` with no next charge, then end after the grace. - Annual and monthly subscriptions are read only inside their window, and only in the first sweep of the hour. - A cancellation seen after the period end (lost failure webhook) marks `past_due`. - A renewal that lands during the read keeps the subscription active. - Adapter: `getSubscription` reads under the customer and maps status and next payment date. Closes #142
supernaut lade till 2 incheckningar 2026-10-12 14:23:20 +00:00
Mollie sends no webhook when a subscription changes status. Revoking the mandate cancels the subscription, and no payment is created. The local subscription stayed `active`, `nextCharge` kept promising a charge, and access ended silently after the grace.

- `PaymentProvider.getSubscription` reads the provider subscription: status and `nextPaymentDate`.
- The sweep reads each active auto-renew subscription from 30 days before its period end, the longest reminder lead. A cancelled or suspended one is marked `past_due`, so `nextCharge` is null and `graceEndsAt` is set.
- The write is skipped when a renewal or cancellation landed after the read.
- This also covers a lost failure webhook, since reconcile replays only paid payments.

Version 0.11.2.

Closes #142
fix(billing): read the mollie subscription hourly within the reminder lead
Alla kontroller lyckades
ci / ci (pull_request) Successful in 2m2s
fbd2cd33fc
The sweep runs every 10 minutes, and a 30-day window covered nearly every monthly subscription on each run.

- The window follows the portal's first reminder: 30 days before an annual period end, 7 before a monthly one. Reads continue past the period end until the grace ends.
- Only the sweep that starts in the first 10 minutes of an hour reads the provider.
- The release version bump is left to the batch release.
- The `graceEndsAt` contract comment is re-wrapped.

Refs #142
supernaut tvångsskickade fix/142-detect-mollie-cancelled-sub från fbd2cd33fc
Alla kontroller lyckades
ci / ci (pull_request) Successful in 2m2s
till be4e3fff10
Alla kontroller lyckades
ci / ci (pull_request) Successful in 2m12s
2026-10-12 14:54:17 +00:00
Jämför
supernaut schemalade den här ändringsförfrågan för automatisk sammanfogning när alla kontroller lyckas 2026-10-12 14:54:32 +00:00
supernaut sammanfogade incheckning 01f208d655 till main 2026-10-12 14:56:55 +00:00
supernaut tog bort grenen fix/142-detect-mollie-cancelled-sub 2026-10-12 14:56:55 +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!157
Ingen beskrivning angiven.