invoices, order handling, db updates

This commit is contained in:
2026-02-14 23:09:21 +07:00
parent a3aaafd7ac
commit 50b1a8f80c
28 changed files with 508 additions and 44 deletions

View File

@@ -1,9 +1,13 @@
import logging
from typing import Optional
from aiogram import Router, F
from aiogram.types import CallbackQuery, Message
from aiogram.fsm.context import FSMContext
from sqlalchemy.ext.asyncio import AsyncSession
from config import NOTIFICATION_CHANNEL
from dto.checkout import CheckoutContext
from misc.kb.admins import customer_contacts
from misc.kb.client import (
order_confirmation,
order_specs_confirmation,
@@ -16,6 +20,7 @@ from repositories.orders import OrderRepository
from services.orders import OrderService
router = Router()
logger = logging.getLogger(__name__)
@router.callback_query(F.data == "checkout")
@@ -119,4 +124,55 @@ async def checkout_address(msg: Message, state: FSMContext):
f"<i>📍 Ваш адрес: {ctx.address}</i>\n\n"
"━━━━━━━━━━━━━━",
reply_markup=order_specs_confirmation(ctx.order_id),
) # TODO: State-driven Payment System.
)
await state.set_state(CheckoutStorage.confirmation)
await state.set_data({"ctx": ctx})
@router.callback_query(CheckoutStorage.confirmation)
@router.callback_query(F.data.startswith("payment:"))
async def payment_create(
cb: CallbackQuery,
state: FSMContext,
session: AsyncSession,
order_service: OrderService,
):
data = await state.get_data()
ctx: Optional[CheckoutContext] = data.get("ctx")
if not ctx:
await cb.message.edit_text(
"🍃 Что-то пошло не так, повторите попытку позже...",
reply_markup=return_menu,
)
logger.warning("ctx not found on confirmation screen")
return
await state.clear()
await cb.message.edit_text(
"<b>🟢 Ваш заказ успешно отправлен!</b>\n"
"<i>📦 Мы свяжемся с вами для уточнения деталей в ближайшее время.</i>\n\n"
"<b>‼️ Чтобы убедиться, что вы общаетесь с доверенным контактом ШВЕЙТЕХЦЕНТР, перешлите любое сообщение человека в этот чат.</b>",
reply_markup=return_menu,
)
cart = await order_service.build_full_cart_dto(session, cb.from_user.id)
try:
await cb.bot.send_message(
NOTIFICATION_CHANNEL,
"🟢 Новый заказ.\n\n"
"━━━━━━━━━━━━━━\n\n"
f"<i>👤 Имя: {ctx.name}</i>\n"
f"<i>📱 Номер телефона: {ctx.phone}</i>\n"
f"<i>📍 Адрес: {ctx.address}</i>\n\n"
"━━━━━━━━━━━━━━\n"
f"{get_order_item_list(cart)}",
reply_markup=customer_contacts(
cb.from_user.id, bool(cb.from_user.username), cb.from_user.username
),
)
except Exception as e:
logger.exception(e)
return