invoice payment! prerelease
This commit is contained in:
@@ -137,6 +137,7 @@ async def payment_create(
|
||||
state: FSMContext,
|
||||
session: AsyncSession,
|
||||
order_service: OrderService,
|
||||
order_repo: OrderRepository,
|
||||
):
|
||||
data = await state.get_data()
|
||||
ctx: Optional[CheckoutContext] = data.get("ctx")
|
||||
@@ -150,16 +151,15 @@ async def payment_create(
|
||||
|
||||
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.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)
|
||||
await cb.bot.send_message(
|
||||
NOTIFICATION_CHANNEL,
|
||||
"🟢 Новый заказ.\n\n"
|
||||
@@ -173,6 +173,11 @@ async def payment_create(
|
||||
cb.from_user.id, bool(cb.from_user.username), cb.from_user.username
|
||||
),
|
||||
)
|
||||
await order_repo.remove_order_by_customer(session, cb.from_user.id)
|
||||
except Exception as e:
|
||||
await cb.message.edit_text(
|
||||
"🍃 Что-то пошло не так, повторите попытку позже...",
|
||||
reply_markup=return_menu,
|
||||
)
|
||||
logger.exception(e)
|
||||
return
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
import logging
|
||||
|
||||
from aiogram import Router
|
||||
from aiogram import Router, F
|
||||
from aiogram.filters import CommandObject, CommandStart
|
||||
from aiogram.fsm.context import FSMContext
|
||||
from aiogram.types import (
|
||||
CallbackQuery,
|
||||
Message,
|
||||
)
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from db.models.invoices import InvoiceStatus
|
||||
from misc.kb.admins import verify_payment
|
||||
from misc.kb.client import confirm_payment, return_menu
|
||||
from repositories.invoices import InvoiceRepository
|
||||
from config import card_info
|
||||
|
||||
router = Router()
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -24,6 +30,86 @@ async def activate_invoice(
|
||||
|
||||
invoice_id = int(payload.split(":")[1])
|
||||
invoice = await invoice_repo.get_invoice_by_id(session, invoice_id)
|
||||
|
||||
if not invoice:
|
||||
await msg.answer(
|
||||
"⏳ Счёт истёк. Повторите попытку позже.", reply_markup=return_menu
|
||||
)
|
||||
return
|
||||
|
||||
if invoice.status != InvoiceStatus.PENDING:
|
||||
await msg.answer("⏳ Этот счёт недоступен.", reply_markup=return_menu)
|
||||
return
|
||||
|
||||
if not (card_info.number and card_info.holder):
|
||||
await msg.answer(
|
||||
"🍃 Оплата недоступна, повторите попытку позже.", reply_markup=return_menu
|
||||
)
|
||||
return
|
||||
|
||||
await msg.answer(
|
||||
f"<b>🟢 Получен счёт на {invoice.amount}₽</b>"
|
||||
) # TODO: Process payment
|
||||
f"<b>💎 Счёт на {invoice.amount}₽</b>\n\n"
|
||||
"<i>🔸 Проведите оплату по реквизитам ниже:</i>\n"
|
||||
f"🪪 Номер карты: <code>{card_info.number}</code>\n"
|
||||
f"👤 Держатель карты: <b>{card_info.holder}</b>",
|
||||
reply_markup=confirm_payment(invoice_id),
|
||||
)
|
||||
|
||||
|
||||
@router.callback_query(F.data.startswith("refresh_payment:"))
|
||||
async def refresh_payment(
|
||||
cb: CallbackQuery,
|
||||
state: FSMContext,
|
||||
session: AsyncSession,
|
||||
invoice_repo: InvoiceRepository,
|
||||
):
|
||||
await state.clear()
|
||||
|
||||
invoice_id = int(cb.data.split(":")[1])
|
||||
invoice = await invoice_repo.get_invoice_by_id(session, invoice_id)
|
||||
|
||||
if not invoice:
|
||||
await cb.message.edit_text("🍃 Оплата недоступна.")
|
||||
return
|
||||
|
||||
await cb.message.edit_reply_markup()
|
||||
await cb.message.reply(
|
||||
"<b>💸 Вы отметили платёж как оплаченый.</b> Если вы сделали это ошибочно, проведите платёж в ближайшее время.",
|
||||
reply_markup=return_menu,
|
||||
)
|
||||
|
||||
await invoice_repo.update_invoice_status(
|
||||
session, invoice_id=invoice.id, status=InvoiceStatus.PAID
|
||||
)
|
||||
|
||||
await cb.bot.edit_message_text(
|
||||
inline_message_id=invoice.inline_message_id,
|
||||
text="<b><i>🟡 Счёт помечен как оплаченый, жду подтверждения...</i></b>",
|
||||
reply_markup=verify_payment(invoice.id),
|
||||
)
|
||||
|
||||
|
||||
@router.callback_query(F.data.startswith("verify_payment:"))
|
||||
async def verify_payment_cb(
|
||||
cb: CallbackQuery,
|
||||
state: FSMContext,
|
||||
session: AsyncSession,
|
||||
invoice_repo: InvoiceRepository,
|
||||
):
|
||||
await state.clear()
|
||||
|
||||
invoice_id = int(cb.data.split(":")[1])
|
||||
invoice = await invoice_repo.get_invoice_by_id(session, invoice_id)
|
||||
|
||||
if cb.from_user.id != invoice.creator_id:
|
||||
await cb.answer("❌ Подтвердить может только создатель счёта")
|
||||
return
|
||||
|
||||
await invoice_repo.update_invoice_status(
|
||||
session, invoice_id=invoice_id, status=InvoiceStatus.RECEIVED
|
||||
)
|
||||
|
||||
await cb.bot.edit_message_text(
|
||||
inline_message_id=invoice.inline_message_id,
|
||||
text=f"<b>✅ Платёж на {invoice.amount}₽ успешно оплачен.</b>",
|
||||
)
|
||||
|
||||
@@ -37,6 +37,11 @@ async def main_menu_cb(
|
||||
):
|
||||
await state.clear()
|
||||
|
||||
try:
|
||||
await cb.message.reply_to_message.delete()
|
||||
except Exception:
|
||||
...
|
||||
|
||||
cart_items = await order_items_repo.get_items_count_by_customer(
|
||||
session, cb.from_user.id
|
||||
)
|
||||
|
||||
@@ -146,7 +146,7 @@ async def add_to_cart(
|
||||
else:
|
||||
show_cart = False
|
||||
quantity = 0
|
||||
await order_service.clear_cart_item(
|
||||
await order_service.clear_from_cart(
|
||||
session, customer=cb.from_user.id, product_id=product_id
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user