Practitionist / Practitionist/elluminar_web
Referral & affiliate programs (ledger-backed rewards)
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1
- Forks
- 0
- Avg merge
- 17h 2m
- Merged PRs (30d)
- 18
Description
Why / Context
PRD §7.2E / §8.6: referral (learner→learner) and affiliate (creator→creator) programs are core growth levers for V1. Marketplace network effects (teardown §5.3 BUILD-EXTRA: "every new creator brings learners who discover other creators") get a direct accelerant when both sides are incentivized to recruit.
Schema already in place — NO migration required
ReferralCode(owner user OR tenant OR platform, kind LEARNER/CREATOR/AFFILIATE,rewardConfig Json, expiry)Referral(referredUser unique, status PENDING→QUALIFIED→REWARDED,rewardLedgerEntryId,firstOrderId)LedgerAccount(ownerType: USER)+LedgerEntry(entryType: REFERRAL_REWARD)— user-owned reward balancesCoupon.campaignfor coupon-based reward variants
Implementation plan
- Reward config contract (Zod):
{ referrerReward: {type: 'CREDIT'|'COUPON', amountMinor|couponSpec}, refereeReward: {...}, qualifyingEvent: 'FIRST_PAID_ORDER'|'SIGNUP', minOrderMinor }. - Code issuance: auto-generate a LEARNER code per user on first login (vanity edit allowed); creator/affiliate codes issued from studio/admin.
- Attribution:
?ref=CODE→ cookie (90d) →Referral(PENDING)on signup; last-touch wins; self-referral blocked. - Qualification worker: on first PAID order above
minOrderMinor, mark QUALIFIED → apply rewards: referrerLedgerEntry(REFERRAL_REWARD)on their USER ledger account (or coupon), referee coupon at checkout. - Redemption of user credit at checkout: apply USER ledger balance as a payment-side discount line (cap per order via PlatformConfig).
- Affiliate variant: tenant-owned codes reward the tenant ledger account; affiliate dashboard (clicks → signups → qualified → earnings) in studio.
- Fraud guards: same-device/email-domain heuristics, reward clawback path (ADJUSTMENT entries) on refund of qualifying order.
- Surfaces: /account/referrals (share links, status), post-purchase share prompt, creator "invite a creator" page.
Acceptance criteria
- Referred signup + first qualifying purchase → both-side rewards exactly once (idempotent under webhook replay)
- Refunding the qualifying order claws back the reward via ledger reversal
- User credit balance spendable at checkout with cap enforced
- Affiliate tenant earnings appear in the payout pipeline like sale earnings
- Self-referral and duplicate-device attempts rejected
Dependencies / sequencing
- MVP M7 (checkout/ledger) required; payout automation (issue #14) pays affiliate balances out
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with MVP M7 checkout/ledger and the existing ReferralCode, Referral, LedgerAccount, LedgerEntry, and Coupon schema described here. Trace the qualification worker, first paid-order and refund paths, checkout credit redemption, /account/referrals, studio/admin issuance, and the payout pipeline. Done means rewards are idempotent, refunds reverse them, caps and fraud guards work, and affiliate earnings reach payouts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend, database, full-stack, payments
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100