- Added billing models and repository for handling bills. - Introduced BillingService to manage payment initiation and bill creation. - Updated user service to remove ticket-related functionality. - Refactored settings to include new billing-related fields. - Removed ticket-related handlers and schemas. - Added new billing handlers for processing payments. - Updated database schema with new bills table and status enum. - Enhanced utility functions to calculate prices considering discounts. - Introduced prehandling for non-private messages. - Updated main application to initialize new billing services and repositories.
48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
import logging
|
|
|
|
from aiogram import F, Router
|
|
from aiogram.fsm.context import FSMContext
|
|
from aiogram.types import CallbackQuery
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from keyboards.client import pay_url, return_to_menu
|
|
from schemas.billing import BillingContext, BillingProviders
|
|
from schemas.di import DependenciesDTO
|
|
from states.buy import BillingStorage
|
|
from texts import BILL_CREATED, BILL_CREATION, CALLBACK_FALLBACK
|
|
|
|
router = Router()
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@router.callback_query(BillingStorage.pending, F.data == "billing:pally")
|
|
async def pally_init(
|
|
cb: CallbackQuery, state: FSMContext, session: AsyncSession, deps: DependenciesDTO
|
|
):
|
|
data = await state.get_data()
|
|
ctx: BillingContext | None = data.get("ctx")
|
|
if not ctx:
|
|
logger.warning("ctx not found on billing choice")
|
|
await cb.message.edit_text(CALLBACK_FALLBACK, reply_markup=return_to_menu)
|
|
return
|
|
|
|
await state.clear()
|
|
|
|
ctx.provider = BillingProviders.PALLY
|
|
|
|
await cb.message.edit_text(BILL_CREATION.format(amount=ctx.amount, provider=ctx.provider.value.title()))
|
|
|
|
bill = await deps.billing_service.pally_initiate_payment(
|
|
session, deps.pally_client, user_id=cb.from_user.id, amount=ctx.amount
|
|
)
|
|
|
|
if not bill:
|
|
await cb.message.edit_text(CALLBACK_FALLBACK, reply_markup=return_to_menu)
|
|
logger.critical("bill creation prompted, but bill is None")
|
|
return
|
|
|
|
await cb.message.edit_text(
|
|
BILL_CREATED.format(amount=ctx.amount, provider=ctx.provider.value.title()),
|
|
reply_markup=pay_url(bill.link_page_url),
|
|
)
|