fix: test command
This commit is contained in:
@@ -4,9 +4,11 @@ from decimal import Decimal
|
||||
from typing import Any
|
||||
from ulid import ULID
|
||||
import aiohttp
|
||||
import orjson
|
||||
from aiohttp import BasicAuth, ClientTimeout
|
||||
from src.application.contracts import IReceipt
|
||||
from src.application.domain.exceptions import ApplicationException
|
||||
from src.infrastructure.cloud_kassir.constants import CLOUD_KASSIR_API_BASE_URL
|
||||
|
||||
|
||||
class ClaudeKassirClient(IReceipt):
|
||||
@@ -16,7 +18,7 @@ class ClaudeKassirClient(IReceipt):
|
||||
public_id: str,
|
||||
api_secret: str,
|
||||
inn: str,
|
||||
api_base_url: str = 'https://api.cloudpayments.ru',
|
||||
api_base_url: str = CLOUD_KASSIR_API_BASE_URL,
|
||||
success_url: str | None = None,
|
||||
fail_url: str | None = None,
|
||||
timeout_seconds: float = 30,
|
||||
@@ -118,9 +120,28 @@ class ClaudeKassirClient(IReceipt):
|
||||
async with aiohttp.ClientSession(timeout=self._timeout) as session:
|
||||
auth = BasicAuth(self._public_id, self._api_secret)
|
||||
async with session.post(url, json=payload, headers=headers, auth=auth) as resp:
|
||||
body = await resp.json(content_type=None)
|
||||
raw = (await resp.text()).strip()
|
||||
if not raw:
|
||||
raise ApplicationException(
|
||||
status_code=502,
|
||||
message=f'Receipt provider empty response (HTTP {resp.status})',
|
||||
)
|
||||
try:
|
||||
parsed: Any = orjson.loads(raw)
|
||||
except orjson.JSONDecodeError:
|
||||
preview = raw[:240].replace('\n', ' ')
|
||||
raise ApplicationException(
|
||||
status_code=502,
|
||||
message=f'Receipt provider non-JSON response (HTTP {resp.status}): {preview}',
|
||||
)
|
||||
if not isinstance(parsed, dict):
|
||||
raise ApplicationException(status_code=502, message='Receipt provider invalid response')
|
||||
body = parsed
|
||||
if resp.status >= 400:
|
||||
raise ApplicationException(status_code=502, message='Receipt provider error')
|
||||
raise ApplicationException(
|
||||
status_code=502,
|
||||
message=str(body.get('Message') or 'Receipt provider error'),
|
||||
)
|
||||
if body.get('Success') is False:
|
||||
raise ApplicationException(status_code=409, message=str(body.get('Message') or 'Receipt provider rejected receipt'))
|
||||
return body
|
||||
|
||||
Reference in New Issue
Block a user