Skip to content

feat(billing): card-required Pro free trial with a capped allowance - #10330

Merged
waleedlatif1 merged 4 commits into
stagingfrom
feat/pro-card-trial
Nov 23, 2026
Merged

waleedlatif1 merged 4 commits into
stagingfrom
feat/pro-card-trial

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Trial at checkout: new personal Pro subscribers get a 14-day free trial through Stripe Checkout (subscription_data.trial_period_days).
    • A card is required, and only a card, so it always has a fingerprint.
    • A trial left without a payment method cancels.
    • Eligibility is decided in getProTrialCheckoutParams. Only the Pro tier on a personal reference qualifies, for an account that has never trialed or held a subscription and still holds its free allowance. Abandoned checkouts don't count against it.
  • One trial per card and per account: enforceOneTrialPerCard runs when checkout completes.
    • Card fingerprints are claimed in a new trial_card table. A claim outlives account deletion (user_id set null).
    • A reused card, a second trial on the same account (checkouts racing), or a card with no fingerprint ends the trial at once (trial_end: 'now'), so Stripe charges the card.
    • A redelivered webhook finds its own claim and keeps the trial.
  • Trial counts as Pro: trialing joins the entitled and usable statuses, so a trial gets Pro features and Sim-hosted keys.
  • What differs during a trial:
    • Fixed allowance: usage is capped at PRO_TRIAL_USAGE_LIMIT_DOLLARS (2,000 credits). syncUsageLimitsFromSubscription sets it exactly, which also lowers a stale higher limit, and raises it to the plan base on conversion.
    • No weekly refresh: via getSubscriptionWeeklyRefreshDollars.
    • No limit or on-demand edits: canEditUsageLimit is false, updateUserUsageLimit uses it, and the UI separates canManageBilling from canEditUsageLimit.
    • No overage:
      • billsOverage gates threshold billing and the capped-payer mid-run checks.
      • calculateSubscriptionOverage returns 0 for a period inside the trial.
      • Cycle close sweeps only SETTLED_SUBSCRIPTION_STATUSES, which matches the partial index predicate, so a trial period is never closed or billed.
    • No team conversion or transfer until the trial converts.
  • Direct-v1 billing: account decisions now record payerBillsOverage, so trial payers are capped on that path too. Older decisions fall back to the previous rule.
  • UI and emails:
    • Billing settings show "Free trial ends" and hide weekly refresh and on-demand during a trial.
    • The welcome, 80% and limit-reached emails get trial wording.
    • Pricing FAQ, comparison table and cost docs describe the trial.
  • Migration 0470_pro_trial_card: a new table only.

Type of Change

  • New feature

Testing

  • lib/billing/trial.integration.ts (real Postgres, Stripe stubbed), 16 cases:
    • Eligibility: new account, abandoned checkout, Max, team, org, earlier trial, earlier paid plan, reused identity.
    • Card enforcement: first trial, redelivery, a card reused after the first account is deleted, unidentifiable card, an account racing a second trial, non-trial checkout.
    • Limits: trial cap, stale-limit lowering, conversion to plan base, refused limit raise.
    • Proved red: reverting each guard fails its cases.
  • Unit tests:
    • mid-run-usage.test.ts: capped payer on attributed runs and on direct-v1 runs (with and without the overage flag).
    • billing.test.ts: overage for a trial period vs a period past the trial.
    • threshold-billing.test.ts: a trial never bills.
    • utils.test.ts: no weekly refresh during a trial.
    • validate/route.test.ts: the account decision header carries the overage flag.
  • Ran the unit tests beside every changed source file, plus bun run lint, check:migrations and the generators. CI runs type-check and the full audits.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
docs Ready Ready Preview Nov 23, 2026 12:08pm UTC

Request Review

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 47 files

Confidence score: 3/5

  • freeTierEligible in apps/sim/lib/billing/trial.ts can allow trial checkout for accounts that have already used their free allowance. Check effective free usage before returning trial checkout.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/sim/lib/billing/trial.ts">

<violation number="1" location="apps/sim/lib/billing/trial.ts:56">
P2: This gate does not exclude accounts that have already spent their free allowance. `freeTierEligible` only tracks deleted-identity reuse, so check the account's effective free usage before returning trial checkout parameters.</violation>
</file>

This PR changes payment, billing, or quota logic. Ultrareviews find 2.4x more serious bugs than standard reviews. Comment @cubic-dev-ai ultrareview to run one.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/billing/trial.ts Resolved
@greptile-apps

greptile-apps Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The latest changes appear safe to merge, with no new blocking issues found.

Summary

Adds a card-required Pro trial with a fixed allowance, trial-aware billing checks, and updated billing copy.

  • New personal Pro subscribers can start a card-backed 14-day trial.
  • Trial usage stays capped until the subscription converts to a paid plan.
  • Billing screens and emails explain the trial end date and credit cap.
  • Trial subscriptions cannot be transferred or converted into team plans.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Checkout completes] --> B[Read saved subscription]
  B --> C{Personal Pro trial?}
  C -->|No| D[Leave unchanged]
  C -->|Yes| E[Read card fingerprint]
  E --> F[Lock claims for this account]
  F --> G[Insert claim and read winners]
  G --> H{Account and card both win?}
  H -->|Yes| I[Keep trial]
  H -->|No| J[End trial now]
  B -->|Read fails or row missing| K[Fail webhook for retry]
Loading

Reviews (3) · Last reviewed commit: "fix(billing): serialize trial claims per..." · Reviewed by Greptile

Comment thread apps/sim/lib/auth/auth.ts Resolved
Comment thread apps/sim/lib/billing/trial.ts Resolved
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

Comment thread apps/sim/lib/billing/trial.ts Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 51 files

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/billing/trial.ts Resolved
Comment thread apps/sim/lib/auth/auth.ts Resolved
Comment thread apps/sim/lib/billing/trial.ts Resolved
Comment thread apps/sim/lib/billing/trial.ts Resolved
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 51 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

New personal Pro subscribers get a 14-day trial at checkout with a card
collected up front. The trial counts as Pro (features and Sim-hosted
keys) under a fixed 2,000-credit allowance: no weekly refresh, no
on-demand usage, no overage billing, and no team conversion until it
converts. Each card and each account starts one trial; a reused card
ends the trial at once so the card is charged.
@waleedlatif1
waleedlatif1 merged commit 90cca5e into staging Nov 23, 2026
86 checks passed

This branch was successfully deployed

1 active deployment
Preview — 5bc9db98 Deployed Nov 23, 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