Skip to content

fix(billing): block tracking + features for orgs without active subscription - #56

Merged
gkhngyk merged 1 commit into
mainfrom
fix/subscription-gate-tracking
May 19, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/subscription-gate-tracking

Conversation

@gkhngyk

@gkhngyk gkhngyk commented May 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Three places on the aeo-server fell back to starter plan limits whenever an org's Stripe subscription wasn't `active`. That meant any signup who completed onboarding and closed the Stripe checkout tab — leaving the org at `plan='free'` `subscription_status='incomplete'` — silently kept running on-demand tracking, daily monitoring cron, and gated feature calls. Cloro + AI provider spend continued landing on us for users who never paid.
  • The intended rule is: only orgs with `subscription_status` of `'active'` or `'trialing'` (Stripe sets `trialing` during the free-trial period of a paid plan) may use billed features. Everything else (`incomplete`, `canceled`, `past_due`, `unpaid`) is blocked.

What changes

Centralizes the check as `isSubscriptionActive(status)` in `server/src/config/plans.js` and applies it in three spots:

File Old behaviour New behaviour
`routes/tracking.js` POST `/check` `subscription_status !== 'active'` → starter fallback, job runs Returns 402 with a "subscribe to continue" message
`server.js` `runDailyTracking()` cron Same fallback, processed brand silently Skips the brand entirely (`plan = null` → continue)
`lib/plan-guard.js` `resolveOrgPlan()` Same fallback for feature checks (volume fetch, content gen, etc.) Throws `PlanLimitError(402)` with the same message

Self-hosted instances are unaffected — `isSubscriptionActive()` short-circuits to `true` when `IS_CLOUD !== 'true'`.

What this does NOT change

The Next.js `(dashboard)` layout already redirects when `subscription_status` is not active/trialing. The gap was entirely on the aeo-server endpoints/cron that don't go through that layout — they were the silent leak. UI behaviour stays the same; users hitting a blocked endpoint will see a "subscribe to continue" message instead of phantom progress.

Existing 6 unsubscribed orgs

There are 6 orgs at `plan='free'` / `subscription_status='incomplete'` today (real prospect signups, including one major TR retail brand). After this lands they lose tracking access on their next attempt. The "soft cut + manual outreach" path is intentional — they're high-value prospects, the maintainer will email them to push through Stripe checkout before merge.

Test plan

  • On a brand whose org has `subscription_status='incomplete'` or `'canceled'`, hit `POST /api/tracking/check` → response is `402` with the subscribe message
  • Same org, daily cron run → that brand is logged as skipped and produces no `prompt_results` rows
  • Feature-gated endpoint (e.g. volume re-fetch) for that org → returns `402`
  • On a brand whose org has `subscription_status='trialing'` → all of the above succeed normally (this is the legit free-trial case and must NOT regress)
  • On a brand whose org has `subscription_status='active'` → all of the above succeed normally
  • Self-hosted instance with `IS_CLOUD=false` → all of the above succeed regardless of subscription_status (it doesn't apply)

…ription

Three places on the aeo-server fell back to starter plan limits whenever
an org's Stripe subscription was not active. That meant any signup who
completed onboarding and closed the Stripe checkout tab — leaving the
org at plan='free' subscription_status='incomplete' — silently kept
running on-demand tracking, daily monitoring cron, and gated feature
calls, with Cloro and AI provider spend still landing on us.

The intended rule is: only orgs with subscription_status of 'active' or
'trialing' (which Stripe sets while a paid plan is in its free-trial
period) may use billed features. Everything else (incomplete, canceled,
past_due, unpaid) is blocked.

Centralizes the check as isSubscriptionActive() in config/plans.js and
applies it in three spots:

- routes/tracking.js POST /check — returns 402 with a "subscribe to
  continue" message instead of falling back to starter limits
- server.js runDailyTracking() cron — skips brands whose org has no
  active subscription; previously these brands silently consumed
  daily jobs
- lib/plan-guard.js resolveOrgPlan() — throws PlanLimitError(402)
  on feature checks (volume fetch, content generation, etc.)

Self-hosted instances are unaffected: isSubscriptionActive() short-
circuits to true when IS_CLOUD !== 'true'.

Note on Next.js side: the (dashboard) layout already redirects when
subscription_status is not active/trialing, so the gap was entirely
on the aeo-server endpoints / cron that don't go through that layout.
@gkhngyk
gkhngyk merged commit cb8056d into main May 19, 2026
2 checks passed
@gkhngyk
gkhngyk deleted the fix/subscription-gate-tracking branch May 20, 2026 10:06
@gkhngyk gkhngyk mentioned this pull request May 26, 2026

This branch was successfully deployed

1 active deployment
Preview — bab7cb05 Deployed May 19, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant