Advertisement
Guest User

telegram stars using example

a guest
Jun 9th, 2024
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. from aiogram import Router, F, Bot
  2. from aiogram.filters import Command
  3. from aiogram.types import Message, PreCheckoutQuery
  4.  
  5.    
  6. router = Router()
  7.  
  8.  
  9. @router.message(Command('start'))
  10. async def create_invoice(msg: Message):
  11.     await msg.answer_invoice(
  12.         title="Title",
  13.         description="Description",
  14.         payload="payload",
  15.         currency="XTR",  # XTR only, don't change
  16.         prices=[
  17.             LabeledPrice(label="label", amount=5),  # 5 telegram stars
  18.         ],
  19.     )
  20.    
  21.    
  22. @router.pre_checkout_query()
  23. async def checkout_handler(checkout_query: PreCheckoutQuery):
  24.     await checkout_query.answer(ok=True)
  25.  
  26.  
  27. @router.message(F.successful_payment)
  28. async def star_payment(msg: Message, bot: Bot):
  29.     await bot.refund_star_payment(  # for testing auto-recovery of funds
  30.         msg.chat.id,
  31.         msg.successful_payment.telegram_payment_charge_id,
  32.     )
  33.     # What actions, such as:
  34.     # - adding a transaction to the database
  35.     # - opening access to paid functions
  36.     await msg.answer(f"Your transaction id: {msg.successful_payment.telegram_payment_charge_id}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement