main файл
import asyncio
from aiogram.types import Message, ContentType
from core.handlers.basic import get_start, get_photo, get_hello
from aiogram import Bot, Dispatcher, F
import logging
from core.settings import settings
from aiogram.filters import Command, CommandStart
from core.utils.commands import set_commands
from core.handlers.basic import get_location
from core.handlers.basic import get_inline
from core.handlers.callback import select_macbook
from core.utils.callbackdata import MacInfo
from core.handlers.pay import order, pre_checkout_query, successful_payment
async def start_bot(bot:Bot):
await set_commands(bot)
await bot.send_message(settings.bots.admin_id, text='Бот запущен!')
async def stop_bot(bot:Bot):
await bot.send_message(settings.bots.admin_id, text='Бот остановлен!')
async def start():
logging.basicConfig(level=logging.INFO,
format="%(asctime)s - [%(levelname)s] - %(name)s"
"(%(filename)s).%(funcName)s(%(lineno)d) - %(message)s"
)
bot = Bot(token=settings.bots.bot_token, parse_mode='HTML')
dp = Dispatcher()
dp.startup.register(start_bot)
dp.shutdown.register(stop_bot)
dp.message.register(order, Command(commands='pay'))
dp.pre_checkout_query.register(pre_checkout_query)
dp.message.register(successful_payment, F.ContentType(content_types=[ContentType.SUCCESSFUL_PAYMENT]))
dp.message.register(get_inline, Command(commands='inline'))
dp.callback_query.register(select_macbook, MacInfo.filter())
dp.message.register(get_location, F.location)
dp.message.register(get_photo, F.photo)
dp.message.register(get_hello, F.text == 'Привет')
dp.message.register(get_start, Command(commands=['start', 'run']))
try:
await dp.start_polling(bot)
finally:
await bot.session.close()
if __name__ == "__main__":
asyncio.run(start())
pay файл
from aiogram import Bot
from aiogram.types import Message, LabeledPrice, PreCheckoutQuery
async def order(message: Message, bot: Bot):
await bot.send_invoice(
chat_id=message.chat.id,
title='Покупка подписки',
description='Описание',
payload='Payment throught a bot',
provider_token='381764678:TEST:73747',
currency='rub',
prices=[
LabeledPrice(
label='Доступ к секретной информации',
amount=99000
),
LabeledPrice(
label='НДС',
amount=20000
),
LabeledPrice(
label='Скидка',
amount=-20000
),
LabeledPrice(
label='Бонус',
amount=-40000
)
],
max_tip_amount=5000,
suggested_tip_amounts=[1000, 2000, 3000, 4000],
start_parameter='nztcoder',
provider_data=None,
photo_url=None,
photo_size=100,
photo_width=800,
photo_height=450,
need_name=True,
need_phone_number=True,
need_email=True,
need_shipping_address=False,
send_phone_number_to_provider=False,
send_email_to_provider=False,
is_flexible=False,
disable_notification=False,
protect_content=False,
reply_to_message_id=None,
allow_sending_without_reply=True,
reply_markup=None,
request_timeout=15
)
async def pre_checkout_query(pre_checkout_query: PreCheckoutQuery, bot: Bot):
await bot.answer_pre_checkout_query(pre_checkout_query.id, ok=True)
async def successful_payment(message: Message, bot: Bot):
msg = f'Спасибо за оплату {message.successful_payment.total_amount // 100} {message.successful_payment.currency}.' \
f'\r\nмы получили оплату, vpn скоро будет выслан вам'
await message.answer(msg)
Помогите пожалуйста