Skip to content

Commit

Permalink
add error_details to invoice and retry endpoint on invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
annvelents committed Aug 22, 2024
1 parent bf34230 commit 4ca368b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lago_python_client/invoices/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ 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_put_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, Union

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


Expand Down Expand Up @@ -46,6 +47,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 @@ -95,3 +97,4 @@ class InvoiceResponse(BaseResponseModel):
credits: Optional[CreditsResponse]
metadata: Optional[InvoiceMetadataList]
applied_taxes: Optional[InvoiceAppliedTaxes]
error_details: Optional[ErrorDetailsResponse]
19 changes: 19 additions & 0 deletions tests/test_invoice_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ def test_valid_find_invoice_request(httpx_mock: HTTPXMock):
assert response.lago_id == identifier


def test_valid_find_invoice_request_with_error_details(httpx_mock: HTTPXMock):
client = Client(api_key='886fe239-927d-4072-ab72-6dd345e8dd0d')
identifier = '5eb02857-a71e-4ea2-bcf9-57d3a41bc6ba'

httpx_mock.add_response(method='GET', url='https://api.getlago.com/api/v1/invoices/' + identifier, content=mock_response())
response = client.invoices.find(identifier)

assert response.lago_id == identifier


def test_invalid_find_invoice_request(httpx_mock: HTTPXMock):
client = Client(api_key='invalid')
identifier = '5eb02857-a71e-4ea2-bcf9-57d3a41bc6ba'
Expand Down Expand Up @@ -151,6 +161,15 @@ 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='PUT', 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 4ca368b

Please sign in to comment.