-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(analytics): Add overdue balance endpoint
- Loading branch information
Showing
9 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from typing import List, Optional | ||
|
||
from ..base_model import BaseModel, BaseResponseModel | ||
|
||
|
||
class OverdueBalanceResponse(BaseResponseModel): | ||
amount_cents: int | ||
currency: str | ||
month: str | ||
lago_invoice_ids: List[str] | ||
|
||
|
||
class OverdueBalancesResponse(BaseResponseModel): | ||
__root__: List[OverdueBalanceResponse] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import sys | ||
from typing import Any, ClassVar, Type, Union | ||
|
||
from ..base_client import BaseClient | ||
from ..mixins import FindAllCommandMixin | ||
from ..models.overdue_balance import OverdueBalanceResponse | ||
from ..services.request import make_headers, make_url, send_get_request | ||
from ..services.response import get_response_data, prepare_index_response, Response | ||
|
||
if sys.version_info >= (3, 9): | ||
from collections.abc import Mapping | ||
else: | ||
from typing import Mapping | ||
|
||
|
||
class OverdueBalanceClient( | ||
FindAllCommandMixin[OverdueBalanceResponse], | ||
BaseClient, | ||
): | ||
API_RESOURCE: ClassVar[str] = 'overdue_balances' | ||
RESPONSE_MODEL: ClassVar[Type[OverdueBalanceResponse]] = OverdueBalanceResponse | ||
ROOT_NAME: ClassVar[str] = 'overdue_balance' | ||
|
||
def find_all(self, options: Mapping[str, Union[int, str]] = {}) -> Mapping[str, Any]: | ||
api_response: Response = send_get_request( | ||
url=make_url( | ||
origin=self.base_url, | ||
path_parts=('analytics', 'overdue_balance'), | ||
query_pairs=options, | ||
), | ||
headers=make_headers(api_key=self.api_key), | ||
) | ||
|
||
# Process response data | ||
return prepare_index_response( | ||
api_resource=self.API_RESOURCE, | ||
response_model=self.RESPONSE_MODEL, | ||
data=get_response_data(response=api_response), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"overdue_balances": [ | ||
{ | ||
"month": "2023-11-01T00:00:00.000Z", | ||
"amount_cents": 100, | ||
"currency": "EUR", | ||
"lago_invoice_ids": ["1a901a90-1a90-1a90-1a90-1a901a901a90"] | ||
}, | ||
{ | ||
"month": "2023-12-01T00:00:00.000Z", | ||
"amount_cents": 200, | ||
"currency": "USD", | ||
"lago_invoice_ids": ["1a901a90-1a90-1a90-1a90-1a901a901a90"] | ||
} | ||
], | ||
"meta": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import os | ||
|
||
import pytest | ||
from pytest_httpx import HTTPXMock | ||
|
||
from lago_python_client.client import Client | ||
from lago_python_client.exceptions import LagoApiError | ||
from lago_python_client.models.overdue_balance import OverdueBalanceResponse | ||
|
||
|
||
def mock_collection_response(): | ||
current_dir = os.path.dirname(os.path.abspath(__file__)) | ||
data_path = os.path.join(current_dir, 'fixtures/overdue_balance_index.json') | ||
|
||
with open(data_path, 'rb') as overdue_balances_response: | ||
return overdue_balances_response.read() | ||
|
||
|
||
def test_valid_find_all_overdue_balances_request(httpx_mock: HTTPXMock): | ||
client = Client(api_key='886fe239-927d-4072-ab72-6dd345e8dd0d') | ||
|
||
httpx_mock.add_response(method='GET', url='https://api.getlago.com/api/v1/analytics/overdue_balance', content=mock_collection_response()) | ||
response = client.overdue_balances.find_all() | ||
|
||
assert response['overdue_balances'][0].currency == 'EUR' | ||
assert response['overdue_balances'][0].amount_cents == 100 | ||
assert response['overdue_balances'][0].month == '2023-11-01T00:00:00.000Z' | ||
assert response['overdue_balances'][0].lago_invoice_ids == ['1a901a90-1a90-1a90-1a90-1a901a901a90'] |