Overview
Telegram Stars (currency codeXTR) is Telegram’s in-app payment system. Humain uses it to sell
two kinds of purchases directly inside Telegram, with no separate checkout page:
- Subscription — a recurring monthly plan (
subscription_periodof 2,592,000 seconds / 30 days). - PAYG (pay-as-you-go) — a one-off credit bundle that adds extra session capacity.
subscription and payg are.
Where the invoice is created
Invoice creation happens in the Mini App /cmd/server, not in the bot itself:
- The Mini App’s
/c/paycompact view (opened via a bot deep link) collects the plan or bundle choice and POSTs{ workspace_id, plan_id | bundle_id }to/api/v1/telegram/stars/invoice. cmd/serververifies the caller’s workspace membership, calls Telegram’screateInvoiceLinkAPI, and returns the resultinginvoice_link.- The Mini App calls
window.Telegram.WebApp.openInvoice(invoice_link, callback), which opens Telegram’s native payment sheet.
user_id,
plan_id or bundle_id, workspace_id, and kind (subscription, product, or payg).
Where the payment is fulfilled
Fulfillment happens in the bot (cmd/telegram), which is the process that receives
Telegram’s payment webhooks:
1
Pre-checkout
Telegram sends a pre-checkout query before charging the user. The bot must answer within 10
seconds — it decodes the invoice payload, verifies
payload.user_id matches the paying
user, and accepts.2
Successful payment
On success, Telegram sends a
successful_payment update. The bot:- Writes a row to
telegram_subscriptions, keyed oncharge_id(unique) so a duplicate webhook delivery is a no-op (ON CONFLICT charge_id DO NOTHING). - For
subscriptionandpaygkinds, calls into billing to assign the plan or add PAYG session credit (extra_seconds) to the workspace.
charge_id — Telegram’s at-least-once delivery for payment updates
cannot double-charge or double-fulfill a purchase.
Data model
telegram_subscriptions stores every Stars purchase:
Testing
Use anhk_test_ sandbox-linked workspace where possible, but note Stars payments always use
real Telegram Stars — there is no sandbox currency for Stars purchases. Test with a small
Stars balance and Telegram’s own refund tools if you need to reverse a test transaction.