feat(billing): Convert referral bonuses from monthly recurring to one-time credits #422
+2,898
−78
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📊 Impact: +71 / -75 lines (excluding tests and autogenerated files)
Summary
This PR changes the referral program from granting recurring monthly credits to one-time bonus credits that never expire. Existing (legacy) recurring referral bonuses are grandfathered and will continue to renew monthly.
Changes
Core Feature
expires_at: nullinstead of the user's next quota reset dateis_legacycolumn: Tracks whether a referral grant is legacy (recurring monthly) or new (one-time)referral_legacygrant type: Separate grant type for grandfathered recurring referrals with priority 30 (consumed first)is_legacycolumn andreferral_legacyenum valueGrant Priority Changes
referral_legacy(priority 30): Consumed first, renews monthly for grandfathered usersreferral(priority 50): One-time bonus, never expires, preserved longerUI Updates
API Changes
/api/referralsnow returnsis_legacyfieldredeemReferralCodecreates grants withtype: 'referral',expiresAt: null,is_legacy: falsecalculateTotalLegacyReferralBonusonly counts referrals whereis_legacy = trueFiles Changed
common/src/types/grant.ts- Addedreferral_legacygrant typecommon/src/constants/grant-priorities.ts- Updated prioritiespackages/billing/src/grant-credits.ts- Usereferral_legacyfor monthly renewalpackages/internal/src/db/schema.ts- Addedis_legacycolumnweb/src/app/api/referrals/helpers.ts- One-time grants with null expiryweb/src/app/api/referrals/route.ts- Addedis_legacyto responseweb/src/app/profile/components/referrals-section.tsx- Badge & label updatesweb/src/app/profile/components/usage-display.tsx- Addedreferral_legacydisplay