Skip to content
Draft
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
2 changes: 2 additions & 0 deletions lago_python_client/models/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class RecurringTransactionRule(BaseModel):
transaction_metadata: Optional[List[Dict[str, str]]]
transaction_name: Optional[str]
ignore_paid_top_up_limits: Optional[bool]
grants_target_top_up: Optional[bool]
payment_method: Optional[PaymentMethod]
invoice_custom_section: Optional[InvoiceCustomSectionInput]

Expand All @@ -41,6 +42,7 @@ class RecurringTransactionRuleResponse(BaseModel):
transaction_metadata: Optional[List[Dict[str, str]]]
transaction_name: Optional[str]
ignore_paid_top_up_limits: Optional[bool]
grants_target_top_up: Optional[bool]
payment_method: Optional[PaymentMethod]
applied_invoice_custom_sections: Optional[AppliedInvoiceCustomSections]

Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/wallet.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"target_ongoing_balance": "200.0",
"transaction_name": "Recurring Transaction Rule",
"ignore_paid_top_up_limits": true,
"grants_target_top_up": true,
"payment_method": {
"payment_method_type": "card",
"payment_method_id": "pm_123"
Expand Down
41 changes: 41 additions & 0 deletions tests/test_customer_wallet_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def wallet_object():
target_ongoing_balance="105.0",
transaction_name="Recurring Transaction Rule",
ignore_paid_top_up_limits=True,
grants_target_top_up=True,
)
rules_list = RecurringTransactionRuleList(__root__=[rule])
applies_to = AppliesTo(
Expand Down Expand Up @@ -73,6 +74,7 @@ def test_valid_create_wallet_request(httpx_mock: HTTPXMock):
"target_ongoing_balance": "105.0",
"transaction_name": "Recurring Transaction Rule",
"ignore_paid_top_up_limits": True,
"grants_target_top_up": True,
}
],
"invoice_requires_successful_payment": False,
Expand All @@ -88,6 +90,7 @@ def test_valid_create_wallet_request(httpx_mock: HTTPXMock):
assert response.recurring_transaction_rules.__root__[0].trigger == "interval"
assert response.recurring_transaction_rules.__root__[0].interval == "monthly"
assert response.recurring_transaction_rules.__root__[0].ignore_paid_top_up_limits is True
assert response.recurring_transaction_rules.__root__[0].grants_target_top_up is True
assert response.applies_to.fee_types[0] == "charge"
assert response.applies_to.billable_metric_codes[0] == "usage"
assert response.paid_top_up_max_amount_cents == 10000
Expand Down Expand Up @@ -348,3 +351,41 @@ def test_valid_update_customer_wallet_with_invoice_custom_section_on_recurring_t
.invoice_custom_section_id
== "section_rule_001"
)


def test_valid_update_wallet_with_grants_target_top_up_on_recurring_transaction_rule(httpx_mock: HTTPXMock):
client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d")
wallet_id = "b7ab2926-1de8-4428-9bcd-779314ac129b"
rule = RecurringTransactionRule(
trigger="interval",
interval="monthly",
method="target",
target_ongoing_balance="200.0",
grants_target_top_up=True,
)
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"),
match_json={
"wallet": {
"name": "name",
"recurring_transaction_rules": [
{
"interval": "monthly",
"trigger": "interval",
"method": "target",
"target_ongoing_balance": "200.0",
"grants_target_top_up": True,
}
],
}
},
)
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].grants_target_top_up is True
41 changes: 41 additions & 0 deletions tests/test_wallet_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def wallet_object():
target_ongoing_balance="105.0",
transaction_name="Recurring Transaction Rule",
ignore_paid_top_up_limits=True,
grants_target_top_up=True,
)
rules_list = RecurringTransactionRuleList(__root__=[rule])
applies_to = AppliesTo(
Expand Down Expand Up @@ -92,6 +93,7 @@ def test_valid_create_wallet_request(httpx_mock: HTTPXMock):
"target_ongoing_balance": "105.0",
"transaction_name": "Recurring Transaction Rule",
"ignore_paid_top_up_limits": True,
"grants_target_top_up": True,
}
],
"invoice_requires_successful_payment": False,
Expand All @@ -107,6 +109,7 @@ def test_valid_create_wallet_request(httpx_mock: HTTPXMock):
assert response.recurring_transaction_rules.__root__[0].trigger == "interval"
assert response.recurring_transaction_rules.__root__[0].interval == "monthly"
assert response.recurring_transaction_rules.__root__[0].ignore_paid_top_up_limits is True
assert response.recurring_transaction_rules.__root__[0].grants_target_top_up is True
assert response.applies_to.fee_types[0] == "charge"
assert response.applies_to.billable_metric_codes[0] == "usage"
assert response.paid_top_up_max_amount_cents == 10000
Expand Down Expand Up @@ -594,3 +597,41 @@ def test_valid_update_wallet_with_invoice_custom_section_on_recurring_transactio
.invoice_custom_section_id
== "section_rule_001"
)


def test_valid_update_wallet_with_grants_target_top_up_on_recurring_transaction_rule(httpx_mock: HTTPXMock):
client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d")
wallet_id = "b7ab2926-1de8-4428-9bcd-779314ac129b"
rule = RecurringTransactionRule(
trigger="interval",
interval="monthly",
method="target",
target_ongoing_balance="200.0",
grants_target_top_up=True,
)
rules_list = RecurringTransactionRuleList(__root__=[rule])

httpx_mock.add_response(
method="PUT",
url="https://api.getlago.com/api/v1/wallets/" + wallet_id,
content=mock_response(),
match_json={
"wallet": {
"name": "name",
"recurring_transaction_rules": [
{
"interval": "monthly",
"trigger": "interval",
"method": "target",
"target_ongoing_balance": "200.0",
"grants_target_top_up": True,
}
],
}
},
)
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].grants_target_top_up is True
Loading