hokage_Rost

Untitled

Jan 28th, 2024
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.71 KB | None | 0 0
  1. from telegram import LabeledPrice, Update #надеюсь те импорти CallbackContext filters
  2. from .import database
  3. from telegram.ext import CommandHandler, CallbackQueryHandler, MessageHandler, ContextTypes, PreCheckoutQueryHandler, filters, ContextTypes
  4. from main import logger
  5.  
  6.  
  7.  
  8.  
  9. async def send_invoice(query, context: ContextTypes.DEFAULT_TYPE, meetings, price) -> None:
  10.     title = f"{meetings} встреч"
  11.     chat_id = query.message.chat.id
  12.     description = f"Оплата за {meetings} встреч"
  13.     # payload = f"purchase_{meetings}_{price}"
  14.     payload = f'{meetings}'
  15.     PAYMENT_PROVIDER_TOKEN = '381764678:TEST:76547'  # Replace with your actual payment provider token
  16.     start_parameter = 'time-slot-purchase'
  17.     currency = 'RUB'
  18.     prices = [LabeledPrice(title, int(price) * 100)]  # Price in kopecks
  19.  
  20.     # await context.bot.send_invoice(
  21.     #     chat_id=query.message.chat.id,
  22.     #     title=title,
  23.     #     description=description,
  24.     #     payload=payload,
  25.     #     provider_token=provider_token,
  26.     #     start_parameter=start_parameter,
  27.     #     currency=currency,
  28.     #     prices=prices
  29.     # )
  30.     await context.bot.send_invoice(
  31.         chat_id, title, description, payload, PAYMENT_PROVIDER_TOKEN, currency, prices
  32.     )
  33.  
  34.  
  35. async def precheckout_callback(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
  36.     query = update.pre_checkout_query
  37.     try:
  38.         await context.bot.answer_pre_checkout_query(pre_checkout_query_id=query.id, ok=True)
  39.         print('precheckout_callback')
  40.     except Exception as e:
  41.         print(f"Ошибка при обработке pre_checkout_query: {e}")
  42.  
  43.  
  44.  
  45. async def process_payment(query, meetings, price, context):
  46.     await send_invoice(query, context, meetings, price)
  47.    
  48.  
  49.  
  50. async def successful_payment_callback(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
  51.     await update.message.reply_text("Thank you for your payment!")
  52.    
  53.  
  54. def register_handlers(application):
  55.     application.add_handler(CommandHandler("start", start))
  56.     application.add_handler(CallbackQueryHandler(utils.button_handler))
  57.     application.add_handler(CommandHandler("staff", staff_command))
  58.     application.add_handler(MessageHandler(None, utils.change_text))
  59.     application.add_handler(CommandHandler('buy', shop.send_invoice))
  60.     application.add_handler(PreCheckoutQueryHandler(shop.precheckout_callback))
  61.     application.add_handler(MessageHandler(filters.SUCCESSFUL_PAYMENT, shop.successful_payment_callback))
  62.  
  63.    
  64.     loop = asyncio.get_event_loop()
  65.     loop.create_task(utils.notify_restart(application))
  66.     utils.load_welcome_text()
  67.  
  68.     application.run_polling(allowed_updates=Update.ALL_TYPES)
Advertisement
Add Comment
Please, Sign In to add comment