Appearance
Referrals
Base /v1. Every person is credited to at most one referrer or affiliate, forever (growth_attributions, keyed by the person). An affiliate code or link wins over a user referral code when both arrive together. Nobody can be credited to themselves. Web links are SHARE_BASE_URL/r/<code>, deep links plemuz://r/<code>.
Flow
- The web page or app opening a link calls
POST /referrals/clicksand keeps the returnedclickToken. - Straight after sign-up/sign-in the app calls
POST /me/attributionwith the code and/or click token it holds (withinREFERRAL_CLAIM_WINDOW_DAYSof joining). - When the referred person's first paid (non-trial) charge settles, a reward row is written and
referral.reward_earnedis emitted; identity's own consumer credits subscription days through the rewards port (REFERRAL_REWARD_REFERRER_DAYS,REFERRAL_REWARD_REFERRED_DAYS). Rewards are time, never money.
Fraud checks: at attribution, referrer inactive, either-way block, or a shared device → REFERRAL_NOT_ELIGIBLE. At reward time the same checks plus "paid by the referrer" and a shared payment-method fingerprint mark the reward blocked (silently).
Endpoints
| Method | Path | Auth | Body / query | Response | Errors |
|---|---|---|---|---|---|
| GET | /me/referral | user | – | { code, webUrl, deepLink, qrPath, rewardDays: { referrer, referred } } | USER_NOT_FOUND |
| GET | /me/referrals | user | – | { code, total, stats: { invited, signedUp, subscribed, rewardDaysEarned }, recent: [{ joinedAt, isVerified, hasSubscribed }] } | USER_NOT_FOUND |
| POST | /me/referral | user | { code } | { status: "ok" } (legacy, code only) | as below |
| POST | /me/attribution | user | { referralCode?, affiliateCode?, clickToken?, source?: code|link|qr|deep_link } (at least one of the first three) | 201 { kind: referral|affiliate, source, attributedAt } | REFERRAL_ALREADY_SET 409, REFERRAL_WINDOW_CLOSED 422, REFERRAL_CODE_INVALID 422, REFERRAL_CLICK_INVALID 422, REFERRAL_NOT_ELIGIBLE 422 |
| GET | /me/attribution | user | – | the view above, or null | – |
| POST | /referrals/clicks | public (30/min/IP) | { code, channel?: link|qr|deep_link, deviceKey? } | 201 { clickToken | null, expiresAt | null, deepLink } (null token for bots) | REFERRAL_CODE_INVALID |
| GET | /referrals/:code/qr.svg | public, cacheable | – | image/svg+xml QR of the web link | VALIDATION_FAILED |
Click tokens look like r_<uuid>.<secret> (user referral) or a_<uuid>.<secret> (affiliate); only the secret's hash is stored.
Events
| Type | When | Payload |
|---|---|---|
identity.user.referred | user referral recorded (existing) | { userId, referrerUserId } |
identity.user.attributed | any attribution recorded | { userId, kind, source, referrerUserId, affiliateId, affiliateLinkId, affiliateClickId, attributedAt } |
referral.reward_earned | referred person's first paid charge, not blocked | { rewardId, referrerUserId, referredUserId, paymentId, referrerDays, referredDays, earnedAt } |
Notifications: referral.joined, referral.reward_earned.