Skip to content

Commit

Permalink
feature(anrok): add error details to invoice response (#260)
Browse files Browse the repository at this point in the history
* add error_details to invoice and retry endpoint on invoice

* use post method instead of put for retry invoice

* remove not used type

* fix ruff
  • Loading branch information
annvelents authored Sep 10, 2024
1 parent cae8551 commit 7fea97c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lago_python_client/invoices/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ def refresh(self, resource_id: str) -> InvoiceResponse:
data=get_response_data(response=api_response, key=self.ROOT_NAME),
)

def retry(self, resource_id: str) -> InvoiceResponse:
api_response: Response = send_post_request(
url=make_url(
origin=self.base_url,
path_parts=(self.API_RESOURCE, resource_id, "retry"),
),
headers=make_headers(api_key=self.api_key),
)

return prepare_object_response(
response_model=self.RESPONSE_MODEL,
data=get_response_data(response=api_response, key=self.ROOT_NAME),
)

def finalize(self, resource_id: str) -> InvoiceResponse:
api_response: Response = send_put_request(
url=make_url(
Expand Down
15 changes: 15 additions & 0 deletions lago_python_client/models/error_detail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from typing import Any, Dict, List, Optional

from lago_python_client.base_model import BaseModel

from ..base_model import BaseResponseModel


class ErrorDetailResponse(BaseModel):
organization_id: str
error_code: str
details: Optional[Dict[str, Any]]


class ErrorDetailsResponse(BaseResponseModel):
__root__: List[ErrorDetailResponse]
3 changes: 3 additions & 0 deletions lago_python_client/models/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .customer import CustomerResponse
from .fee import FeesResponse
from .subscription import SubscriptionsResponse
from .error_detail import ErrorDetailsResponse
from ..base_model import BaseResponseModel
from .usage_threshold import UsageThreshold

Expand Down Expand Up @@ -47,6 +48,7 @@ class OneOffInvoice(BaseModel):
external_customer_id: Optional[str]
currency: Optional[str]
fees: Optional[InvoiceFeesList]
error_details: Optional[ErrorDetailsResponse]


class InvoiceAppliedTax(BaseResponseModel):
Expand Down Expand Up @@ -109,3 +111,4 @@ class InvoiceResponse(BaseResponseModel):
metadata: Optional[InvoiceMetadataList]
applied_taxes: Optional[InvoiceAppliedTaxes]
applied_usage_thresholds: Optional[InvoiceAppliedUsageThresholds]
error_details: Optional[ErrorDetailsResponse]
13 changes: 13 additions & 0 deletions tests/test_invoice_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,19 @@ def test_valid_refresh_invoice_request(httpx_mock: HTTPXMock):
assert response.lago_id == "5eb02857-a71e-4ea2-bcf9-57d3a41bc6ba"


def test_valid_retry_invoice_request(httpx_mock: HTTPXMock):
client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d")

httpx_mock.add_response(
method="POST",
url="https://api.getlago.com/api/v1/invoices/5eb02857-a71e-4ea2-bcf9-57d3a41bc6ba/retry",
content=mock_response(),
)
response = client.invoices.retry("5eb02857-a71e-4ea2-bcf9-57d3a41bc6ba")

assert response.lago_id == "5eb02857-a71e-4ea2-bcf9-57d3a41bc6ba"


def test_valid_lose_dispute_invoice_request(httpx_mock: HTTPXMock):
client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d")

Expand Down

0 comments on commit 7fea97c

Please sign in to comment.