2024-10-05 14:35:26 +00:00
|
|
|
from aiogram import Router, types
|
2024-10-06 13:29:07 +00:00
|
|
|
from aiogram.filters import CommandStart, Command
|
|
|
|
from aiogram.types import LabeledPrice, PreCheckoutQuery
|
2024-10-05 14:35:26 +00:00
|
|
|
|
2024-10-06 13:29:07 +00:00
|
|
|
from bot.handlers.user.model_processing import PayCallBack
|
2024-10-05 14:35:26 +00:00
|
|
|
from bot.handlers.user.page_processing import get_page_content
|
|
|
|
from bot.kbs.inline import PageCallBack
|
2024-10-06 13:29:07 +00:00
|
|
|
from config import shop_api_token
|
2024-10-05 14:35:26 +00:00
|
|
|
|
|
|
|
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()
|
2024-10-06 13:29:07 +00:00
|
|
|
|
|
|
|
@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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|