Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from telegram import LabeledPrice, Update #надеюсь те импорти CallbackContext filters
- from .import database
- from telegram.ext import CommandHandler, CallbackQueryHandler, MessageHandler, ContextTypes, PreCheckoutQueryHandler, filters, ContextTypes
- from main import logger
- async def send_invoice(query, context: ContextTypes.DEFAULT_TYPE, meetings, price) -> None:
- title = f"{meetings} встреч"
- chat_id = query.message.chat.id
- description = f"Оплата за {meetings} встреч"
- # payload = f"purchase_{meetings}_{price}"
- payload = f'{meetings}'
- PAYMENT_PROVIDER_TOKEN = '381764678:TEST:76547' # Replace with your actual payment provider token
- start_parameter = 'time-slot-purchase'
- currency = 'RUB'
- prices = [LabeledPrice(title, int(price) * 100)] # Price in kopecks
- # await context.bot.send_invoice(
- # chat_id=query.message.chat.id,
- # title=title,
- # description=description,
- # payload=payload,
- # provider_token=provider_token,
- # start_parameter=start_parameter,
- # currency=currency,
- # prices=prices
- # )
- await context.bot.send_invoice(
- chat_id, title, description, payload, PAYMENT_PROVIDER_TOKEN, currency, prices
- )
- async def precheckout_callback(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
- query = update.pre_checkout_query
- try:
- await context.bot.answer_pre_checkout_query(pre_checkout_query_id=query.id, ok=True)
- print('precheckout_callback')
- except Exception as e:
- print(f"Ошибка при обработке pre_checkout_query: {e}")
- async def process_payment(query, meetings, price, context):
- await send_invoice(query, context, meetings, price)
- async def successful_payment_callback(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
- await update.message.reply_text("Thank you for your payment!")
- def register_handlers(application):
- application.add_handler(CommandHandler("start", start))
- application.add_handler(CallbackQueryHandler(utils.button_handler))
- application.add_handler(CommandHandler("staff", staff_command))
- application.add_handler(MessageHandler(None, utils.change_text))
- application.add_handler(CommandHandler('buy', shop.send_invoice))
- application.add_handler(PreCheckoutQueryHandler(shop.precheckout_callback))
- application.add_handler(MessageHandler(filters.SUCCESSFUL_PAYMENT, shop.successful_payment_callback))
- loop = asyncio.get_event_loop()
- loop.create_task(utils.notify_restart(application))
- utils.load_welcome_text()
- application.run_polling(allowed_updates=Update.ALL_TYPES)
Advertisement
Add Comment
Please, Sign In to add comment