Skip to content

The open alternative to Salesforce, designed for AI.

fix: re-init subscription items when user ends his trial period (#11616)

Etienne71dbd1d66bfe
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 5e320a2692c..c5ba4378e2f 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
@@ -45,6 +45,8 @@ export class BillingSubscriptionService {
private readonly stripeCustomerService: StripeCustomerService,
private readonly twentyConfigService: TwentyConfigService,
private readonly stripeSubscriptionItemService: StripeSubscriptionItemService,
+ @InjectRepository(BillingSubscriptionItem, 'core')
+ private readonly billingSubscriptionItemRepository: Repository<BillingSubscriptionItem>,
) {}
async getCurrentBillingSubscriptionOrThrow(criteria: {
@@ -240,6 +242,11 @@ export class BillingSubscriptionService {
},
);
+ await this.billingSubscriptionItemRepository.update(
+ { stripeSubscriptionId: updatedSubscription.id },
+ { hasReachedCurrentPeriodCap: false },
+ );
+
return {
status: getSubscriptionStatus(updatedSubscription.status),
hasPaymentMethod: true,