diff --git a/packages/twenty-server/src/engine/core-modules/billing/services/billing-subscription.service.ts b/packages/twenty-server/src/engine/core-modules/billing/services/billing-subscription.service.ts index 3d74a0a1511bb..93e16d4cc29ab 100644 --- a/packages/twenty-server/src/engine/core-modules/billing/services/billing-subscription.service.ts +++ b/packages/twenty-server/src/engine/core-modules/billing/services/billing-subscription.service.ts @@ -151,7 +151,7 @@ export class BillingSubscriptionService { workspaceId, }); - if (subscriptionToCancel) { + if (isDefined(subscriptionToCancel)) { await this.stripeSubscriptionService.cancelSubscription( subscriptionToCancel.stripeSubscriptionId, ); diff --git a/packages/twenty-server/src/engine/workspace-manager/workspace-cleaner/services/cleaner.workspace-service.ts b/packages/twenty-server/src/engine/workspace-manager/workspace-cleaner/services/cleaner.workspace-service.ts index 972279f17837f..5b2670f549997 100644 --- a/packages/twenty-server/src/engine/workspace-manager/workspace-cleaner/services/cleaner.workspace-service.ts +++ b/packages/twenty-server/src/engine/workspace-manager/workspace-cleaner/services/cleaner.workspace-service.ts @@ -14,6 +14,7 @@ import { In, Repository } from 'typeorm'; import { BillingSubscriptionEntity } from 'src/engine/core-modules/billing/entities/billing-subscription.entity'; import { SubscriptionStatus } from 'src/engine/core-modules/billing/enums/billing-subscription-status.enum'; +import { BillingSubscriptionService } from 'src/engine/core-modules/billing/services/billing-subscription.service'; import { EmailService } from 'src/engine/core-modules/email/email.service'; import { I18nService } from 'src/engine/core-modules/i18n/i18n.service'; import { MetricsService } from 'src/engine/core-modules/metrics/metrics.service'; @@ -59,6 +60,7 @@ export class CleanerWorkspaceService { private readonly workspaceRepository: Repository, @InjectRepository(BillingSubscriptionEntity) private readonly billingSubscriptionRepository: Repository, + private readonly billingSubscriptionService: BillingSubscriptionService, @InjectRepository(UserWorkspaceEntity) private readonly userWorkspaceRepository: Repository, private readonly i18nService: I18nService, @@ -304,7 +306,11 @@ export class CleanerWorkspaceService { userWorkspace.userId, ); } - + if (this.twentyConfigService.get('IS_BILLING_ENABLED')) { + await this.billingSubscriptionService.deleteSubscriptions( + workspace.id, + ); + } await this.workspaceRepository.delete(workspace.id); } }