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
@@ -302,6 +302,8 @@ func updateChatID(u telego.Update) int64 {
|
||||
return u.CallbackQuery.From.ID
|
||||
case u.MyChatMember != nil:
|
||||
return u.MyChatMember.Chat.ID
|
||||
case u.PreCheckoutQuery != nil:
|
||||
return u.PreCheckoutQuery.From.ID
|
||||
case u.WidgetQuery != nil:
|
||||
if u.WidgetQuery.Chat != nil {
|
||||
return u.WidgetQuery.Chat.ID
|
||||
@@ -332,6 +334,8 @@ func (b *Bot) HandleUpdate(ctx context.Context, u telego.Update) {
|
||||
b.handleMyChatMember(ctx, u.MyChatMember)
|
||||
case u.WidgetQuery != nil:
|
||||
b.handleWidgetQuery(ctx, u.WidgetQuery)
|
||||
case u.PreCheckoutQuery != nil:
|
||||
b.handlePreCheckout(ctx, u.PreCheckoutQuery)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,6 +351,8 @@ func updateUser(u telego.Update) (*telego.User, *telego.Chat) {
|
||||
return &u.CallbackQuery.From, &chat
|
||||
}
|
||||
return &u.CallbackQuery.From, nil
|
||||
case u.PreCheckoutQuery != nil:
|
||||
return &u.PreCheckoutQuery.From, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
@@ -361,6 +367,8 @@ func updateType(u telego.Update) string {
|
||||
return "my_chat_member"
|
||||
case u.WidgetQuery != nil:
|
||||
return "widget_query"
|
||||
case u.PreCheckoutQuery != nil:
|
||||
return "pre_checkout_query"
|
||||
}
|
||||
return "other"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user