from aiogram import F, Router from aiogram.fsm.context import FSMContext from aiogram.types import CallbackQuery, Message from bot.keyboards.client import payment_gateways, return_to_menu from bot.states.buy import BillingStorage from bot.states.deposit import DepositStorage from bot.texts import ( CHECKOUT_PAYMENT_CHOICE, DEPOSIT_AMOUNT, DEPOSIT_AMOUNT_BELOW_MINIMAL, DEPOSIT_AMOUNT_FALLBACK, ) from config import settings from schemas.billing import BillingContext from schemas.common import GeneralMessageContext router = Router() @router.callback_query(F.data == "deposit") async def deposit_init(cb: CallbackQuery, state: FSMContext): await state.clear() await cb.message.edit_text(DEPOSIT_AMOUNT, reply_markup=return_to_menu) ctx = GeneralMessageContext(msg=cb.message) await state.set_state(DepositStorage.amount) await state.set_data({"ctx": ctx}) @router.message(DepositStorage.amount) async def deposit_amount(msg: Message, state: FSMContext): data = await state.get_data() await state.clear() await msg.delete() ctx: GeneralMessageContext | None = data.get("ctx") if not isinstance(ctx, GeneralMessageContext) or not msg.text.isdigit(): await msg.answer(DEPOSIT_AMOUNT_FALLBACK, reply_markup=return_to_menu) await state.set_state(DepositStorage.amount) await state.set_data(data) return if int(msg.text) < settings.deposit_threshold: await ctx.msg.edit_text( DEPOSIT_AMOUNT_BELOW_MINIMAL.format(threshold=settings.deposit_threshold), reply_markup=return_to_menu, ) await state.set_state(DepositStorage.amount) await state.set_data(data) return await ctx.msg.edit_text(CHECKOUT_PAYMENT_CHOICE, reply_markup=payment_gateways) await state.set_state(BillingStorage.pending) billing_context = BillingContext(amount=int(msg.text)) await state.set_data({"ctx": billing_context})