Skip to content

Commit 0db91dd

Browse files
authored
feat(payment-receipts): Add payment receipts (#304)
1 parent a2a9df8 commit 0db91dd

File tree

8 files changed

+149
-0
lines changed

8 files changed

+149
-0
lines changed

lago_python_client/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from .mrrs.clients import MrrClient
1515
from .organizations.clients import OrganizationClient
1616
from .overdue_balances.clients import OverdueBalanceClient
17+
from .payment_receipts.clients import PaymentReceiptClient
1718
from .payment_requests.clients import PaymentRequestClient
1819
from .payments.clients import PaymentClient
1920
from .invoice_collections.clients import InvoiceCollectionClient
@@ -115,6 +116,10 @@ def organizations(self) -> OrganizationClient:
115116
def overdue_balances(self) -> OverdueBalanceClient:
116117
return OverdueBalanceClient(self.base_api_url, self.api_key)
117118

119+
@callable_cached_property
120+
def payment_receipts(self) -> PaymentReceiptClient:
121+
return PaymentReceiptClient(self.base_api_url, self.api_key)
122+
118123
@callable_cached_property
119124
def payment_requests(self) -> PaymentRequestClient:
120125
return PaymentRequestClient(self.base_api_url, self.api_key)

lago_python_client/models/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@
9090
UsageThresholds as UsageThresholds,
9191
UsageThresholdsResponse as UsageThresholdsResponse,
9292
)
93+
from .payment_receipt import (
94+
PaymentReceiptResponse as PaymentReceiptResponse,
95+
PaymentReceiptsResponse as PaymentReceiptsResponse,
96+
)
9397
from .payment_request import PaymentRequest as PaymentRequest
9498
from .payment import Payment as Payment
9599
from .lifetime_usage import LifetimeUsageResponse as LifetimeUsageResponse
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from typing import List
2+
3+
from ..base_model import BaseResponseModel
4+
from .payment import PaymentResponse
5+
6+
7+
class PaymentReceiptResponse(BaseResponseModel):
8+
lago_id: str
9+
number: str
10+
payment: PaymentResponse
11+
created_at: str
12+
13+
14+
class PaymentReceiptsResponse(BaseResponseModel):
15+
__root__: List[PaymentReceiptResponse]

lago_python_client/payment_receipts/__init__.py

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from typing import ClassVar, Type
2+
3+
from ..base_client import BaseClient
4+
from ..mixins import FindAllCommandMixin, FindCommandMixin
5+
from ..models.payment_receipt import PaymentReceiptResponse
6+
7+
8+
class PaymentReceiptClient(
9+
FindAllCommandMixin[PaymentReceiptResponse],
10+
FindCommandMixin[PaymentReceiptResponse],
11+
BaseClient,
12+
):
13+
API_RESOURCE: ClassVar[str] = "payment_receipts"
14+
RESPONSE_MODEL: ClassVar[Type[PaymentReceiptResponse]] = PaymentReceiptResponse
15+
ROOT_NAME: ClassVar[str] = "payment_receipt"

tests/fixtures/payment_receipt.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"payment_receipt": {
3+
"lago_id": "89b6b61e-4dbc-4307-ac96-4abcfa9e3e2d",
4+
"number": "LAG-1234-001-002",
5+
"created_at": "2024-06-30T10:59:51Z",
6+
"payment": {
7+
"lago_id": "8e5d5ec2-bdc7-4c43-a944-5ababae775d4",
8+
"invoice_ids": [
9+
"ed267c66-8170-4d23-83e8-6d6e4fc735ef"
10+
],
11+
"amount_cents": 100,
12+
"amount_currency": "USD",
13+
"payment_status": "succeeded",
14+
"type": "manual",
15+
"reference": "the reference",
16+
"external_payment_id": null,
17+
"created_at": "2025-02-18T18:31:13Z"
18+
}
19+
}
20+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"payment_receipts": [
3+
{
4+
"lago_id": "89b6b61e-4dbc-4307-ac96-4abcfa9e3e2d",
5+
"number": "LAG-1234-001-002",
6+
"created_at": "2024-06-30T10:59:51Z",
7+
"payment": {
8+
"lago_id": "8e5d5ec2-bdc7-4c43-a944-5ababae775d4",
9+
"invoice_ids": [
10+
"ed267c66-8170-4d23-83e8-6d6e4fc735ef"
11+
],
12+
"amount_cents": 100,
13+
"amount_currency": "USD",
14+
"payment_status": "succeeded",
15+
"type": "manual",
16+
"reference": "the reference",
17+
"external_payment_id": null,
18+
"created_at": "2025-02-18T18:31:13Z"
19+
}
20+
}
21+
],
22+
"meta": {
23+
"current_page": 1
24+
}
25+
}

tests/test_payment_receipt_client.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import os
2+
3+
import pytest
4+
from pytest_httpx import HTTPXMock
5+
6+
from lago_python_client.client import Client
7+
from lago_python_client.exceptions import LagoApiError
8+
9+
10+
def mock_response():
11+
this_dir = os.path.dirname(os.path.abspath(__file__))
12+
data_path = os.path.join(this_dir, "fixtures/payment_receipt.json")
13+
14+
with open(data_path, "rb") as payment_receipt_response:
15+
return payment_receipt_response.read()
16+
17+
18+
def mock_collection_response():
19+
current_dir = os.path.dirname(os.path.abspath(__file__))
20+
data_path = os.path.join(current_dir, "fixtures/payment_receipt_index.json")
21+
22+
with open(data_path, "rb") as payment_receipts_response:
23+
return payment_receipts_response.read()
24+
25+
26+
def test_valid_find_all_payment_receipts_request(httpx_mock: HTTPXMock):
27+
client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d")
28+
29+
httpx_mock.add_response(
30+
method="GET",
31+
url="https://api.getlago.com/api/v1/payment_receipts",
32+
content=mock_collection_response(),
33+
)
34+
response = client.payment_receipts.find_all()
35+
36+
assert response["payment_receipts"][0].lago_id == "89b6b61e-4dbc-4307-ac96-4abcfa9e3e2d"
37+
assert response["meta"]["current_page"] == 1
38+
39+
40+
def test_valid_find_all_payment_receipts_request_with_options(httpx_mock: HTTPXMock):
41+
client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d")
42+
43+
httpx_mock.add_response(
44+
method="GET",
45+
url="https://api.getlago.com/api/v1/payment_receipts?per_page=2&page=1",
46+
content=mock_collection_response(),
47+
)
48+
response = client.payment_receipts.find_all({"per_page": 2, "page": 1})
49+
50+
assert response["payment_receipts"][0].lago_id == "89b6b61e-4dbc-4307-ac96-4abcfa9e3e2d"
51+
assert response["meta"]["current_page"] == 1
52+
53+
54+
def test_invalid_find_all_payment_receipts_request(httpx_mock: HTTPXMock):
55+
client = Client(api_key="invalid")
56+
57+
httpx_mock.add_response(
58+
method="GET",
59+
url="https://api.getlago.com/api/v1/payment_receipts",
60+
status_code=404,
61+
content=b"",
62+
)
63+
64+
with pytest.raises(LagoApiError):
65+
client.payment_receipts.find_all()

0 commit comments

Comments
 (0)