From 7530775dc1e9413710f5832ca2f9eef7d10a6ed8 Mon Sep 17 00:00:00 2001 From: Etienne <45695613+etiennejouan@users.noreply.github.com> Date: Tue, 9 Jun 2026 16:12:48 +0200 Subject: [PATCH] fix(billing) - Suspend workspace at trial period end if cancelation is planned (#21363) https://twenty-v7.sentry.io/issues/6900026484/events/e5a9e11fe0464df296d8beeabcf0f538/?end=2026-06-09T05%3A24%3A00&project=4507072499810304&query=%21twenty.workspace.id%3A%EF%80%8DContains%EF%80%8Dad6668da-9f4c-4618-9424-9092ea87db26%20%21twenty.workspace.id%3A%EF%80%8DContains%EF%80%8D86b352c5-ffff-4a4c-8660-b1b2bfb7f57d&referrer=next-event&start=2026-05-23T06%3A02%3A00 --- .../services/billing-webhook-subscription.service.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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.ts index a78c98c0ed..e3d9f904c6 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 @@ -197,7 +197,6 @@ export class BillingWebhookSubscriptionService { const suspendedStatuses = [ SubscriptionStatus.Canceled, SubscriptionStatus.Unpaid, - SubscriptionStatus.Paused, // TODO: remove this once paused subscriptions are deprecated ]; if (suspendedStatuses.includes(status)) { @@ -208,7 +207,16 @@ export class BillingWebhookSubscriptionService { const hasTrialJustEnded = timeSinceTrialEnd > 0 && timeSinceTrialEnd < 60 * 60 * 24; - return hasTrialJustEnded && status === SubscriptionStatus.PastDue; + const canceledDuringTrial = + data.object.cancel_at_period_end && + isDefined(data.object.canceled_at) && + isDefined(data.object.trial_end) && + data.object.canceled_at <= data.object.trial_end; + + return ( + hasTrialJustEnded && + (status === SubscriptionStatus.PastDue || canceledDuringTrial) + ); } async updateBillingSubscriptionItems(