@@ -179,6 +179,7 @@ class CSEClient:
|
||||
"cse_request_server_error",
|
||||
operation=operation,
|
||||
status_code=response.status_code,
|
||||
response_excerpt=_response_excerpt(response.text),
|
||||
)
|
||||
raise CSEClientError(
|
||||
f"CSE {operation} request failed with status "
|
||||
@@ -233,6 +234,10 @@ class CSEClient:
|
||||
return self._retry_backoff_seconds * (2**attempt)
|
||||
|
||||
|
||||
def _response_excerpt(text: str, *, limit: int = 1000) -> str:
|
||||
return " ".join(text.split())[:limit]
|
||||
|
||||
|
||||
class CSEProvider(DeliveryProvider):
|
||||
name = CSE_PROVIDER_NAME
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
"""SOAP (cargo3) Element serialization and parsing for CSE.
|
||||
|
||||
CSE exposes a SOAP/1C web service ("Карго") that transfers data through nested
|
||||
universal ``Element`` structures (``Key``/``Value``/``ValueType``/``Fields``/
|
||||
``List``/``Tables``/``Properties``). This module builds request envelopes and
|
||||
parses responses into a plain Python representation that mappers can navigate.
|
||||
universal ``Element`` structures (``Key``/``Value``/``ValueType``/
|
||||
``Properties``/``Fields``/``List``/``Tables``). This module builds request
|
||||
envelopes and parses responses into a plain Python representation that mappers
|
||||
can navigate.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -15,8 +16,6 @@ from xml.etree import ElementTree as ET
|
||||
CARGO_NS = "http://www.cargo3.ru"
|
||||
SOAP_NS = "http://www.w3.org/2003/05/soap-envelope"
|
||||
|
||||
# Child tags of an Element that hold nested Element lists.
|
||||
_LIST_TAGS = ("Fields", "List", "Tables", "Properties")
|
||||
_SCALAR_TAGS = ("Key", "Value", "ValueType")
|
||||
_BINARY_TAG = "BData"
|
||||
|
||||
@@ -102,14 +101,14 @@ def _append_element(parent: ET.Element, tag: str, element: Element) -> None:
|
||||
_scalar(node, "Value", element.value)
|
||||
if element.value_type is not None:
|
||||
_scalar(node, "ValueType", element.value_type)
|
||||
for child in element.properties:
|
||||
_append_element(node, "Properties", child)
|
||||
for child in element.fields:
|
||||
_append_element(node, "Fields", child)
|
||||
for child in element.items:
|
||||
_append_element(node, "List", child)
|
||||
for child in element.tables:
|
||||
_append_element(node, "Tables", child)
|
||||
for child in element.properties:
|
||||
_append_element(node, "Properties", child)
|
||||
|
||||
|
||||
def _scalar(parent: ET.Element, tag: str, text: str) -> None:
|
||||
|
||||
@@ -5,7 +5,7 @@ from enum import Enum
|
||||
|
||||
class TBankPaymentNotificationAction(str, Enum):
|
||||
ACKNOWLEDGE_ONLY = "acknowledge_only"
|
||||
REGISTER_CDEK_ORDER = "register_cdek_order"
|
||||
REGISTER_PROVIDER_ORDER = "register_provider_order"
|
||||
|
||||
|
||||
def resolve_tbank_payment_notification_action(
|
||||
@@ -15,7 +15,7 @@ def resolve_tbank_payment_notification_action(
|
||||
error_code: str,
|
||||
) -> TBankPaymentNotificationAction:
|
||||
if status == "CONFIRMED" and success is True and error_code == "0":
|
||||
return TBankPaymentNotificationAction.REGISTER_CDEK_ORDER
|
||||
return TBankPaymentNotificationAction.REGISTER_PROVIDER_ORDER
|
||||
return TBankPaymentNotificationAction.ACKNOWLEDGE_ONLY
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user