fix(billing): downgrade orgs when Polar subscription is revoked (#759)

* fix(billing): downgrade orgs when Polar subscription is revoked

The Polar webhook handler had subscription.revoked as a no-op, so
subscriptions that expired or failed to renew never got the org's
organization_plan row deactivated, leaving them stuck on a paid plan
indefinitely. Handle subscription.revoked the same way as an inactive
subscription.updated event.

Also add a one-time backfill script (db:downgrade-expired-subscriptions)
that re-checks every currently-active org plan against Polar directly
and downgrades any whose subscription already ended, to fix orgs
affected before this webhook fix shipped.

* Update packages/db/src/scripts/downgrade-expired-subscriptions.ts

---------
This commit is contained in:
Rotimi Best
2026-07-16 00:57:31 +01:00
committed by GitHub
parent 3980aa0a9b
commit c9b7c79365
4 changed files with 149 additions and 1 deletions
+1
View File
@@ -71,6 +71,7 @@
"db:backfill-profile-email-verification": "tsx src/scripts/backfill-profile-email-verification.ts",
"db:update-user-email": "tsx src/scripts/update-user-email.ts",
"db:notify-students-over-limit": "tsx src/scripts/notify-students-over-limit.ts",
"db:downgrade-expired-subscriptions": "tsx src/scripts/downgrade-expired-subscriptions.ts",
"move-users": "tsx src/scripts/supabase-to-betterauth.ts",
"pull": "drizzle-kit pull --config drizzle.config.ts",
"generate-types": "tsx scripts/generate-types.ts && pnpm format",