mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-10-15 13:21:11 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user