Billing - Update alert when meter price is updated (#16952)

This commit is contained in:
Etienne
2026-01-06 13:25:28 +01:00
committed by GitHub
parent 35c7687ed8
commit 3539f5cb7a
@@ -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 } =