fix: only sum currentPriceAmount from the identified plan subscription

Summing across all active subscriptions could mix amounts with
different billing intervals (isAnnualCurrent only reflects the
matched plan subscription), producing an inconsistent total.
This commit is contained in:
Mauricio Siu 2026-08-30 18:13:33 -06:00
parent e79239a100
commit 3f6dfbaaa7

View File

@ -115,17 +115,12 @@ export const stripeRouter = createTRPCRouter({
| undefined;
isAnnualCurrent = firstPrice?.recurring?.interval === "year";
const totalCents = subscriptions.data.reduce(
(subTotal, sub) =>
subTotal +
sub.items.data.reduce((sum, item) => {
const price = item.price as Stripe.Price;
const amount = price.unit_amount ?? 0;
const qty = item.quantity ?? 1;
return sum + amount * qty;
}, 0),
0,
);
const totalCents = (activeSub?.items.data ?? []).reduce((sum, item) => {
const price = item.price as Stripe.Price;
const amount = price.unit_amount ?? 0;
const qty = item.quantity ?? 1;
return sum + amount * qty;
}, 0);
currentPriceAmount = totalCents / 100;
}