Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lago_python_client/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
2 changes: 2 additions & 0 deletions lago_python_client/models/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
17 changes: 17 additions & 0 deletions lago_python_client/models/invoice_custom_section.py
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
3 changes: 3 additions & 0 deletions lago_python_client/models/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 5 additions & 0 deletions lago_python_client/models/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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]
3 changes: 3 additions & 0 deletions lago_python_client/models/wallet_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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):
Expand All @@ -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):
Expand Down
9 changes: 8 additions & 1 deletion tests/fixtures/subscription.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
}
18 changes: 16 additions & 2 deletions tests/fixtures/wallet.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"
}
]
}
}
9 changes: 8 additions & 1 deletion tests/fixtures/wallet_transaction.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
99 changes: 99 additions & 0 deletions tests/test_customer_wallet_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from lago_python_client.exceptions import LagoApiError
from lago_python_client.models import (
AppliesTo,
InvoiceCustomSectionInput,
RecurringTransactionRule,
RecurringTransactionRuleList,
Wallet,
Expand Down Expand Up @@ -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"
)
21 changes: 21 additions & 0 deletions tests/test_invoice_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from lago_python_client.models import (
Customer,
Invoice,
InvoiceCustomSectionInput,
InvoiceFee,
InvoiceFeesList,
InvoiceMetadata,
Expand Down Expand Up @@ -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"
Loading
Loading