From 374f1b40b7441a2c34a99ca7d898c5671d06b545 Mon Sep 17 00:00:00 2001 From: Ayush Kumar Sharaf Date: Tue, 21 Jul 2026 05:21:46 +0530 Subject: [PATCH] fix(usage): populate lago_invoice_id on customer usage responses The Lago API returns the invoice identifier under `lago_invoice_id`, but `CustomerUsageResponse` declared it as `invoice_id`. Because pydantic drops unknown fields by default, the value was silently discarded and the field was always null. Rename the field to `lago_invoice_id` to match the API payload (same fix applied to `WalletTransactionResponse` in #379), affecting both the `current_usage` and `past_usage` endpoints. Update the current-usage fixture and add assertions covering the field. Fixes #407 Co-Authored-By: Claude Opus 4.8 (1M context) --- lago_python_client/models/customer_usage.py | 2 +- tests/fixtures/customer_usage.json | 2 +- tests/test_customer_client.py | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lago_python_client/models/customer_usage.py b/lago_python_client/models/customer_usage.py index 78bf752c..cfb01a37 100644 --- a/lago_python_client/models/customer_usage.py +++ b/lago_python_client/models/customer_usage.py @@ -73,7 +73,7 @@ class CustomerUsageResponse(BaseResponseModel): from_datetime: str to_datetime: str issuing_date: str - invoice_id: Optional[str] + lago_invoice_id: Optional[str] currency: str amount_cents: int total_amount_cents: int diff --git a/tests/fixtures/customer_usage.json b/tests/fixtures/customer_usage.json index a0ad50d9..885b2fa8 100644 --- a/tests/fixtures/customer_usage.json +++ b/tests/fixtures/customer_usage.json @@ -3,7 +3,7 @@ "from_datetime": "2022-07-01T00:00:00Z", "to_datetime": "2022-07-31T23:59:59Z", "issuing_date": "2022-08-01", - "invoice_id": null, + "lago_invoice_id": null, "currency": "EUR", "amount_cents": 123, "total_amount_cents": 123, diff --git a/tests/test_customer_client.py b/tests/test_customer_client.py index 4ce3564f..9c7ed58a 100644 --- a/tests/test_customer_client.py +++ b/tests/test_customer_client.py @@ -130,6 +130,7 @@ def test_valid_current_usage(httpx_mock: HTTPXMock): response = client.customers.current_usage("external_customer_id", "123") assert response.from_datetime == "2022-07-01T00:00:00Z" + assert response.lago_invoice_id is None assert len(response.charges_usage) == 1 assert response.charges_usage[0].units == "1.0" assert len(response.charges_usage[0].filters) == 1 @@ -272,6 +273,7 @@ def test_valid_past_usage(httpx_mock: HTTPXMock): assert len(response["usage_periods"]) == 1 assert response["usage_periods"][0].from_datetime == "2022-07-01T00:00:00Z" + assert response["usage_periods"][0].lago_invoice_id == "1a901a90-1a90-1a90-1a90-1a901a901a90" assert len(response["usage_periods"][0].charges_usage) == 1 assert response["usage_periods"][0].charges_usage[0].units == "1.0" assert len(response["usage_periods"][0].charges_usage[0].filters) == 1