feat(promo): Добавлена поддержка промокодов на скидку для всех платёжных систем

This commit is contained in:
VAQYBIN
2026-01-21 01:09:49 +05:00
parent 39d5fd1856
commit 229ce7e1e0
10 changed files with 92 additions and 9 deletions
@@ -9,6 +9,7 @@ from bot.middlewares.i18n import JsonI18n
from bot.services.severpay_service import SeverPayService
from config.settings import Settings
from db.dal import payment_dal
from bot.handlers.user.subscription.payment_discount_helper import apply_discount_to_payment
router = Router(name="user_subscription_payments_severpay_router")
@@ -20,6 +21,7 @@ async def pay_severpay_callback_handler(
i18n_data: dict,
severpay_service: SeverPayService,
session: AsyncSession,
promo_code_service=None,
):
current_lang = i18n_data.get("current_language", settings.DEFAULT_LANGUAGE)
i18n: Optional[JsonI18n] = i18n_data.get("i18n_instance")
@@ -67,14 +69,22 @@ async def pay_severpay_callback_handler(
)
currency_code = settings.DEFAULT_CURRENCY_SYMBOL or "RUB"
# Apply active discount if exists
final_price_rub, discount_amount, promo_code_id = await apply_discount_to_payment(
session, user_id, price_rub, promo_code_service
)
payment_record_payload = {
"user_id": user_id,
"amount": price_rub,
"amount": final_price_rub,
"original_amount": price_rub if discount_amount else None,
"discount_applied": discount_amount,
"currency": currency_code,
"status": "pending_severpay",
"description": payment_description,
"subscription_duration_months": int(months),
"provider": "severpay",
"promo_code_id": promo_code_id,
}
try:
@@ -100,7 +110,7 @@ async def pay_severpay_callback_handler(
payment_db_id=payment_record.payment_id,
user_id=user_id,
months=months,
amount=price_rub,
amount=final_price_rub,
currency=currency_code,
description=payment_description,
)