from aiogram import Router, types from aiogram.filters import CommandStart, Command from aiogram.types import LabeledPrice, PreCheckoutQuery from bot.handlers.user.model_processing import PayCallBack from bot.handlers.user.page_processing import get_page_content from bot.kbs.inline import PageCallBack from config import shop_api_token user = Router() @user.message(CommandStart()) async def start(message: types.Message): text, reply_markup = await get_page_content(page=0,name="main") await message.answer(text, reply_markup=reply_markup) @user.callback_query(PageCallBack.filter()) async def user_pages(callback: types.CallbackQuery, callback_data: PageCallBack): text, reply_markup = await get_page_content( page=callback_data.page, name=callback_data.page_name, ) await callback.message.edit_text(text, reply_markup=reply_markup) await callback.answer() @user.callback_query(PayCallBack.filter()) async def buy(callback: types.CallbackQuery, callback_data: PayCallBack): await callback.message.bot.send_invoice( chat_id=callback.from_user.id, description=f'{callback_data.tokens} токенов за {callback_data.amount} RUB для модели {callback_data.name}', title=f'{callback_data.option_of_model} подписка на {callback_data.name}', payload=f'sub_{callback_data.name}', provider_token=shop_api_token, start_parameter='test', currency="RUB", prices=[LabeledPrice( label=f'Оплата токенов для {callback_data.option_of_model}', amount=int(callback_data.amount)*100, )], ) @user.pre_checkout_query() async def procces_pre_checkout_query(pre_checkout_query: PreCheckoutQuery): await pre_checkout_query.answer(ok=True)