feat: add SuperPDP invoice event creation
This commit is contained in:
@@ -462,6 +462,56 @@ class SuperPDPClient:
|
|||||||
|
|
||||||
return self._read_response(response)
|
return self._read_response(response)
|
||||||
|
|
||||||
|
def create_invoice_event(
|
||||||
|
self,
|
||||||
|
access_token: str,
|
||||||
|
*,
|
||||||
|
invoice_id: int,
|
||||||
|
status_code: str,
|
||||||
|
details: dict[str, Any] | None = None,
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""Créer un événement associé à une facture."""
|
||||||
|
|
||||||
|
try:
|
||||||
|
normalized_invoice_id = int(invoice_id)
|
||||||
|
except (TypeError, ValueError) as exc:
|
||||||
|
raise ValueError(
|
||||||
|
"invoice_id doit être un entier valide."
|
||||||
|
) from exc
|
||||||
|
|
||||||
|
if normalized_invoice_id <= 0:
|
||||||
|
raise ValueError(
|
||||||
|
"invoice_id doit être supérieur à zéro."
|
||||||
|
)
|
||||||
|
|
||||||
|
normalized_status_code = str(
|
||||||
|
status_code or ""
|
||||||
|
).strip()
|
||||||
|
|
||||||
|
if not normalized_status_code:
|
||||||
|
raise ValueError(
|
||||||
|
"status_code est obligatoire."
|
||||||
|
)
|
||||||
|
|
||||||
|
payload: dict[str, Any] = {
|
||||||
|
"invoice_id": normalized_invoice_id,
|
||||||
|
"status_code": normalized_status_code,
|
||||||
|
}
|
||||||
|
|
||||||
|
if details is not None:
|
||||||
|
payload["details"] = details
|
||||||
|
|
||||||
|
response = self.session.post(
|
||||||
|
f"{self.base_url}/v1.beta/invoice_events",
|
||||||
|
headers=self._authorization_headers(
|
||||||
|
access_token
|
||||||
|
),
|
||||||
|
json=payload,
|
||||||
|
timeout=self.timeout,
|
||||||
|
)
|
||||||
|
|
||||||
|
return self._read_response(response)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _authorization_headers(
|
def _authorization_headers(
|
||||||
access_token: str,
|
access_token: str,
|
||||||
|
|||||||
@@ -535,6 +535,52 @@ class TestSuperPDPClient(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_invoice_event(self) -> None:
|
||||||
|
response = Mock()
|
||||||
|
response.ok = True
|
||||||
|
response.status_code = 201
|
||||||
|
response.json.return_value = {
|
||||||
|
"id": 42,
|
||||||
|
"invoice_id": 79635,
|
||||||
|
"status_code": "fr:212",
|
||||||
|
}
|
||||||
|
|
||||||
|
self.session.post.return_value = response
|
||||||
|
|
||||||
|
result = self.client.create_invoice_event(
|
||||||
|
"secret-access-token",
|
||||||
|
invoice_id=79635,
|
||||||
|
status_code="fr:212",
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
result["status_code"],
|
||||||
|
"fr:212",
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
result["invoice_id"],
|
||||||
|
79635,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.session.post.assert_called_once_with(
|
||||||
|
(
|
||||||
|
"https://api.superpdp.tech/"
|
||||||
|
"v1.beta/invoice_events"
|
||||||
|
),
|
||||||
|
headers={
|
||||||
|
"Authorization": (
|
||||||
|
"Bearer secret-access-token"
|
||||||
|
),
|
||||||
|
},
|
||||||
|
json={
|
||||||
|
"invoice_id": 79635,
|
||||||
|
"status_code": "fr:212",
|
||||||
|
},
|
||||||
|
timeout=(5, 30),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_list_incoming_invoices_with_expansion(
|
def test_list_incoming_invoices_with_expansion(
|
||||||
self,
|
self,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user