Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(wallet-recurring-transaction-rules): add support for wallet recurring transaction rules #209

Merged
merged 1 commit into from
Nov 30, 2023
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
3 changes: 2 additions & 1 deletion lago_python_client/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from .subscription import Subscription
from .customer_usage import Metric, ChargeObject, ChargeUsage, CustomerUsageResponse
from .tax import Tax, Taxes, TaxResponse, TaxesResponse
from .wallet import Wallet
from .wallet import Wallet, RecurringTransactionRule, RecurringTransactionRuleList, \
RecurringTransactionRuleResponse, RecurringTransactionRuleResponseList
from .wallet_transaction import WalletTransaction
from .webhook_endpoint import WebhookEndpoint
31 changes: 30 additions & 1 deletion lago_python_client/models/wallet.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
from typing import Optional
from typing import List, Optional

from pydantic import BaseModel

from ..base_model import BaseResponseModel


class RecurringTransactionRule(BaseModel):
lago_id: Optional[str]
rule_type: Optional[str]
interval: Optional[str]
threshold_credits: Optional[str]
paid_credits: Optional[str]
granted_credits: Optional[str]


class RecurringTransactionRuleResponse(BaseModel):
lago_id: Optional[str]
rule_type: Optional[str]
interval: Optional[str]
threshold_credits: Optional[str]
paid_credits: Optional[str]
granted_credits: Optional[str]
created_at: Optional[str]


class RecurringTransactionRuleList(BaseModel):
__root__: List[RecurringTransactionRule]


class RecurringTransactionRuleResponseList(BaseModel):
__root__: List[RecurringTransactionRuleResponse]


class Wallet(BaseModel):
external_customer_id: Optional[str]
rate_amount: Optional[str]
Expand All @@ -13,6 +40,7 @@ class Wallet(BaseModel):
granted_credits: Optional[str]
expiration_at: Optional[str]
currency: Optional[str]
recurring_transaction_rules: Optional[RecurringTransactionRuleList]


class WalletResponse(BaseResponseModel):
Expand All @@ -31,4 +59,5 @@ class WalletResponse(BaseResponseModel):
last_balance_sync_at: Optional[str]
last_consumed_credit_at: Optional[str]
terminated_at: Optional[str]
recurring_transaction_rules: Optional[RecurringTransactionRuleResponseList]
balance: str # NOTE(legacy)
11 changes: 10 additions & 1 deletion tests/fixtures/wallet.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
"created_at": "2022-04-29T08:59:51Z",
"expiration_at": null,
"last_balance_sync_at": "2022-04-29T08:59:51Z",
"last_consumed_credit_at": "2022-04-29T08:59:51Z"
"last_consumed_credit_at": "2022-04-29T08:59:51Z",
"recurring_transaction_rules": [
{
"lago_id": "12345",
"rule_type": "interval",
"interval": "monthly",
"paid_credits": "105.0",
"granted_credits": "105.0"
}
]
}
}
15 changes: 13 additions & 2 deletions tests/test_wallet_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,24 @@

from lago_python_client.client import Client
from lago_python_client.exceptions import LagoApiError
from lago_python_client.models import Wallet
from lago_python_client.models import Wallet, RecurringTransactionRule, RecurringTransactionRuleList


def wallet_object():
rule = RecurringTransactionRule(
rule_type='interval',
interval='monthly',
paid_credits='105.0',
granted_credits='105.0',
)
rules_list = RecurringTransactionRuleList(__root__=[rule])
return Wallet(
name='name',
external_customer_id='12345',
rate_amount='1',
paid_credits='10',
granted_credits='10'
granted_credits='10',
recurring_transaction_rules=rules_list
)


Expand All @@ -41,6 +49,9 @@ def test_valid_create_wallet_request(httpx_mock: HTTPXMock):
response = client.wallets.create(wallet_object())

assert response.lago_id == 'b7ab2926-1de8-4428-9bcd-779314ac129b'
assert response.recurring_transaction_rules.__root__[0].lago_id == '12345'
assert response.recurring_transaction_rules.__root__[0].rule_type == 'interval'
assert response.recurring_transaction_rules.__root__[0].interval == 'monthly'


def test_invalid_create_wallet_request(httpx_mock: HTTPXMock):
Expand Down