From 3f6dfbaaa7e682341f5221543fcc2702a5d4b91b Mon Sep 17 00:00:00 2001 From: Mauricio Siu Date: Sun, 30 Aug 2026 18:13:33 -0600 Subject: [PATCH] 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. --- apps/dokploy/server/api/routers/stripe.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/apps/dokploy/server/api/routers/stripe.ts b/apps/dokploy/server/api/routers/stripe.ts index 32e69b253..f89d2dcbf 100644 --- a/apps/dokploy/server/api/routers/stripe.ts +++ b/apps/dokploy/server/api/routers/stripe.ts @@ -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; }