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:
Michilis
2026-11-18 20:58:43 +00:00
co-authored by Claude Opus 5.5
parent 123cede7f3
commit f7ceadc462
30 changed files with 945 additions and 148 deletions
+76 -38
View File
@@ -42,7 +42,7 @@ editMessageCaption
```
<b>Test Video</b>
Sending it to Telegram…
Downloading…
[Cancel]
```
@@ -50,7 +50,7 @@ editMessageCaption
```
<b>Test Video</b>
Downloading…
Sending it to Telegram…
[Cancel]
```
@@ -244,6 +244,12 @@ This content is private or for members only.
[Open app]
```
sendMessage
```
Looking up the link…
```
editMessageText
```
@@ -251,12 +257,6 @@ The site is limiting requests right now. Please try again in a few minutes.
[Try again]
```
sendMessage
```
Looking up the link…
```
editMessageText
```
@@ -360,11 +360,16 @@ editMessageText
```
<b>Invite friends</b>
Share your link. When somebody you invited makes a first purchase, you get 200 sats.
Share your link. When somebody you invited pays for a first purchase in sats (Lightning), you get 200 sats in credits.
https://t.me/nr_dl_test_bot?start=ref_501
https://t.me/nr_dl_test_bot?start=rf_CW5AYJM3
You invited 0 people so far.
Invited: 0 · Bought something: 0
Earned: 0 sats · Waiting: 0 sats
You earn at most 2,000 sats a day. Rewards above that wait for the next day.
[Share] [Copy link]
[QR code]
[Back]
```
@@ -567,11 +572,16 @@ sendMessage
```
<b>Invite friends</b>
Share your link. When somebody you invited makes a first purchase, you get 200 sats.
Share your link. When somebody you invited pays for a first purchase in sats (Lightning), you get 200 sats in credits.
https://t.me/nr_dl_test_bot?start=ref_501
https://t.me/nr_dl_test_bot?start=rf_CW5AYJM3
You invited 0 people so far.
Invited: 0 · Bought something: 0
Earned: 0 sats · Waiting: 0 sats
You earn at most 2,000 sats a day. Rewards above that wait for the next day.
[Share] [Copy link]
[QR code]
```
sendMessage
@@ -859,7 +869,7 @@ sendPhoto
```
<b>Day pass</b> · 700 sats
<code>lnbc7000n1fake9e41f41fd5cc828364d5339ff5a3c5c9cb74029e2a942757aba2c50ecf40f117</code>
<code>lnbc7000n1fake932bb5fc424d32f8967f5a103ec1aa9b323d60cf969ac292033fe465b6058e60</code>
Scan the code or tap the invoice to copy it. Valid for 10 minutes.
[Open in wallet]
@@ -904,7 +914,7 @@ editMessageCaption
```
<b>Test Video</b>
Enviándolo a Telegram…
Descargando…
[Cancelar]
```
@@ -912,7 +922,7 @@ editMessageCaption
```
<b>Test Video</b>
Descargando…
Enviándolo a Telegram…
[Cancelar]
```
@@ -1114,6 +1124,13 @@ Buscando el enlace…
editMessageText
```
El sitio está limitando los pedidos por ahora. Vuelve a intentar en unos minutos.
[Reintentar]
```
editMessageText
```
<b>Test Video</b>
Descargando…
@@ -1128,13 +1145,6 @@ No funcionó. El archivo supera tu límite. Prueba con una calidad más baja.
[Calidad menor] [Mejorar mi plan]
```
editMessageText
```
El sitio está limitando los pedidos por ahora. Vuelve a intentar en unos minutos.
[Reintentar]
```
sendMessage
```
@@ -1222,11 +1232,16 @@ editMessageText
```
<b>Invita a tus amigos</b>
Comparte tu enlace. Cuando alguien que invitaste haga su primera compra, recibes 200 sats.
Comparte tu enlace. Cuando alguien que invitaste pague una primera compra en sats (Lightning), recibes 200 sats en créditos.
https://t.me/nr_dl_test_bot?start=ref_501
https://t.me/nr_dl_test_bot?start=rf_MXZGYTEK
Hasta ahora invitaste a 0 personas.
Invitados: 0 · Compraron algo: 0
Ganado: 0 sats · En espera: 0 sats
Ganas como máximo 2.000 sats al día. Lo que pase de eso espera al día siguiente.
[Compartir] [Copiar enlace]
[Código QR]
[Volver]
```
@@ -1429,11 +1444,16 @@ sendMessage
```
<b>Invita a tus amigos</b>
Comparte tu enlace. Cuando alguien que invitaste haga su primera compra, recibes 200 sats.
Comparte tu enlace. Cuando alguien que invitaste pague una primera compra en sats (Lightning), recibes 200 sats en créditos.
https://t.me/nr_dl_test_bot?start=ref_501
https://t.me/nr_dl_test_bot?start=rf_MXZGYTEK
Hasta ahora invitaste a 0 personas.
Invitados: 0 · Compraron algo: 0
Ganado: 0 sats · En espera: 0 sats
Ganas como máximo 2.000 sats al día. Lo que pase de eso espera al día siguiente.
[Compartir] [Copiar enlace]
[Código QR]
```
sendMessage
@@ -1721,7 +1741,7 @@ sendPhoto
```
<b>Pase de un día</b> · 700 sats
<code>lnbc7000n1fakee5e71ffd20cc9a72502b3121b9023ef84aaacb3bd8df64c5ebdb282615265645</code>
<code>lnbc7000n1fake5bb91054d0d2b0cbcc9f5394928a595cf2ccba08d4a09432f7db5063c88ffd85</code>
Escanea el código o toca la factura para copiarla. Vale por 10 minutos.
[Abrir en la billetera]
@@ -1869,6 +1889,14 @@ Downloaden…
editMessageText
```
<b>Test Video</b>
Naar Telegram sturen…
[Annuleren]
```
editMessageText
```
<b>Test Video</b>
Naar Telegram sturen…
@@ -2076,11 +2104,16 @@ editMessageText
```
<b>Nodig vrienden uit</b>
Deel je link. Als iemand die je uitnodigde voor het eerst iets koopt, krijg jij 200 sats.
Deel je link. Als iemand die je uitnodigde een eerste aankoop in sats (Lightning) betaalt, krijg jij 200 sats aan tegoed.
https://t.me/nr_dl_test_bot?start=ref_501
https://t.me/nr_dl_test_bot?start=rf_4VIFLSDC
Je hebt tot nu toe 0 mensen uitgenodigd.
Uitgenodigd: 0 · Iets gekocht: 0
Verdiend: 0 sats · Wacht nog: 0 sats
Je verdient maximaal 2.000 sats per dag. Wat daarboven komt, wacht tot de volgende dag.
[Delen] [Link kopiëren]
[QR-code]
[Terug]
```
@@ -2283,11 +2316,16 @@ sendMessage
```
<b>Nodig vrienden uit</b>
Deel je link. Als iemand die je uitnodigde voor het eerst iets koopt, krijg jij 200 sats.
Deel je link. Als iemand die je uitnodigde een eerste aankoop in sats (Lightning) betaalt, krijg jij 200 sats aan tegoed.
https://t.me/nr_dl_test_bot?start=ref_501
https://t.me/nr_dl_test_bot?start=rf_4VIFLSDC
Je hebt tot nu toe 0 mensen uitgenodigd.
Uitgenodigd: 0 · Iets gekocht: 0
Verdiend: 0 sats · Wacht nog: 0 sats
Je verdient maximaal 2.000 sats per dag. Wat daarboven komt, wacht tot de volgende dag.
[Delen] [Link kopiëren]
[QR-code]
```
sendMessage
@@ -2575,7 +2613,7 @@ sendPhoto
```
<b>Dagpas</b> · 700 sats
<code>lnbc7000n1fake958d96c95c5e5aca4a2e7070e86b91a77c9f3c2f0701cf5d697aff726aa60632</code>
<code>lnbc7000n1fake2279497394e085369465914011a009430187243aabd22a7b3642440c8ec67831</code>
Scan de code of tik op de factuur om hem te kopiëren. Geldig voor 10 minuten.
[Openen in wallet]