This commit is contained in:
+18
-12
@@ -30,6 +30,7 @@ from app.adapters.tbank.base import (
|
||||
from app.domain.payment_notifications import (
|
||||
TBankPaymentNotificationAction,
|
||||
resolve_tbank_payment_notification_action,
|
||||
should_apply_tbank_payment_status,
|
||||
)
|
||||
from app.domain.price import (
|
||||
DEFAULT_PROVIDER_PRICE_MULTIPLIER,
|
||||
@@ -537,9 +538,12 @@ class AggregatorService:
|
||||
|
||||
try:
|
||||
async with self._order_repository.session() as session:
|
||||
# FOR UPDATE: сериализуем конкурентные уведомления по одному заказу,
|
||||
# чтобы внеочередной статус не затирал уже записанный (lost update).
|
||||
order = await self._order_repository.get_order_by_order_uuid(
|
||||
session,
|
||||
notification.OrderId,
|
||||
for_update=True,
|
||||
)
|
||||
if order is None:
|
||||
logger.warning(
|
||||
@@ -549,19 +553,21 @@ class AggregatorService:
|
||||
raise TBankPaymentNotificationProcessingError(
|
||||
"Order was not found for TBank payment notification."
|
||||
)
|
||||
updated_order = await self._order_repository.mark_payment_status(
|
||||
session,
|
||||
notification.OrderId,
|
||||
notification.Status,
|
||||
notification.PaymentId,
|
||||
)
|
||||
if updated_order is None:
|
||||
logger.warning(
|
||||
"tbank_payment_notification_order_not_found",
|
||||
order_uuid=notification.OrderId,
|
||||
if should_apply_tbank_payment_status(
|
||||
order.payment_status, notification.Status
|
||||
):
|
||||
await self._order_repository.mark_payment_status(
|
||||
session,
|
||||
notification.OrderId,
|
||||
notification.Status,
|
||||
notification.PaymentId,
|
||||
)
|
||||
raise TBankPaymentNotificationProcessingError(
|
||||
"Order was not found for TBank payment notification."
|
||||
else:
|
||||
logger.info(
|
||||
"tbank_payment_status_downgrade_skipped",
|
||||
order_uuid=notification.OrderId,
|
||||
current_status=order.payment_status,
|
||||
incoming_status=notification.Status,
|
||||
)
|
||||
return order
|
||||
except TBankPaymentNotificationProcessingError:
|
||||
|
||||
Reference in New Issue
Block a user