fixes - remove billing cancellation at trial end + disable ai chat if suspended (#21261)

- Remove billing cancelation if trial is ended (subscription activated)
- Disable AI Chat use if workspace suspended
This commit is contained in:
Etienne
2026-06-05 17:34:12 +02:00
committed by GitHub
parent 84ba7eb8dc
commit 27db8bbae4
3 changed files with 18 additions and 0 deletions
@@ -5,6 +5,7 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { ClickHouseModule } from 'src/database/clickHouse/clickHouse.module';
import { WorkspaceIteratorModule } from 'src/database/commands/command-runners/workspace-iterator.module';
import { CoreEntityCacheModule } from 'src/engine/core-entity-cache/core-entity-cache.module';
import { BillingGaugeService } from 'src/engine/core-modules/billing/billing-gauge.service';
import { BillingResolver } from 'src/engine/core-modules/billing/billing.resolver';
import { BillingSyncCustomerDataCommand } from 'src/engine/core-modules/billing/commands/billing-sync-customer-data.command';
@@ -49,6 +50,7 @@ import { WorkspaceCacheModule } from 'src/engine/workspace-cache/workspace-cache
@Module({
imports: [
ClickHouseModule,
CoreEntityCacheModule,
FeatureFlagModule,
StripeModule,
MessageQueueModule,
@@ -263,6 +263,7 @@ export class BillingSubscriptionService {
billingSubscription.stripeSubscriptionId,
{
trial_end: 'now',
cancel_at_period_end: false,
},
);
@@ -3,10 +3,12 @@
import { Injectable, Logger } from '@nestjs/common';
import { isDefined } from 'twenty-shared/utils';
import { WorkspaceActivationStatus } from 'twenty-shared/workspace';
import { differenceInDays } from 'date-fns';
import { ClickHouseService } from 'src/database/clickHouse/clickHouse.service';
import { formatDateTimeForClickHouse } from 'src/database/clickHouse/clickHouse.util';
import { CoreEntityCacheService } from 'src/engine/core-entity-cache/services/core-entity-cache.service';
import {
BillingException,
BillingExceptionCode,
@@ -49,6 +51,7 @@ export class BillingUsageService {
private readonly workspaceCacheService: WorkspaceCacheService,
private readonly clickHouseService: ClickHouseService,
private readonly billingUsageCapService: BillingUsageCapService,
private readonly coreEntityCacheService: CoreEntityCacheService,
) {}
async canFeatureBeUsed(workspaceId: string): Promise<boolean> {
@@ -348,6 +351,18 @@ export class BillingUsageService {
return true;
}
const workspace = await this.coreEntityCacheService.get(
'workspaceEntity',
workspaceId,
);
if (
isDefined(workspace) &&
workspace.activationStatus === WorkspaceActivationStatus.SUSPENDED
) {
return false;
}
const { billingSubscription: subscription } =
await this.workspaceCacheService.getOrRecompute(workspaceId, [
'billingSubscription',