The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
fix(billing): only reactivate suspended workspaces when subscription is in good standing (#22687)
Etiennef2d0a1b90a51
diff --git a/packages/twenty-server/src/engine/core-modules/billing-webhook/services/billing-webhook-subscription.service.ts b/packages/twenty-server/src/engine/core-modules/billing-webhook/services/billing-webhook-subscription.service.tsindex 69c0180686d..d520dc962e4 100644--- a/packages/twenty-server/src/engine/core-modules/billing-webhook/services/billing-webhook-subscription.service.ts+++ b/packages/twenty-server/src/engine/core-modules/billing-webhook/services/billing-webhook-subscription.service.ts@@ -150,9 +150,7 @@ export class BillingWebhookSubscriptionService {'currentBillingSubscription',]);- const shouldSuspend = this.shouldSuspendWorkspace(data);-- if (shouldSuspend) {+ if (this.shouldSuspendWorkspace(data)) {if (workspace.activationStatus === WorkspaceActivationStatus.ACTIVE) {await this.workspaceService.suspendWorkspace(workspaceId);} else if (@@ -162,6 +160,7 @@ export class BillingWebhookSubscriptionService {await this.workspaceService.deleteWorkspace(workspace.id);}} else if (+ this.shouldReactivateWorkspace(data) &&workspace.activationStatus === WorkspaceActivationStatus.SUSPENDED) {await this.workspaceService.reactivateWorkspace(workspaceId);@@ -216,6 +215,22 @@ export class BillingWebhookSubscriptionService {);}+ shouldReactivateWorkspace(+ data:+ | Stripe.CustomerSubscriptionUpdatedEvent.Data+ | Stripe.CustomerSubscriptionCreatedEvent.Data+ | Stripe.CustomerSubscriptionDeletedEvent.Data,+ ): boolean {+ const status = data.object.status as SubscriptionStatus;++ const activeStatuses = [+ SubscriptionStatus.Active,+ SubscriptionStatus.Trialing,+ ];++ return activeStatuses.includes(status);+ }+async updateBillingSubscriptionItems(subscriptionId: string,event: