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:
Michilis
2026-11-18 21:20:03 +00:00
co-authored by Claude Opus 5.5
parent f7ceadc462
commit 2b5625e9d4
37 changed files with 1915 additions and 114 deletions
+43 -1
View File
@@ -156,6 +156,9 @@ pick = "Pick a format:"
cancelled = "Cancelled."
[btn]
pay_lightning = "⚡ Pay with Lightning"
pay_stars = "⭐ Pay with Stars"
with_stars = "{{.Label}} · ⭐ {{.Stars}}"
qr = "QR code"
copy_link = "Copy link"
share = "Share"
@@ -440,6 +443,10 @@ Page {{.Page}} of {{.Pages}}. Tap one to see it and get it again."""
# --- Owner commands ---------------------------------------------------------
[owner]
revenue_title = "<b>Revenue</b>"
stars_refunded = "Refunded {{.Amount}} to user {{.User}} for purchase <code>{{.ID}}</code>. What it granted was taken back."
stars_refund_failed = "Telegram refused the refund: {{.Reason}}"
stars_not_refundable = "This Stars purchase cannot be refunded (status: {{.Status}})."
books_ok = "ledger and balances agree"
ln_ok = "reachable"
ln_down = "NOT reachable"
@@ -480,7 +487,11 @@ Create a gift code:
gift_code = "Gift code: <code>{{.Code}}</code>\nUses: {{.Uses}}"
granted = "Done. The pass of {{.ID}} runs until {{.Until}}."
credit_usage = "Example: <code>/credit 123456789 500</code>"
refund_usage = "Examples:\n<code>/refund 123456789 500</code>\n<code>/refund 123456789 pass 24h</code>"
refund_usage = """
Examples:
<code>/refund 123456789 500</code>
<code>/refund 123456789 pass 24h</code>
<code>/refund PURCHASE_ID</code> returns a Stars payment"""
no_pass = "That wallet has no active pass to extend."
credited = "Done. {{.Amount}} added to {{.ID}}. Balance: {{.Balance}}."
blocklist_empty = "The blocklist is empty."
@@ -756,6 +767,8 @@ cancel_confirm = "Cancel \"{{.Title}}\"?"
cancelled = "Cancelled."
[app.buy]
method_stars = "Telegram Stars ⭐"
method_lightning = "Lightning ⚡"
unavailable = "Payments are not set up on this bot."
step = "Step {{.Step}} of {{.Total}}"
target_title = "Who is it for?"
@@ -780,6 +793,9 @@ at_once = "At the same time"
none = "No limit"
[app.invoice]
refunded = "Refunded"
stars_pay = "Open the payment again"
stars_waiting = "Waiting for Telegram to confirm the payment…"
qr_alt = "Lightning invoice as a QR code"
copy = "Copy invoice"
waiting = "Waiting for payment · {{.Time}}"
@@ -917,3 +933,29 @@ Share your link. When somebody you invited pays for a first purchase in sats (Li
Invited: {{.Invited}} · Bought something: {{.Converted}}
Earned: {{.Earned}} · Waiting: {{.Pending}}"""
[unit.stars]
one = "{{.N}} Star"
other = "{{.N}} Stars"
[stars]
refunded = "Your payment for {{.Title}} was refunded: {{.Amount}} went back to your Telegram balance."
payment_problem = "Your payment arrived, but I could not match it to an order. The bot owner can see it and will sort it out."
precheck_closed = "This invoice is closed. Please start the purchase again."
precheck_failed = "This invoice does not match your order. Please start the purchase again."
invoice_description = "{{.Title}} for The Noderunners Download Bot, yours as soon as the payment arrives."
credits_title = "{{.Amount}} in credits"
offer = """
<b>Pay with Telegram Stars</b>
A pass covers this download. It starts as soon as the payment arrives."""
intro = """
<b>Pay with Telegram Stars</b>
The same passes and credits, paid from your Stars balance in Telegram."""
[owner.revenue_lightning]
one = "Lightning: {{.Amount}} from {{.Count}} purchase"
other = "Lightning: {{.Amount}} from {{.Count}} purchases"
[owner.revenue_stars]
one = "Stars: {{.Amount}} from {{.Count}} purchase, {{.Refunded}} refunded"
other = "Stars: {{.Amount}} from {{.Count}} purchases, {{.Refunded}} refunded"