import logging
from aiogram import Bot, Dispatcher, executor
from aiogram.types.message import ContentType
from telebot import types
import config
logging.basicConfig(level=logging.INFO)
bot = Bot (token=config.TOKEN)
dp = Dispatcher (bot)
PRICE = types. LabeledPrice(label="Подписка на 1 неcяu", amount=588*180)
@dp.message_handler (commands=["buy"])
async def buy(message: types.Message):
if config.RAYMENT_TOKEN.split(":")[1] == "TEST":
await bot.send_message(message.chat.id, "Тестовый платеж")
await bot.send_invoice(message.chat.id,title="Подписка на бота",description= "Активация подписки на бота на 1 месяц",provider_token=config.PAYMENTS_TOKEN,currency="RUB",is_flexible=False,prices=[PRICE],start_parameter="one-month-subscription",payload="test-invoice-payload")
@dp.pre_checkout_query_handler(lambda query: True)
async def pre_checkout_query (pre_checkout_q: types. PreCheckoutQuery):
await bot.answer_pre_checkout_query (pre_checkout_q.id, ok=True)
@dp.message_handler(content_types=ContentType.SUCCESSFUL_PAYMENT)
async def successful_payment (message: types.Message):
print("SUCCESSFUL PAYMENT:")
payment_info = message.successful_payment.to_python()
for k, v in payment_info.items():
print(f"{k} = {v}")
await bot.send_message(message.chat.id,f"Платëж на суMMY {message.successful_payment.total_amount // 100} {message.succesful_paymeyt.currency} прошел успешно!")
if __name__ == "main":
executor.start_polling(dp, skip_updates=False)