Phase 2: money

Lightning payments through LNbits, wallets, passes, credits, the
entitlement resolver and priority lanes.

- internal/entitle: pure resolver (one-off, own pass, group pass, group
  credits, own credits, free) with a table-driven suite and an invariant
  check over every input combination
- internal/billing: wallets, append-only ledger with dedupe keys, stacking
  passes, purchases, gift codes, referral reward
- LNbits client verified against v0.12.12 and v1.7.1 source
- Settlement by one conditional UPDATE: idempotent under any mix of
  webhooks, polls and the check button. Webhooks are unsigned, so every
  payment is confirmed with LNbits before it is credited
- Polling fallback, reconciliation of all unsettled invoices at startup,
  late payments still honored, no expiry while LNbits is unreachable
- Charge, quota and job are written in one transaction; failed, cancelled
  and undeliverable downloads are refunded exactly once
- Paid lane first with one slot of the fleet reserved for free users
- Daily download quota and daily volume cap, per-user and per-group rate
  limits
- Bot: /buy /account /limits /credits /redeem /referral /donate, QR invoice
  message that flips to paid, over-limit offer (passes or this file only),
  deep links from groups, skip the queue
- Fake LNbits server for tests; end-to-end money flows including a payment
  made while the core was down

Cashu redemption is behind an interface and not implemented.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Michilis
2026-11-18 08:09:35 +00:00
co-authored by Claude Fable 5.2
parent 3b361c17a1
commit 0d50f453a0
42 changed files with 7040 additions and 140 deletions
+22
View File
@@ -16,6 +16,11 @@ const (
cbDownload = "dl" // dl:<request id>:<profile>
cbCancelCard = "cx" // cx:<request id>
cbCancelJob = "jc" // jc:<delivery id>
cbSkipQueue = "sq" // sq:<delivery id>
cbBuy = "by" // by:<product>[:<amount>]
cbOfferBuy = "ob" // ob:<product>:<request id>:<profile>
cbPayCheck = "pc" // pc:<purchase id>
cbPayCancel = "px" // px:<purchase id>
)
func cbData(parts ...string) string { return strings.Join(parts, ":") }
@@ -88,3 +93,20 @@ func (b *Bot) cancelJobKeyboard(lang, deliveryID string) *telego.InlineKeyboardM
button(b.tr.T(lang, "btn.cancel", nil), cbData(cbCancelJob, deliveryID)),
})
}
// queuedKeyboard adds "Skip the queue" to the Cancel button of a job that
// waits in the free lane.
func (b *Bot) queuedKeyboard(lang, deliveryID string) *telego.InlineKeyboardMarkup {
skip := b.tr.T(lang, "btn.with_size", i18n.Args{
"Label": b.tr.T(lang, "btn.skip_queue", nil),
"Size": b.tr.Sats(lang, b.cfg.Prices.SkipQueue),
})
return keyboard(
[]telego.InlineKeyboardButton{button(skip, cbData(cbSkipQueue, deliveryID))},
[]telego.InlineKeyboardButton{button(b.tr.T(lang, "btn.cancel", nil), cbData(cbCancelJob, deliveryID))},
)
}
func urlButton(text, url string) telego.InlineKeyboardButton {
return telego.InlineKeyboardButton{Text: text, URL: url}
}