Phase 4: Telegram Stars payments
- Stars as a second payment method for passes and credit packs, next to Lightning (STARS_ENABLED, prices in [stars_prices] / STARS_PRICES, set on their own). Invoices in XTR with no provider token and one price; pre-checkout checks payer, state, currency and amount; successful_payment settles through the same transaction as Lightning, so entitlement is identical. Idempotent by telegram_payment_charge_id (unique index). - Migration 00009: payment_method on purchases and ledger entries, plus stars_amount, tg_charge_id and refunded_at on purchases. Stars purchases never reach LNbits. - Chat: buy screen, /credits, /account and the over-limit offer show Lightning first and a Pay with Stars button. - Mini App: Lightning and Stars switch on Buy; Stars use createInvoiceLink and WebApp.openInvoice, confirmed by the server-side payment event. - Owner /refund <purchase or charge ID> calls refundStarPayment and takes back the credits or pass; refunded_payment messages do the same once. /stats shows revenue by payment method. - The sats referral reward counts Lightning purchases only. - The bot now asks Telegram for pre_checkout_query updates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
f7ceadc462
commit
2b5625e9d4
@@ -393,3 +393,35 @@ func TestReferralRewardNames(t *testing.T) {
|
||||
t.Fatal("a negative cap was accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStarsPrices(t *testing.T) {
|
||||
cfg := Default()
|
||||
if n, ok := cfg.StarsPrice("pass_week", 0); !ok || n != 200 {
|
||||
t.Fatalf("default pass_week = %d %v", n, ok)
|
||||
}
|
||||
if n, ok := cfg.StarsPrice("credits", 5000); !ok || n != 330 {
|
||||
t.Fatalf("default 5000 credits = %d %v", n, ok)
|
||||
}
|
||||
if _, ok := cfg.StarsPrice("credits", 1234); ok {
|
||||
t.Fatal("a pack without a Stars price is sold for Stars")
|
||||
}
|
||||
if _, ok := cfg.StarsPrice("one_off", 0); ok {
|
||||
t.Fatal("one-off payments are not sold for Stars")
|
||||
}
|
||||
m, err := ParseStarsPrices(" pass_day=25, credits_1000=60 ")
|
||||
if err != nil || m["pass_day"] != 25 || m["credits_1000"] != 60 || len(m) != 2 {
|
||||
t.Fatalf("ParseStarsPrices = %v, %v", m, err)
|
||||
}
|
||||
if _, err := ParseStarsPrices("pass_day=lots"); err == nil {
|
||||
t.Fatal("a bad price was accepted")
|
||||
}
|
||||
cfg.Telegram.Token = "x"
|
||||
cfg.StarsPrices = map[string]int64{"pass_year": 5}
|
||||
if err := cfg.Validate(); err == nil || !strings.Contains(err.Error(), "pass_year") {
|
||||
t.Fatalf("unknown product: %v", err)
|
||||
}
|
||||
cfg.StarsPrices = map[string]int64{"pass_day": 0}
|
||||
if err := cfg.Validate(); err == nil {
|
||||
t.Fatal("a price of 0 Stars was accepted")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user