The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Billing - Update alert when meter price is updated (#16952)
Etienne3539f5cb7ac6
diff --git a/packages/twenty-server/src/engine/core-modules/billing/services/billing-subscription-update.service.ts b/packages/twenty-server/src/engine/core-modules/billing/services/billing-subscription-update.service.tsindex 50ec6f10ccf..76b826bca24 100644--- a/packages/twenty-server/src/engine/core-modules/billing/services/billing-subscription-update.service.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/services/billing-subscription-update.service.ts@@ -79,37 +79,7 @@ export class BillingSubscriptionUpdateService {newMeteredPriceId: meteredPriceId,} as const;- const isScheduledForPeriodEnd =- await this.shouldUpdateAtSubscriptionPeriodEnd(- billingSubscription,- subscriptionUpdate,- );-await this.updateSubscription(billingSubscription.id, subscriptionUpdate);-- if (!isScheduledForPeriodEnd) {- await this.billingSubscriptionItemRepository.update(- { stripeSubscriptionId: billingSubscription.stripeSubscriptionId },- { hasReachedCurrentPeriodCap: false },- );-- const meteredPricingInfo =- await this.meteredCreditService.getMeteredPricingInfoFromPriceId(- meteredPriceId,- );-- const creditBalance = await this.meteredCreditService.getCreditBalance(- billingSubscription.stripeCustomerId,- meteredPricingInfo.unitPriceCents,- );-- await this.stripeBillingAlertService.createUsageThresholdAlertForCustomerMeter(- billingSubscription.stripeCustomerId,- meteredPricingInfo.tierCap,- creditBalance,- billingSubscription.currentPeriodStart,- );- }}async cancelSwitchMeteredPrice(workspace: WorkspaceEntity): Promise<void> {@@ -299,6 +269,30 @@ export class BillingSubscriptionUpdateService {...subscriptionOptions,});+ if (subscriptionUpdate.type !== SubscriptionUpdateType.SEATS) {+ await this.billingSubscriptionItemRepository.update(+ { stripeSubscriptionId: subscription.stripeSubscriptionId },+ { hasReachedCurrentPeriodCap: false },+ );++ const meteredPricingInfo =+ await this.meteredCreditService.getMeteredPricingInfoFromPriceId(+ toUpdateCurrentPrices.meteredPriceId,+ );++ const creditBalance = await this.meteredCreditService.getCreditBalance(+ subscription.stripeCustomerId,+ meteredPricingInfo.unitPriceCents,+ );++ await this.stripeBillingAlertService.createUsageThresholdAlertForCustomerMeter(+ subscription.stripeCustomerId,+ meteredPricingInfo.tierCap,+ creditBalance,+ subscription.currentPeriodStart,+ );+ }+if (isDefined(nextPhase)) {assertIsDefinedOrThrow(schedule);const { currentPhase: refreshedCurrentPhase } =