Phase 3: own referral system (sats)
- Referral links carry a random 8 character base32 code (rf_<code>) built from the bot username from getMe. Old ref_<id> links still work but are never shown. - The reward (REFERRAL_REWARD_SATS, old name REFERRAL_REWARD still read) is paid through the ledger once the invited user's first purchase settles, once per invited user, never for self-referrals. - REFERRAL_DAILY_CAP limits what an inviter earns per UTC day; rewards above it wait as pending and are paid on a later day by the billing loop. - /referral shows invited, converted, earned and pending, with Share, Copy link and QR code buttons. The Mini App Me page mirrors it. - Migration 00008: users.ref_code (unique) and referral_rewards, backfilled from earlier referral credits in the ledger. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
123cede7f3
commit
f7ceadc462
@@ -370,3 +370,26 @@ func TestWorkerConfig(t *testing.T) {
|
||||
t.Fatalf("worker env not applied: %+v", w)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReferralRewardNames(t *testing.T) {
|
||||
t.Setenv("BOT_TOKEN", "x")
|
||||
t.Setenv("DLBOT_CONFIG", "")
|
||||
t.Chdir(t.TempDir())
|
||||
t.Setenv("REFERRAL_REWARD", "150")
|
||||
cfg, err := Load("")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if cfg.Prices.ReferralReward != 150 || cfg.ReferralDailyCap != 2000 {
|
||||
t.Fatalf("old name: reward %d, cap %d", cfg.Prices.ReferralReward, cfg.ReferralDailyCap)
|
||||
}
|
||||
t.Setenv("REFERRAL_REWARD_SATS", "300")
|
||||
t.Setenv("REFERRAL_DAILY_CAP", "0")
|
||||
if cfg, err = Load(""); err != nil || cfg.Prices.ReferralReward != 300 || cfg.ReferralDailyCap != 0 {
|
||||
t.Fatalf("new name: %+v %v", cfg.Prices.ReferralReward, err)
|
||||
}
|
||||
t.Setenv("REFERRAL_DAILY_CAP", "-5")
|
||||
if _, err := Load(""); err == nil {
|
||||
t.Fatal("a negative cap was accepted")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user