Skip to content

feat(billing): show affiliates their referrals and earnings - #4281

Merged
baktun14 merged 6 commits into
mainfrom
feat/billing-show-affiliate-earnings
Nov 11, 2026
Merged

baktun14 merged 6 commits into
mainfrom
feat/billing-show-affiliate-earnings

Conversation

@baktun14

@baktun14 baktun14 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Why

Closes CON-1193. Affiliates need to see what their link is doing, both to trust the program and to keep promoting Console.

What

  • GET /v1/affiliates/me adds stats (sign-ups, referred users who paid by card, total commission, commission this calendar month in UTC) and the 100 most recent commission entries (date, amount, amount taken back). Totals are net of reversals.
  • The Referrals page shows the four figures and a commission table. A reversal shows as a deduction, and with nothing earned yet the table is replaced by "No commission yet. You'll see it here when someone you referred pays by card."
  • The figures don't change with the active organization. Commission rows are read per affiliate, so having a team active doesn't hide them. A referred user counts as paying under the same rule as the commission: their personal organization or a team they created.
  • Nothing about the referred users themselves (ids, emails, names) is returned or shown.

Testing

Repository integration specs (counts, distinct paying users, other affiliates excluded, sums with reversals, the month boundary), service and page specs, and functional specs that check the response holds no referred-user identity and still shows the earnings while a team is active. Mutation score on changed lines: API 100%, deploy-web 87.5%.

Screenshots

Rendered from the real components with test data. The figures are fixture values, not totals of the rows.

Referrals page with stats and commission history

A newly approved affiliate:

Referrals page with no commission yet

Dark mode:

Referrals page in dark mode

@baktun14
baktun14 requested a review from a team as a code owner October 8, 2026 15:37

@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

Warning

Review limit reached

  • Run on-demand review

This review includes 14 billable files and costs up to $3.50.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 21 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 52266e4 and c508f05.

Files ignored due to path filters: 1

  • apps/api/test/functional/__snapshots__/docs.spec.ts.snap is excluded by !**/*.snap
Files selected for processing: 14

  • apps/api/src/affiliate/http-schemas/affiliate-profile.schema.ts
  • apps/api/src/affiliate/repositories/referral/referral.repository.integration.ts
  • apps/api/src/affiliate/repositories/referral/referral.repository.ts
  • apps/api/src/affiliate/services/affiliate/affiliate.service.spec.ts
  • apps/api/src/affiliate/services/affiliate/affiliate.service.ts
  • apps/api/src/billing/repositories/stripe-transaction/stripe-transaction.repository.integration.ts
  • apps/api/src/billing/repositories/stripe-transaction/stripe-transaction.repository.ts
  • apps/api/src/core/repositories/unscoped-reasons.ts
  • apps/api/swagger/openapi.json
  • apps/api/test/functional/affiliate-profile.spec.ts
  • apps/deploy-web/src/components/referrals/ReferralsPage/ReferralsPage.spec.tsx
  • apps/deploy-web/src/components/referrals/ReferralsPage/ReferralsPage.tsx
  • apps/deploy-web/src/hooks/useSettingsNavLinks.spec.ts
  • packages/console-api-types/src/schema.d.ts
  • 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-reverse-affiliate-commission branch from 05315db to d76364a Compare November 4, 2026 07:29
@baktun14
baktun14 force-pushed the feat/billing-show-affiliate-earnings branch from 09361ae to 8edad2e Compare November 4, 2026 07:29
@baktun14
baktun14 force-pushed the feat/billing-reverse-affiliate-commission branch from d76364a to 8490638 Compare November 5, 2026 21:02
@baktun14
baktun14 force-pushed the feat/billing-show-affiliate-earnings branch from 8edad2e to cc2e62b Compare November 5, 2026 21:02
@baktun14
baktun14 force-pushed the feat/billing-reverse-affiliate-commission branch from 8490638 to 67c3b38 Compare November 5, 2026 21:43
@baktun14
baktun14 force-pushed the feat/billing-show-affiliate-earnings branch from cc2e62b to 9781445 Compare November 5, 2026 21:43
@baktun14
baktun14 force-pushed the feat/billing-reverse-affiliate-commission branch from 67c3b38 to 340549c Compare November 9, 2026 01:08
@baktun14
baktun14 force-pushed the feat/billing-show-affiliate-earnings branch from 9781445 to 0bfe132 Compare November 9, 2026 01:08
@baktun14
baktun14 changed the base branch from feat/billing-reverse-affiliate-commission to main November 10, 2026 04:43
@baktun14
baktun14 force-pushed the feat/billing-show-affiliate-earnings branch from 0bfe132 to 2b128f4 Compare November 10, 2026 04:43
@github-actions github-actions Bot added size: XL and removed size: L labels Nov 10, 2026
@baktun14
baktun14 force-pushed the feat/billing-show-affiliate-earnings branch from 2b128f4 to ebc50cc Compare November 10, 2026 04:50
@codecov

codecov Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.13%. Comparing base (52266e4) to head (c508f05).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4281      +/-   ##
==========================================
+ Coverage   94.94%   95.13%   +0.19%     
==========================================
  Files        2158     2048     -110     
  Lines       62945    60121    -2824     
  Branches    15758    15192     -566     
==========================================
- Hits        59763    57198    -2565     
+ Misses       2855     2612     -243     
+ Partials      327      311      -16     
Flag Coverage Δ *Carryforward flag
api 96.87% <100.00%> (+0.01%) ⬆️
deploy-web 93.63% <100.00%> (+<0.01%) ⬆️
log-collector ?
notifications 96.68% <ø> (ø) Carriedforward from 52266e4
provider-console 81.68% <ø> (ø) Carriedforward from 52266e4
provider-inventory ?
provider-proxy 95.18% <ø> (ø) Carriedforward from 52266e4
tx-signer ?

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
...liate/repositories/referral/referral.repository.ts 92.00% <100.00%> (+3.11%) ⬆️
.../affiliate/services/affiliate/affiliate.service.ts 100.00% <100.00%> (ø)
...tripe-transaction/stripe-transaction.repository.ts 90.09% <100.00%> (+2.71%) ⬆️
apps/api/src/core/repositories/unscoped-reasons.ts 100.00% <ø> (ø)
...mponents/referrals/ReferralsPage/ReferralsPage.tsx 100.00% <100.00%> (+4.54%) ⬆️

... and 110 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@baktun14
baktun14 force-pushed the feat/billing-show-affiliate-earnings branch from 1d12490 to 5dd55fa Compare November 10, 2026 05:36
@baktun14
baktun14 added this pull request to the merge queue Nov 10, 2026
@baktun14
baktun14 removed this pull request from the merge queue due to a manual request Nov 10, 2026
@baktun14
baktun14 force-pushed the feat/billing-show-affiliate-earnings branch from 5dd55fa to c826540 Compare November 10, 2026 06:01
@baktun14
baktun14 force-pushed the feat/billing-show-affiliate-earnings branch 2 times, most recently from fe9526c to b9df7d6 Compare November 11, 2026 03:54
Extends GET /v1/affiliates/me with signup/paying-user counts and
commission totals, plus a list of recent commission entries, and
renders both on the Referrals page.

- add ReferralRepository.countByAffiliate / countPayingByAffiliate
- add StripeTransactionRepository.sumAffiliateCommissionNet /
  findAffiliateCommissions
- AffiliateService.getProfile returns stats and commissions, built
  only from counts and sums so no referred user's identity leaks
- ReferralsPage renders a stats row and a commission history table
  with the empty-state copy, reversed amounts shown as a deduction
…ering

Adds column-header and zero-reversal assertions to ReferralsPage so the
table's structure and the no-deduction case are pinned, not just the
reversed-amount path.
Commissions are filed under the affiliate's personal organization, but
the earnings queries went through the organization-scoped repository.
With organizations on and a team active, the Referrals page showed no
earnings. The two commission reads now opt out of organization scoping
under a registered "affiliate-earnings" reason and still filter by the
affiliate's own user id.

The paying-referrals count now follows the commission rule: a referred
user counts once their personal organization, or a team they created,
settles a card payment, whichever member paid. A payment for a team
they only joined no longer counts.

Refs CON-1193
@baktun14
baktun14 force-pushed the feat/billing-show-affiliate-earnings branch from b9df7d6 to c508f05 Compare November 11, 2026 04:13
@github-actions github-actions Bot added size: L and removed size: XL labels Nov 11, 2026
@baktun14
baktun14 added this pull request to the merge queue Nov 11, 2026
Merged via the queue into main with commit 19ebbcd Nov 11, 2026
85 checks passed
@baktun14
baktun14 deleted the feat/billing-show-affiliate-earnings branch November 11, 2026 04:30
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