Skip to content

feat: add referral program with commission structure and fraud detection - #124

Merged
heymariam merged 2 commits into
Dorisio:mainfrom
kingsmart-sketch:feature/referral-program
Oct 8, 2026
Merged

heymariam merged 2 commits into
Dorisio:mainfrom
kingsmart-sketch:feature/referral-program

Conversation

@kingsmart-sketch

Copy link
Copy Markdown
Contributor

**feat: refer

Summary

Implements a complete word-of-mouth referral system
code, share it, and earn commissions when referred users
commission tiers and manage

What

Schema & migration

  • Added `ReferralT
  • Added relations on User (refer
  • Migration: 20260927180000_add_referral_program

Referral service

  • Unique 8-char URL-
  • Idempotent `get
  • `
    code
    abused
  • `processCommissionFor
    converted on first
  • `pay
  • `getAf

Routes (src/domains/referrals/referral.routes.ts)

┌────────┬───────────────────────────┬──────┐
│ Method │ Path │ Auth │
├────────┼───────────────────────────┼──────┤
│ GET │ /api/v1/referrals/my-code │ User │
└────────┴───────────────────────────┴──────┘
│ GET │ /api/v1/referrals/my-code │ User │
├────────┼─────────────────────────────┼──────┤
│ GET │ /api/v1/referrals/dashboard │ User │
├────────┼─────────────────────────────┼──────┤
│ POST │ /api/v1/referrals/payout │ User │
└────────┴─────────────────────────────┴──────┘
|
| POST | /api/v1/admin | POST | /api/v1/admin/referrals/:referralId/flag
| POST
│ GET │ /api/v1/referrals/code/:code │ Public │
├──────────────┼────────────────────────────────────────────────┼────────┤
│ GET/POST │ /api/v1/admin/referrals/tiers │ Admin │
├──────────────┼────────────────────────────────────────────────┼────────┤
│ PATCH/DELETE │ /api/v1/admin/referrals/tiers/:tierId │ Admin │
├──────────────┼────────────────────────────────────────────────┼────────┤
│ POST │ /api/v1/admin/referrals/codes/:codeId/lock │ Admin │
├──────────────┼────────────────────────────────────────────────┼────────┤
│ POST │ /api/v1/admin/referrals/:referralId/flag-fraud │ Admin │
├──────────────┼────────────────────────────────────────────────┼────────┤
│ POST │ /api/v1/admin/referrals/codes/:codeId/tier │ Admin │
└──────────────┴────────────────────────────────────────────────┴────────┘

**Integration

  • Commission
    PaymentService.updateTipStatus
    tip
  • `

Tests (src/domains/referrals/tests/referral.service.test.ts)

  • Full coverage of all service methods with an in
  • Fraud guard scenarios: self-referral, duplicate, locked code, depth limit, velocity lock
  • Commission id
  • Dashboard aggregation, tier

Testing

pnpm run test:
pnpm run type-check # zero type errors
p
p

Notes

  • No live database was available
    prisma generate and the migration SQL
    existing migrations
  • Commission failures are intent
    confirmed

▸ Credits: 0.30 • Time: 12s
⠀ Thinking... (esc to cancel)

closes #67

- Add ReferralTier, ReferralCode, Referral, ReferralCommission Prisma models
- Add migration SQL (20260927180000_add_referral_program)
- Implement ReferralService: code generation, referral tracking, commission
  calculation, payout, fraud detection (self-referral, duplicate, depth,
  velocity, locked-code guards), tier CRUD, affiliate dashboard
- Add referral routes: GET my-code, GET dashboard, POST payout,
  GET code/:code (public), admin tier/code/fraud management endpoints
- Hook commission processing into payment.service updateTipStatus on
  tip confirmation (non-blocking, errors logged)
- Register referral routes in bootstrap()
- Add POST /api/v1/referrals/payout to sensitive rate-limit class
- Add comprehensive unit tests for all service methods
@heymariam

Copy link
Copy Markdown
Contributor

@kingsmart-sketch well done and thanks for contributing, resolve the conflicts so we can check and merge

@heymariam
heymariam merged commit d8d47f4 into Dorisio:main Oct 8, 2026
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.

Affiliate/Referral Program System

2 participants