Fix ETTN creation on live Checkbox

- prepayment as DISCOUNT: live API rejects PRE_PAYMENT with 400 third_party.generic
- normalize lowercase ETTN statuses returned by the live API
- show Checkbox error code instead of bare 'Internal Server Error'
- page size 50 for ETTN list, 429 rate limit is retryable, pause polling on it
- phone in 380XXXXXXXXX format like portal receipts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-24 13:49:50 +03:00
co-authored by Claude Opus 5.5
parent 912a37c00c
commit 3a6ad85d11
7 changed files with 73 additions and 26 deletions
+10 -3
View File
@@ -23,8 +23,9 @@ from app.services.checkbox.client import (
_PROVIDER = "novapost"
_TIMEOUT = httpx.Timeout(30, connect=10)
# Сколько страниц списка ЕТТН просматривать при сверке после таймаута.
_FIND_PAGES = 5
_FIND_PAGE_SIZE = 100
# Список отдаётся от новых к старым; больше 50 за страницу Checkbox не принимает.
_FIND_PAGES = 3
_FIND_PAGE_SIZE = 50
def _error_message(response: httpx.Response) -> str:
@@ -35,6 +36,11 @@ def _error_message(response: httpx.Response) -> str:
if isinstance(data, dict):
message = data.get("message")
detail = data.get("detail")
# Ошибки со стороны Новой Почты Checkbox отдаёт как
# {"code": "third_party.*", "message": "Internal Server Error"} —
# без кода кассир видит только бесполезное «Internal Server Error».
if code := data.get("code"):
message = f"{message or 'Ошибка'} ({code})"
if isinstance(detail, list) and detail:
parts = [
f"{'.'.join(str(p) for p in item.get('loc', []))}: {item.get('msg')}"
@@ -74,7 +80,8 @@ class HttpCheckboxClient:
)
except httpx.HTTPError as exc:
raise CheckboxUnavailableError(f"Checkbox недоступен: {exc!r}") from exc
if response.status_code >= 500:
# 429 — «Занадто часто виконуються запити»: исход не ошибка данных, повторяемо.
if response.status_code >= 500 or response.status_code == 429:
raise CheckboxUnavailableError(_error_message(response))
return response