fix(payments): Исправлена ошибка с дублированием скидки для всех платёжных систем

This commit is contained in:
VAQYBIN
2026-01-23 00:00:16 +05:00
parent 1e8b97888a
commit a121d38fbb
7 changed files with 165 additions and 37 deletions
@@ -10,7 +10,6 @@ from bot.middlewares.i18n import JsonI18n
from bot.services.freekassa_service import FreeKassaService
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_freekassa_router")
@@ -70,22 +69,19 @@ async def pay_fk_callback_handler(
)
currency_code = getattr(freekassa_service, "default_currency", None) or 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
)
# Price is already discounted at payments_subscription.py stage
# Service will handle discount metadata if needed
payment_record_payload = {
"user_id": user_id,
"amount": final_price_rub,
"original_amount": price_rub if discount_amount else None,
"discount_applied": discount_amount,
"amount": price_rub,
"original_amount": None,
"discount_applied": None,
"currency": currency_code,
"status": "pending_freekassa",
"description": payment_description,
"subscription_duration_months": int(months),
"provider": "freekassa",
"promo_code_id": promo_code_id,
"promo_code_id": None,
}
try:
@@ -111,13 +107,15 @@ async def pay_fk_callback_handler(
payment_db_id=payment_record.payment_id,
user_id=payment_record.user_id,
months=months,
amount=final_price_rub,
amount=price_rub,
currency=freekassa_service.default_currency,
payment_method_id=freekassa_service.payment_method_id,
ip_address=freekassa_service.server_ip,
extra_params={
"us_method": freekassa_service.payment_method_id,
},
promo_code_service=promo_code_service,
session=session,
)
if success:
@@ -10,7 +10,6 @@ from bot.middlewares.i18n import JsonI18n
from bot.services.platega_service import PlategaService
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_platega_router")
@@ -70,22 +69,19 @@ async def pay_platega_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
)
# Price is already discounted at payments_subscription.py stage
# Service will handle discount metadata if needed
payment_record_payload = {
"user_id": user_id,
"amount": final_price_rub,
"original_amount": price_rub if discount_amount else None,
"discount_applied": discount_amount,
"amount": price_rub,
"original_amount": None,
"discount_applied": None,
"currency": currency_code,
"status": "pending_platega",
"description": payment_description,
"subscription_duration_months": int(months),
"provider": "platega",
"promo_code_id": promo_code_id,
"promo_code_id": None,
}
try:
@@ -120,10 +116,12 @@ async def pay_platega_callback_handler(
payment_db_id=payment_record.payment_id,
user_id=user_id,
months=months,
amount=final_price_rub,
amount=price_rub,
currency=currency_code,
description=payment_description,
payload=payload_meta,
promo_code_service=promo_code_service,
session=session,
)
if success:
@@ -9,7 +9,6 @@ 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")
@@ -69,22 +68,19 @@ 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
)
# Price is already discounted at payments_subscription.py stage
# Service will handle discount metadata if needed
payment_record_payload = {
"user_id": user_id,
"amount": final_price_rub,
"original_amount": price_rub if discount_amount else None,
"discount_applied": discount_amount,
"amount": price_rub,
"original_amount": None,
"discount_applied": None,
"currency": currency_code,
"status": "pending_severpay",
"description": payment_description,
"subscription_duration_months": int(months),
"provider": "severpay",
"promo_code_id": promo_code_id,
"promo_code_id": None,
}
try:
@@ -110,9 +106,11 @@ async def pay_severpay_callback_handler(
payment_db_id=payment_record.payment_id,
user_id=user_id,
months=months,
amount=final_price_rub,
amount=price_rub,
currency=currency_code,
description=payment_description,
promo_code_service=promo_code_service,
session=session,
)
if success: