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:
@@ -157,6 +157,16 @@ async function onPayload(payload: PolarWebhookPayload) {
|
||||
case 'subscription.active':
|
||||
break;
|
||||
case 'subscription.revoked':
|
||||
try {
|
||||
const result = await OrgPlanApiServer.cancelOrgPlan({
|
||||
subscriptionId,
|
||||
payload: data as unknown as Record<string, unknown>
|
||||
});
|
||||
console.log('Subscription revoked', result);
|
||||
} catch (error) {
|
||||
console.error('Error revoking org plan', error);
|
||||
}
|
||||
|
||||
break;
|
||||
case 'subscription.canceled':
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user