Skip to content

feat(billing): give referred users the referral trial - #4277

Open
baktun14 wants to merge 5 commits into
feat/billing-capture-referral-linkfrom
feat/billing-referral-trial
Open

baktun14 wants to merge 5 commits into
feat/billing-capture-referral-linkfrom
feat/billing-referral-trial

Conversation

@baktun14

@baktun14 baktun14 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Why

Closes CON-1190. A bigger trial gives affiliates something to offer and gives referred users enough credit to try a real workload. The standard trial is $1.

Stacked on #4276.

What

  • A new user linked to an affiliate gets REFERRAL_TRIAL_DEPLOYMENT_ALLOWANCE_AMOUNT as their trial deployment limit ($5 by default), and everyone else keeps the standard trial. The amount is an env value, so we can change it without a release. Fees, the anti-abuse checks, deployment limits and expiry are unchanged.
  • The granted amount is saved on the referral inside the same locked transaction that grants the trial, before the wallet is marked activated, so a failed write is retried along with the activation instead of being skipped.
  • trial_started in Amplitude now carries is_referral and trial_credits_usd.
  • GET /v1/referral returns the referred user's trial amount ({ data: null } for everyone else). The onboarding page shows that amount and falls back to NEXT_PUBLIC_TRIAL_CREDITS_AMOUNT. It only asks while affiliate_program is on, so with the flag off it makes no new request and works against an API that predates this PR.

Ops: set REFERRAL_TRIAL_DEPLOYMENT_ALLOWANCE_AMOUNT in Doppler if we want something other than $5 (same micro-denom unit as TRIAL_DEPLOYMENT_ALLOWANCE_AMOUNT).

Testing

Unit specs for the wallet initializer (referred, not referred, the anti-abuse checks for referred users, a failed record), the referral service, the query hook and the onboarding page, plus a functional spec for the endpoint. Mutation score on changed lines: API 100%, deploy-web 100%.

Screenshots

Onboarding for a user who signed up through an affiliate link:

Onboarding showing $5 in free trial credits

@baktun14
baktun14 requested a review from a team as a code owner October 8, 2026 12:44

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review: 1

  • main

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@baktun14

Copy link
Copy Markdown
Contributor Author

@claude review

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Code review skipped — your organization's remaining monthly code review budget is too low to start another review, so this review was not started.

An organization admin can view or raise the monthly spending cap at claude.ai/admin-settings/usage, on the Claude Code Review row under Services. The cap resets at the start of the next billing period.

Once the cap resets or is raised, someone with write access to this repository can comment @claude review on this pull request to trigger a review.

@baktun14
baktun14 force-pushed the feat/billing-capture-referral-link branch from 12234c6 to e036578 Compare November 4, 2026 07:29
@baktun14
baktun14 force-pushed the feat/billing-referral-trial branch from 7f67a5b to 80eb401 Compare November 4, 2026 07:29
@baktun14
baktun14 force-pushed the feat/billing-capture-referral-link branch from e036578 to ad3ecae Compare November 5, 2026 21:02
@baktun14
baktun14 force-pushed the feat/billing-referral-trial branch from 80eb401 to 1d9a57c Compare November 5, 2026 21:02
@baktun14
baktun14 force-pushed the feat/billing-capture-referral-link branch from ad3ecae to a39d61e Compare November 5, 2026 21:43
@baktun14
baktun14 force-pushed the feat/billing-referral-trial branch from 1d9a57c to b020646 Compare November 5, 2026 21:43
Referred sign-ups now get the env-configured referral trial deployment
allowance instead of the standard trial amount, exposed via GET
/v1/referral and shown on the onboarding page.
Kills two surviving mutants from the stryker run: a zero-cents edge
case on the recorded referral trial amount, and a sign check on the
trial activation latency passed to instrumentation.
recordTrialGranted ran after the wallet was marked activatedAt, so a
failure there left the trial credits unrecorded while the retry
short-circuited on the already-activated wallet and reported success.
Granting on-chain, then recording the referral trial, then activating
means a failure anywhere leaves the wallet unactivated and the retry
replays the whole sequence.
A referred user briefly saw the default trial amount before the referral
query resolved and swapped in the referral amount.
@baktun14
baktun14 force-pushed the feat/billing-capture-referral-link branch from a39d61e to ba1c23e Compare November 9, 2026 01:08
@baktun14
baktun14 force-pushed the feat/billing-referral-trial branch from b020646 to 10cb1a6 Compare November 9, 2026 01:08

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant