fix(billing): warn paying build-only orgs that exceed their plan

Merged
RI
3d ago
+60-15

Problem

The admin "Above Plan Without Credits" count is rising. On 2026-11-24 prod had 14 active paying orgs above plan with no usable credits. 12 got the weekly user:upgrade_to_* email on 2026-11-23, and Bento's "Your Capgo plan needs attention" template shows opens and clicks from them. 2 orgs (EquiFarmX at 393%, UnPurchase at 270%) never got any warning.

Both orgs use only native builds and have never uploaded a bundle, so is_onboarded_org is false. handleOrgNotificationsAndEvents checked plan usage only for onboarded orgs, which meant:

  • userAbovePlan never ran, so no credit application, no exceeded flags and no upgrade email
  • is_good_plan kept its raw or stale value. UnPurchase stays true at 270%, so the console never shows the "Plan limit reached" banner.

Fix

Run the plan-usage branches when the org is onboarded or has an active plan entitlement. The onboarding email path for non-paying orgs stays the same.

Review follow-ups:

  • A paying org that is still onboarding now gets both the onboarding email and its 50/70/90% usage alerts.
  • syncSubscriptionAndEvents reloads the org after the Stripe sync and uses the fresh plan calculation, the same one cron_stat_org uses. It also saves the credit-adjusted is_good_plan, guarded on product and price, so can_use_more updates right away. I removed the unused cached calculatePlanStatus.

Tests

  • New unit test: a paying org that is not onboarded and is over plan gets user:upgrade_to_maker, finalIsGoodPlan=false and exceeded flags. The test fails without the fix.
  • tests/plans.unit.test.ts: 11/11 pass. eslint is clean.

No UI change. The banner already handles can_use_more=false, and this fix makes that value correct for these orgs.

🤖 Generated with Claude Code


Prove it works
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Summary by CodeRabbit

  • Bug Fixes
    • Plan-usage checks and applicable overage or usage alerts now include organizations with an active plan, even if onboarding is incomplete.
    • Eligible organizations can receive an onboarding reminder alongside a usage-threshold alert. Plan and trial checks now use refreshed subscription information, with credit-adjusted eligibility saved when subscription details match.
  • Tests
    • Added coverage for active-plan organizations with incomplete onboarding, including usage status and notification behavior.