Payments API: Credit Cards & Telegram Stars in Bot Workflows
Step 094: Payments API: Credit Cards & Telegram Stars in Bot Workflows
Executive Overview: Monetizing Telegram automated ecosystems requires navigating two distinct transaction paradigms: native Telegram Stars (XTR) for Apple & Google IAP-compliant digital goods, and direct credit card gateways (Stripe, Smart Glocal) with 0% platform commission for physical e-commerce. In Telegram 194, we construct an end-to-end production payment pipeline: executing sendInvoice, enforcing the critical 10-second pre_checkout_query verification timeout, validating cryptographically sealed receipts via successful_payment, handling automated refunds, and routing digital revenue to TON via Fragment.
1. The 3-Step Payment Authorization Handshake
The Telegram Payments API enforces a strict three-stage cryptographic protocol to guarantee transactional integrity and prevent inventory race conditions:
Invoice Dispatch
Your bot calls sendInvoice with a title, description, price breakdown array (LabeledPrice), currency, and a custom payload string (e.g. your database internal order ID).
10-Second Authorization Window
When the user taps "Pay", Telegram sends a pre_checkout_query update. Your bot has exactly 10 seconds to verify inventory and respond with answerPreCheckoutQuery(ok=True).
Receipt & Fulfillment
Once the user's payment clears, Telegram delivers a message containing the successful_payment object with a unique charge ID. Your backend unlocks access and fulfills the order.
2. Dual Monetization: Telegram Stars (XTR) vs. Physical Goods
Telegram strictly separates digital virtual goods from physical merchandise to maintain compliance with mobile app store guidelines:
Mandatory for Virtual Items & Subscriptions
- Applies to e-books, online courses, digital software, gaming assets, and VIP channel subscriptions.
- Set
currency = "XTR"and leaveprovider_token = ""empty. - Users purchase Stars in-app via Apple Pay, Google Pay, or Fragment.
- Developers cash out accumulated Stars to TON cryptocurrency on Fragment after 21 days.
Credit Cards (Stripe / Smart Glocal)
- Applies exclusively to physical merchandise, apparel, hardware, and offline delivery services.
- Obtain a merchant token from
@BotFather(e.g. Stripe live token). - Supports flexible shipping queries (
sendShippingQuery) to calculate dynamic courier rates. - 0% Telegram fee: Telegram takes no commission on physical e-commerce transactions.
3. Complete Python Implementation: Stars Invoicing & Pre-Checkout
Below is an asynchronous PTB v20 implementation demonstrating invoice generation, pre-checkout validation, and receipt processing:
Payments API Invoice & Stars Checkout Simulator
Invoice Configuration
6. Monetization Comparison: Stars vs. Stripe vs. TON Connect vs. Traditional IAP
| Payment System | Target Goods | Store Policy Status | Conversion Fee | Settlement Asset |
|---|---|---|---|---|
| Telegram Stars (XTR) | Digital / Virtual Only | 100% Compliant (Apple/Google) | Standard IAP split | TON Cryptocurrency |
| Credit Cards (Stripe) | Physical Goods Only | 100% Compliant | 0% Telegram Fee (2.9% Stripe) | Fiat Bank Transfer (USD/EUR) |
| TON Connect 2.0 | Web3 / Decentralized | External Web3 Wallet | 0% (Only ~$0.005 network gas) | Native TON / USDT-TON |
| Legacy Native IAP | Digital In-App Only | Heavy App Store Lock-in | 30% Platform Cut | Fiat Payout (60-day delay) |
Step 094 Visual Recap: Telegram Payments & Stars Checkout Blueprint
Four-tier in-app monetization architecture: sendInvoice dispatch, dual checkout modal (Stars vs. Credit Card), strict 10-second pre-checkout validation, and Fragment TON cashout pipeline.