Рефактор
Deploy / deploy (push) Successful in 18m5s

This commit is contained in:
Раис Юсупалиев
2026-06-26 19:29:11 +03:00
parent c6c37640fd
commit 843175f12e
36 changed files with 795 additions and 461 deletions
+11 -29
View File
@@ -141,18 +141,11 @@ class OrderRepositoryProtocol(Protocol):
payment_id: int,
) -> object | None: ...
async def mark_cdek_order_registered(
async def mark_provider_order_registered(
self,
session: object,
order_uuid: str,
cdek_order_uuid: str,
) -> object | None: ...
async def mark_cse_order_registered(
self,
session: object,
order_uuid: str,
cse_order_number: str,
provider_order_id: str,
) -> object | None: ...
@@ -357,7 +350,7 @@ class AggregatorService:
error=str(exc),
)
raise InvalidInitPaymentRequestError(
"Payment init request is invalid for CDEK price validation."
"Payment init request is invalid for provider price validation."
) from exc
except ProviderClientError as exc:
logger.warning(
@@ -389,7 +382,7 @@ class AggregatorService:
requested_price_kopecks=requested_price,
)
raise InvalidInitPaymentRequestError(
"CDEK did not return the requested tariff for payment validation."
"Provider did not return the requested tariff for payment validation."
)
expected_amount_kopecks = calculate_expected_payment_amount_kopecks(
@@ -411,7 +404,7 @@ class AggregatorService:
provider_price=str(getattr(provider_price, "price", None)),
)
raise InvalidInitPaymentRequestError(
"Payment amount does not match CDEK validated delivery price."
"Payment amount does not match provider validated delivery price."
)
async def handle_tbank_payment_notification(
@@ -593,11 +586,7 @@ class AggregatorService:
@staticmethod
def _has_existing_registration(order: object, provider: str) -> bool:
if provider == "cdek":
return bool(getattr(order, "cdek_order_uuid", None))
if provider == "cse":
return bool(getattr(order, "cse_order_number", None))
return False
return bool(getattr(order, "provider_order_id", None))
@staticmethod
def _extract_registration_id(result: object) -> str:
@@ -646,18 +635,11 @@ class AggregatorService:
registration_id = self._extract_registration_id(result)
try:
async with self._order_repository.session() as session:
if provider == "cse":
order = await self._order_repository.mark_cse_order_registered(
session,
order_uuid,
registration_id,
)
else:
order = await self._order_repository.mark_cdek_order_registered(
session,
order_uuid,
registration_id,
)
order = await self._order_repository.mark_provider_order_registered(
session,
order_uuid,
registration_id,
)
if order is None:
logger.warning(
"order_registration_order_not_found",
+2 -2
View File
@@ -41,7 +41,7 @@ class EmailSenderProtocol(Protocol):
class OrderRecord(Protocol):
order_uuid: str
account_email: str
cdek_waybill_url: str | None
provider_waybill_url: str | None
class WaybillEmailSenderRepositoryProtocol(Protocol):
@@ -133,7 +133,7 @@ class WaybillEmailSenderService:
continue
async def _handle_order(self, session: object, order: OrderRecord) -> None:
waybill_url = order.cdek_waybill_url
waybill_url = order.provider_waybill_url
if waybill_url is None:
return
+16 -14
View File
@@ -27,8 +27,8 @@ class CDEKWaybillInfoAdapterProtocol(Protocol):
class OrderRecord(Protocol):
order_uuid: str
cdek_order_uuid: str | None
cdek_waybill_uuid: str | None
provider_order_id: str | None
provider_waybill_id: str | None
class WaybillPollerRepositoryProtocol(Protocol):
@@ -97,8 +97,8 @@ class WaybillPollerService:
logger.exception(
"waybill_poll_order_failed",
order_uuid=order.order_uuid,
cdek_order_uuid=order.cdek_order_uuid,
cdek_waybill_uuid=order.cdek_waybill_uuid,
provider_order_id=order.provider_order_id,
provider_waybill_id=order.provider_waybill_id,
)
return PollBatchSummary(
processed=len(orders),
@@ -133,11 +133,11 @@ class WaybillPollerService:
async def _handle_order(self, session: object, order: OrderRecord) -> None:
polled_at = self._datetime_now()
if order.cdek_waybill_uuid is None:
cdek_order_uuid = order.cdek_order_uuid
if cdek_order_uuid is None:
if order.provider_waybill_id is None:
provider_order_id = order.provider_order_id
if provider_order_id is None:
return
info = await self._order_info_adapter.get_order(cdek_order_uuid)
info = await self._order_info_adapter.get_order(provider_order_id)
await self._repository.record_order_poll(
session,
order_uuid=order.order_uuid,
@@ -148,13 +148,15 @@ class WaybillPollerService:
logger.info(
"waybill_poll_order_result",
order_uuid=order.order_uuid,
cdek_order_uuid=cdek_order_uuid,
cdek_order_status=info.status_code,
cdek_waybill_uuid=info.waybill_uuid,
provider_order_id=provider_order_id,
provider_order_status=info.status_code,
provider_waybill_id=info.waybill_uuid,
)
return
waybill = await self._waybill_info_adapter.get_waybill(order.cdek_waybill_uuid)
waybill = await self._waybill_info_adapter.get_waybill(
order.provider_waybill_id
)
await self._repository.record_waybill_poll(
session,
order_uuid=order.order_uuid,
@@ -164,6 +166,6 @@ class WaybillPollerService:
logger.info(
"waybill_poll_waybill_result",
order_uuid=order.order_uuid,
cdek_waybill_uuid=order.cdek_waybill_uuid,
cdek_waybill_url=waybill.url,
provider_waybill_id=order.provider_waybill_id,
provider_waybill_url=waybill.url,
)