fix: detect billing plan across all active Stripe subscriptions - #5228
fix: detect billing plan across all active Stripe subscriptions#5228Siumauricio wants to merge 2 commits into
Conversation
getCurrentPlanForUser and getProducts only inspected subscriptions.data[0], so a customer with more than one active Stripe subscription (e.g. Startup plus a separately purchased additional server) could have their plan resolved from the wrong subscription, resulting in currentPlan !== "startup" and the HubSpot chat bubble not rendering.
| 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, | ||
| ); | ||
| currentPriceAmount = totalCents / 100; |
There was a problem hiding this comment.
Mixed billing intervals misprice totals
If a customer has active subscriptions with different billing intervals, currentPriceAmount combines all their charges while isAnnualCurrent describes only the selected plan subscription, causing an annual charge to be included in a total displayed as monthly—or vice versa—and initializing the plan-change form with a cadence that does not describe that total.
Knowledge Base Used: Billing and enterprise features
There was a problem hiding this comment.
Good catch — fixed in 3f6dfba. currentPriceAmount now sums only the items of the identified plan subscription (activeSub) instead of across all active subscriptions, so it stays consistent with isAnnualCurrent even when a customer has subscriptions on different billing intervals.
Summing across all active subscriptions could mix amounts with different billing intervals (isAnnualCurrent only reflects the matched plan subscription), producing an inconsistent total.
Fixes the HubSpot chat bubble not showing for cloud users on the Startup plan.
getCurrentPlanForUser(billing.ts) andgetProducts(stripe.ts) only looked atsubscriptions.data[0], the first active Stripe subscription returned. A customer with more than one active subscription (e.g. Startup plus a separately purchased additional server) could have the plan resolved from the wrong subscription, socurrentPlancame back asnull/wrong plan instead of"startup", and the chat bubble (gated oncurrentPlan === "startup") never rendered.Both functions now scan price IDs across all active subscriptions instead of just the first one.
getProductsalso sumscurrentPriceAmountacross all active subscriptions instead of only the first one's items.Verified locally with Playwright against a cloud-mode instance:
stripe.getCurrentPlannow returns"startup"and the HubSpot script loads correctly.Greptile Summary
The PR updates Stripe plan detection to inspect all active subscriptions instead of only the first and aggregates their charges for the billing view.
Confidence Score: 4/5
The mixed-interval price aggregation should be corrected before merging because it can show customers a materially incorrect billing amount and cadence.
getProducts labels a sum spanning every active subscription with the billing interval of only the selected plan subscription, so annual and monthly charges can be combined and presented as though they share one cadence.
Files Needing Attention: apps/dokploy/server/api/routers/stripe.ts
Reviews (1): Last reviewed commit: "fix: detect billing plan across all acti..." | Re-trigger Greptile
Context used: