diff --git a/lago_python_client/models/__init__.py b/lago_python_client/models/__init__.py index 399d2bf..fe1cca3 100644 --- a/lago_python_client/models/__init__.py +++ b/lago_python_client/models/__init__.py @@ -189,6 +189,15 @@ from .invoice import ( OneOffInvoice as OneOffInvoice, ) +from .invoice_custom_section import ( + AppliedInvoiceCustomSection as AppliedInvoiceCustomSection, +) +from .invoice_custom_section import ( + AppliedInvoiceCustomSections as AppliedInvoiceCustomSections, +) +from .invoice_custom_section import ( + InvoiceCustomSectionInput as InvoiceCustomSectionInput, +) from .invoice_custom_section import ( InvoiceCustomSectionResponse as InvoiceCustomSectionResponse, ) diff --git a/lago_python_client/models/invoice.py b/lago_python_client/models/invoice.py index 424c4a3..98463bb 100644 --- a/lago_python_client/models/invoice.py +++ b/lago_python_client/models/invoice.py @@ -9,6 +9,7 @@ from .customer import Customer, CustomerResponse from .error_detail import ErrorDetailsResponse from .fee import FeesResponse +from .invoice_custom_section import InvoiceCustomSectionInput from .payment_method import PaymentMethod from .subscription import Subscriptions, SubscriptionsResponse from .usage_threshold import UsageThreshold @@ -55,6 +56,7 @@ class OneOffInvoice(BaseModel): fees: Optional[InvoiceFeesList] error_details: Optional[ErrorDetailsResponse] payment_method: Optional[PaymentMethod] + invoice_custom_section: Optional[InvoiceCustomSectionInput] class InvoicePreview(BaseModel): diff --git a/lago_python_client/models/invoice_custom_section.py b/lago_python_client/models/invoice_custom_section.py index b83b075..4e0e888 100644 --- a/lago_python_client/models/invoice_custom_section.py +++ b/lago_python_client/models/invoice_custom_section.py @@ -1,8 +1,25 @@ from typing import List, Optional +from lago_python_client.base_model import BaseModel + from ..base_model import BaseResponseModel +class InvoiceCustomSectionInput(BaseModel): + skip_invoice_custom_sections: Optional[bool] + invoice_custom_section_codes: Optional[List[str]] + + +class AppliedInvoiceCustomSection(BaseResponseModel): + lago_id: Optional[str] + invoice_custom_section_id: Optional[str] + created_at: Optional[str] + + +class AppliedInvoiceCustomSections(BaseResponseModel): + __root__: List[AppliedInvoiceCustomSection] + + class InvoiceCustomSectionResponse(BaseResponseModel): lago_id: Optional[str] code: Optional[str] diff --git a/lago_python_client/models/subscription.py b/lago_python_client/models/subscription.py index 2d90d90..3c38a21 100644 --- a/lago_python_client/models/subscription.py +++ b/lago_python_client/models/subscription.py @@ -3,6 +3,7 @@ from lago_python_client.base_model import BaseModel from ..base_model import BaseResponseModel +from .invoice_custom_section import AppliedInvoiceCustomSections, InvoiceCustomSectionInput from .payment_method import PaymentMethod from .plan import PlanOverrides @@ -17,6 +18,7 @@ class Subscription(BaseModel): ending_at: Optional[str] plan_overrides: Optional[PlanOverrides] payment_method: Optional[PaymentMethod] + invoice_custom_section: Optional[InvoiceCustomSectionInput] class Subscriptions(BaseModel): @@ -52,6 +54,7 @@ class SubscriptionResponse(BaseResponseModel): on_termination_credit_note: Optional[str] on_termination_invoice: Optional[str] payment_method: Optional[PaymentMethod] + applied_invoice_custom_sections: Optional[AppliedInvoiceCustomSections] class SubscriptionsResponse(BaseResponseModel): diff --git a/lago_python_client/models/wallet.py b/lago_python_client/models/wallet.py index ab5e670..d01ea24 100644 --- a/lago_python_client/models/wallet.py +++ b/lago_python_client/models/wallet.py @@ -3,6 +3,7 @@ from lago_python_client.base_model import BaseModel from ..base_model import BaseResponseModel +from .invoice_custom_section import AppliedInvoiceCustomSections, InvoiceCustomSectionInput from .payment_method import PaymentMethod @@ -21,6 +22,7 @@ class RecurringTransactionRule(BaseModel): transaction_name: Optional[str] ignore_paid_top_up_limits: Optional[bool] payment_method: Optional[PaymentMethod] + invoice_custom_section: Optional[InvoiceCustomSectionInput] class RecurringTransactionRuleResponse(BaseModel): @@ -40,6 +42,7 @@ class RecurringTransactionRuleResponse(BaseModel): transaction_name: Optional[str] ignore_paid_top_up_limits: Optional[bool] payment_method: Optional[PaymentMethod] + applied_invoice_custom_sections: Optional[AppliedInvoiceCustomSections] class RecurringTransactionRuleList(BaseModel): @@ -75,6 +78,7 @@ class Wallet(BaseModel): ignore_paid_top_up_limits_on_creation: Optional[bool] metadata: Optional[Dict[str, Optional[str]]] payment_method: Optional[PaymentMethod] + invoice_custom_section: Optional[InvoiceCustomSectionInput] class WalletResponse(BaseResponseModel): @@ -106,3 +110,4 @@ class WalletResponse(BaseResponseModel): paid_top_up_min_amount_cents: Optional[int] metadata: Optional[Dict[str, Optional[str]]] payment_method: Optional[PaymentMethod] + applied_invoice_custom_sections: Optional[AppliedInvoiceCustomSections] diff --git a/lago_python_client/models/wallet_transaction.py b/lago_python_client/models/wallet_transaction.py index 050533f..93fc6cd 100644 --- a/lago_python_client/models/wallet_transaction.py +++ b/lago_python_client/models/wallet_transaction.py @@ -3,6 +3,7 @@ from lago_python_client.base_model import BaseModel from ..base_model import BaseResponseModel +from .invoice_custom_section import AppliedInvoiceCustomSections, InvoiceCustomSectionInput from .payment_method import PaymentMethod @@ -16,6 +17,7 @@ class WalletTransaction(BaseModel): name: Optional[str] ignore_paid_top_up_limits: Optional[bool] payment_method: Optional[PaymentMethod] + invoice_custom_section: Optional[InvoiceCustomSectionInput] class WalletTransactionResponse(BaseResponseModel): @@ -38,6 +40,7 @@ class WalletTransactionResponse(BaseResponseModel): name: Optional[str] invoice_requires_successful_payment: Optional[bool] payment_method: Optional[PaymentMethod] + applied_invoice_custom_sections: Optional[AppliedInvoiceCustomSections] class WalletTransactionConsumptionResponse(BaseResponseModel): diff --git a/tests/fixtures/subscription.json b/tests/fixtures/subscription.json index 10a8e89..7fe2c8b 100644 --- a/tests/fixtures/subscription.json +++ b/tests/fixtures/subscription.json @@ -24,6 +24,13 @@ "payment_method": { "payment_method_type": "card", "payment_method_id": "pm_123" - } + }, + "applied_invoice_custom_sections": [ + { + "lago_id": "ics_12345", + "invoice_custom_section_id": "section_001", + "created_at": "2022-04-29T08:59:51Z" + } + ] } } diff --git a/tests/fixtures/wallet.json b/tests/fixtures/wallet.json index 1602da3..45900b5 100644 --- a/tests/fixtures/wallet.json +++ b/tests/fixtures/wallet.json @@ -31,7 +31,14 @@ "payment_method": { "payment_method_type": "card", "payment_method_id": "pm_123" - } + }, + "applied_invoice_custom_sections": [ + { + "lago_id": "ics_rule_001", + "invoice_custom_section_id": "section_rule_001", + "created_at": "2022-04-29T08:59:51Z" + } + ] } ], "ongoing_balance_cents": 800, @@ -51,6 +58,13 @@ "payment_method": { "payment_method_type": "card", "payment_method_id": "pm_123" - } + }, + "applied_invoice_custom_sections": [ + { + "lago_id": "ics_wallet_001", + "invoice_custom_section_id": "section_wallet_001", + "created_at": "2022-04-29T08:59:51Z" + } + ] } } diff --git a/tests/fixtures/wallet_transaction.json b/tests/fixtures/wallet_transaction.json index c2c2088..5a3458c 100644 --- a/tests/fixtures/wallet_transaction.json +++ b/tests/fixtures/wallet_transaction.json @@ -19,7 +19,14 @@ "payment_method": { "payment_method_type": "card", "payment_method_id": "pm_123" - } + }, + "applied_invoice_custom_sections": [ + { + "lago_id": "ics_tx_001", + "invoice_custom_section_id": "section_tx_001", + "created_at": "2022-04-29T08:59:51Z" + } + ] }, { "lago_id": "b7ab2926-1de8-4428-9bcd-779314ac1222", diff --git a/tests/test_customer_wallet_client.py b/tests/test_customer_wallet_client.py index beb13c7..d2c453d 100644 --- a/tests/test_customer_wallet_client.py +++ b/tests/test_customer_wallet_client.py @@ -5,6 +5,7 @@ from lago_python_client.exceptions import LagoApiError from lago_python_client.models import ( AppliesTo, + InvoiceCustomSectionInput, RecurringTransactionRule, RecurringTransactionRuleList, Wallet, @@ -234,3 +235,101 @@ def test_invalid_find_all_wallet_request(httpx_mock: HTTPXMock): with pytest.raises(LagoApiError): client.customers.wallets.find_all("customer_id") + + +def test_valid_create_customer_wallet_with_invoice_custom_section(httpx_mock: HTTPXMock): + client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d") + invoice_custom_section = InvoiceCustomSectionInput( + skip_invoice_custom_sections=False, + invoice_custom_section_codes=["section_code_1"], + ) + + httpx_mock.add_response( + method="POST", + url="https://api.getlago.com/api/v1/customers/customer_id/wallets", + content=mock_response("wallet"), + ) + wallet = wallet_object() + wallet.invoice_custom_section = invoice_custom_section + response = client.customers.wallets.create("customer_id", wallet) + + assert response.lago_id == "b7ab2926-1de8-4428-9bcd-779314ac129b" + assert response.applied_invoice_custom_sections.__root__[0].lago_id == "ics_wallet_001" + assert response.applied_invoice_custom_sections.__root__[0].invoice_custom_section_id == "section_wallet_001" + assert response.applied_invoice_custom_sections.__root__[0].created_at == "2022-04-29T08:59:51Z" + + +def test_valid_update_customer_wallet_with_invoice_custom_section(httpx_mock: HTTPXMock): + client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d") + wallet_id = "b7ab2926-1de8-4428-9bcd-779314ac129b" + invoice_custom_section = InvoiceCustomSectionInput( + skip_invoice_custom_sections=False, + invoice_custom_section_codes=["section_code_1"], + ) + + httpx_mock.add_response( + method="PUT", + url="https://api.getlago.com/api/v1/customers/customer_id/wallets/" + wallet_id, + content=mock_response("wallet"), + ) + wallet = wallet_object() + wallet.invoice_custom_section = invoice_custom_section + response = client.customers.wallets.update("customer_id", wallet_id, wallet) + + assert response.lago_id == "b7ab2926-1de8-4428-9bcd-779314ac129b" + assert response.applied_invoice_custom_sections.__root__[0].lago_id == "ics_wallet_001" + assert response.applied_invoice_custom_sections.__root__[0].invoice_custom_section_id == "section_wallet_001" + + +def test_valid_create_customer_wallet_with_invoice_custom_section_on_recurring_transaction_rule(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/customers/customer_id/wallets", + content=mock_response("wallet"), + ) + response = client.customers.wallets.create("customer_id", wallet_object()) + + assert response.lago_id == "b7ab2926-1de8-4428-9bcd-779314ac129b" + assert ( + response.recurring_transaction_rules.__root__[0].applied_invoice_custom_sections.__root__[0].lago_id + == "ics_rule_001" + ) + assert ( + response.recurring_transaction_rules.__root__[0] + .applied_invoice_custom_sections.__root__[0] + .invoice_custom_section_id + == "section_rule_001" + ) + + +def test_valid_update_customer_wallet_with_invoice_custom_section_on_recurring_transaction_rule(httpx_mock: HTTPXMock): + client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d") + wallet_id = "b7ab2926-1de8-4428-9bcd-779314ac129b" + invoice_custom_section = InvoiceCustomSectionInput( + skip_invoice_custom_sections=False, + invoice_custom_section_codes=["section_code_1"], + ) + rule = RecurringTransactionRule( + trigger="interval", + interval="monthly", + paid_credits="105.0", + granted_credits="105.0", + invoice_custom_section=invoice_custom_section, + ) + rules_list = RecurringTransactionRuleList(__root__=[rule]) + + httpx_mock.add_response( + method="PUT", + url="https://api.getlago.com/api/v1/customers/customer_id/wallets/" + wallet_id, + content=mock_response("wallet"), + ) + wallet = Wallet(name="name", recurring_transaction_rules=rules_list) + response = client.customers.wallets.update("customer_id", wallet_id, wallet) + + assert response.lago_id == "b7ab2926-1de8-4428-9bcd-779314ac129b" + assert ( + response.recurring_transaction_rules.__root__[0].applied_invoice_custom_sections.__root__[0].lago_id + == "ics_rule_001" + ) diff --git a/tests/test_invoice_client.py b/tests/test_invoice_client.py index 538fd6e..c2a838a 100644 --- a/tests/test_invoice_client.py +++ b/tests/test_invoice_client.py @@ -8,6 +8,7 @@ from lago_python_client.models import ( Customer, Invoice, + InvoiceCustomSectionInput, InvoiceFee, InvoiceFeesList, InvoiceMetadata, @@ -393,3 +394,23 @@ def test_valid_void_invoice_request_with_options(httpx_mock: HTTPXMock): assert response.lago_id == "5eb02857-a71e-4ea2-bcf9-57d3a41bc6ba" assert response.status == "voided" + + +def test_valid_create_one_off_invoice_with_invoice_custom_section(httpx_mock: HTTPXMock): + client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d") + invoice_custom_section = InvoiceCustomSectionInput( + skip_invoice_custom_sections=False, + invoice_custom_section_codes=["section_code_1"], + ) + + httpx_mock.add_response( + method="POST", + url="https://api.getlago.com/api/v1/invoices", + content=mock_response(mock="one_off_invoice"), + ) + invoice = one_off_invoice_object() + invoice.invoice_custom_section = invoice_custom_section + response = client.invoices.create(invoice) + + assert response.lago_id == "5eb02857-a71e-4ea2-bcf9-57d3a41bc6ba" + assert response.invoice_type == "one_off" diff --git a/tests/test_subscription_client.py b/tests/test_subscription_client.py index ccfbaa8..a3f2eb7 100644 --- a/tests/test_subscription_client.py +++ b/tests/test_subscription_client.py @@ -7,7 +7,14 @@ from lago_python_client.client import Client from lago_python_client.exceptions import LagoApiError from lago_python_client.mixins import DEFAULT_TIMEOUT -from lago_python_client.models import Charge, ChargeFilter, FixedCharge, PaymentMethod, Subscription +from lago_python_client.models import ( + Charge, + ChargeFilter, + FixedCharge, + InvoiceCustomSectionInput, + PaymentMethod, + Subscription, +) from lago_python_client.models.alert import Alert, AlertsList, AlertThreshold @@ -1009,6 +1016,53 @@ def test_find_all_charge_filters_with_status(httpx_mock: HTTPXMock): assert len(response["filters"]) == 1 +# --- Invoice custom section tests --- + + +def test_valid_create_subscription_with_invoice_custom_section(httpx_mock: HTTPXMock): + client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d") + invoice_custom_section = InvoiceCustomSectionInput( + skip_invoice_custom_sections=False, + invoice_custom_section_codes=["section_code_1"], + ) + + httpx_mock.add_response( + method="POST", + url="https://api.getlago.com/api/v1/subscriptions", + content=mock_response(), + ) + subscription = create_subscription() + subscription.invoice_custom_section = invoice_custom_section + response = client.subscriptions.create(subscription) + + assert response.external_customer_id == "5eb02857-a71e-4ea2-bcf9-57d3a41bc6ba" + assert response.applied_invoice_custom_sections.__root__[0].lago_id == "ics_12345" + assert response.applied_invoice_custom_sections.__root__[0].invoice_custom_section_id == "section_001" + assert response.applied_invoice_custom_sections.__root__[0].created_at == "2022-04-29T08:59:51Z" + + +def test_valid_update_subscription_with_invoice_custom_section(httpx_mock: HTTPXMock): + client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d") + identifier = "sub_id" + invoice_custom_section = InvoiceCustomSectionInput( + skip_invoice_custom_sections=False, + invoice_custom_section_codes=["section_code_1"], + ) + + httpx_mock.add_response( + method="PUT", + url="https://api.getlago.com/api/v1/subscriptions/" + identifier, + content=mock_response(), + ) + response = client.subscriptions.update( + Subscription(name="name", invoice_custom_section=invoice_custom_section), identifier + ) + + assert response.external_customer_id == "5eb02857-a71e-4ea2-bcf9-57d3a41bc6ba" + assert response.applied_invoice_custom_sections.__root__[0].lago_id == "ics_12345" + assert response.applied_invoice_custom_sections.__root__[0].invoice_custom_section_id == "section_001" + + # --- Default timeout tests --- diff --git a/tests/test_wallet_client.py b/tests/test_wallet_client.py index baa5956..58328d8 100644 --- a/tests/test_wallet_client.py +++ b/tests/test_wallet_client.py @@ -7,6 +7,7 @@ from lago_python_client.exceptions import LagoApiError from lago_python_client.models import ( AppliesTo, + InvoiceCustomSectionInput, PaymentMethod, RecurringTransactionRule, RecurringTransactionRuleList, @@ -480,3 +481,101 @@ def test_valid_delete_metadata_key_request(httpx_mock: HTTPXMock): response = client.wallets.delete_metadata_key(wallet_id, key) assert response == {"baz": "qux"} + + +def test_valid_create_wallet_with_invoice_custom_section(httpx_mock: HTTPXMock): + client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d") + invoice_custom_section = InvoiceCustomSectionInput( + skip_invoice_custom_sections=False, + invoice_custom_section_codes=["section_code_1"], + ) + + httpx_mock.add_response( + method="POST", + url="https://api.getlago.com/api/v1/wallets", + content=mock_response(), + ) + wallet = wallet_object() + wallet.invoice_custom_section = invoice_custom_section + response = client.wallets.create(wallet) + + assert response.lago_id == "b7ab2926-1de8-4428-9bcd-779314ac129b" + assert response.applied_invoice_custom_sections.__root__[0].lago_id == "ics_wallet_001" + assert response.applied_invoice_custom_sections.__root__[0].invoice_custom_section_id == "section_wallet_001" + assert response.applied_invoice_custom_sections.__root__[0].created_at == "2022-04-29T08:59:51Z" + + +def test_valid_update_wallet_with_invoice_custom_section(httpx_mock: HTTPXMock): + client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d") + wallet_id = "b7ab2926-1de8-4428-9bcd-779314ac129b" + invoice_custom_section = InvoiceCustomSectionInput( + skip_invoice_custom_sections=False, + invoice_custom_section_codes=["section_code_1"], + ) + + httpx_mock.add_response( + method="PUT", + url="https://api.getlago.com/api/v1/wallets/" + wallet_id, + content=mock_response(), + ) + wallet = wallet_object() + wallet.invoice_custom_section = invoice_custom_section + response = client.wallets.update(wallet, wallet_id) + + assert response.lago_id == "b7ab2926-1de8-4428-9bcd-779314ac129b" + assert response.applied_invoice_custom_sections.__root__[0].lago_id == "ics_wallet_001" + assert response.applied_invoice_custom_sections.__root__[0].invoice_custom_section_id == "section_wallet_001" + + +def test_valid_create_wallet_with_invoice_custom_section_on_recurring_transaction_rule(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/wallets", + content=mock_response(), + ) + response = client.wallets.create(wallet_object()) + + assert response.lago_id == "b7ab2926-1de8-4428-9bcd-779314ac129b" + assert ( + response.recurring_transaction_rules.__root__[0].applied_invoice_custom_sections.__root__[0].lago_id + == "ics_rule_001" + ) + assert ( + response.recurring_transaction_rules.__root__[0] + .applied_invoice_custom_sections.__root__[0] + .invoice_custom_section_id + == "section_rule_001" + ) + + +def test_valid_update_wallet_with_invoice_custom_section_on_recurring_transaction_rule(httpx_mock: HTTPXMock): + client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d") + wallet_id = "b7ab2926-1de8-4428-9bcd-779314ac129b" + invoice_custom_section = InvoiceCustomSectionInput( + skip_invoice_custom_sections=False, + invoice_custom_section_codes=["section_code_1"], + ) + rule = RecurringTransactionRule( + trigger="interval", + interval="monthly", + paid_credits="105.0", + granted_credits="105.0", + invoice_custom_section=invoice_custom_section, + ) + rules_list = RecurringTransactionRuleList(__root__=[rule]) + + httpx_mock.add_response( + method="PUT", + url="https://api.getlago.com/api/v1/wallets/" + wallet_id, + content=mock_response(), + ) + wallet = Wallet(name="name", recurring_transaction_rules=rules_list) + response = client.wallets.update(wallet, wallet_id) + + assert response.lago_id == "b7ab2926-1de8-4428-9bcd-779314ac129b" + assert ( + response.recurring_transaction_rules.__root__[0].applied_invoice_custom_sections.__root__[0].lago_id + == "ics_rule_001" + ) diff --git a/tests/test_wallet_transaction_client.py b/tests/test_wallet_transaction_client.py index af614f0..152018c 100644 --- a/tests/test_wallet_transaction_client.py +++ b/tests/test_wallet_transaction_client.py @@ -5,7 +5,7 @@ from lago_python_client.client import Client from lago_python_client.exceptions import LagoApiError -from lago_python_client.models import PaymentMethod, WalletTransaction +from lago_python_client.models import InvoiceCustomSectionInput, PaymentMethod, WalletTransaction def wallet_transaction_object(): @@ -237,3 +237,31 @@ def test_valid_fundings_request(httpx_mock: HTTPXMock): assert funding.wallet_transaction.lago_id == "inbound-tx-id" assert funding.wallet_transaction.transaction_type == "inbound" assert response["meta"]["current_page"] == 1 + + +def test_valid_create_wallet_transaction_with_invoice_custom_section(httpx_mock: HTTPXMock): + client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d") + invoice_custom_section = InvoiceCustomSectionInput( + skip_invoice_custom_sections=False, + invoice_custom_section_codes=["section_code_1"], + ) + + httpx_mock.add_response( + method="POST", + url="https://api.getlago.com/api/v1/wallet_transactions", + content=mock_response(), + ) + transaction = wallet_transaction_object() + transaction.invoice_custom_section = invoice_custom_section + response = client.wallet_transactions.create(transaction) + + assert response["wallet_transactions"][0].lago_id == "b7ab2926-1de8-4428-9bcd-779314ac1111" + assert response["wallet_transactions"][0].applied_invoice_custom_sections.__root__[0].lago_id == "ics_tx_001" + assert ( + response["wallet_transactions"][0].applied_invoice_custom_sections.__root__[0].invoice_custom_section_id + == "section_tx_001" + ) + assert ( + response["wallet_transactions"][0].applied_invoice_custom_sections.__root__[0].created_at + == "2022-04-29T08:59:51Z" + )