Skip to content

Commit

Permalink
Add usage_thresholds & progressive_billing_credit_amount_cents attrib…
Browse files Browse the repository at this point in the history
…utes
  • Loading branch information
nudded committed Aug 29, 2024
1 parent bf34230 commit d71ed7f
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 11 deletions.
1 change: 1 addition & 0 deletions lago_python_client/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@
RecurringTransactionRuleResponse, RecurringTransactionRuleResponseList
from .wallet_transaction import WalletTransaction
from .webhook_endpoint import WebhookEndpoint
from .usage_threshold import UsageThreshold, UsageThresholds, UsageThresholdsResponse
2 changes: 2 additions & 0 deletions lago_python_client/models/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ class InvoiceResponse(BaseResponseModel):
coupons_amount_cents: int
taxes_amount_cents: int
credit_notes_amount_cents: int
progressive_billing_credit_amount_cents: int
sub_total_excluding_taxes_amount_cents: int
sub_total_including_taxes_amount_cents: int
total_amount_cents: int
prepaid_credit_amount_cents: int

file_url: Optional[str]
customer: Optional[CustomerResponse]
subscriptions: Optional[SubscriptionsResponse]
Expand Down
5 changes: 5 additions & 0 deletions lago_python_client/models/plan.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from typing import List, Optional

from lago_python_client.base_model import BaseModel
from lago_python_client.models.usage_threshold import UsageThreshold

from .charge import Charges, ChargesResponse, ChargesOverrides
from .usage_threshold import UsageThresholds, UsageThresholdsResponse, UsageThresholdsOverrides
from .minimum_commitment import MinimumCommitment, MinimumCommitmentResponse, MinimumCommitmentOverrides
from .tax import Taxes, TaxesResponse
from ..base_model import BaseResponseModel
Expand All @@ -21,6 +23,7 @@ class Plan(BaseModel):
bill_charges_monthly: Optional[bool]
charges: Optional[Charges]
minimum_commitment: Optional[MinimumCommitment]
usage_thresholds: Optional[UsageThresholds]
tax_codes: Optional[List[str]]


Expand All @@ -39,6 +42,7 @@ class PlanResponse(BaseResponseModel):
bill_charges_monthly: Optional[bool]
charges: Optional[ChargesResponse]
minimum_commitment: Optional[MinimumCommitmentResponse]
usage_thresholds: Optional[UsageThresholdsResponse]
active_subscriptions_count: int
draft_invoices_count: int
taxes: Optional[TaxesResponse]
Expand All @@ -52,4 +56,5 @@ class PlanOverrides(BaseModel):
trial_period: Optional[float]
charges: Optional[ChargesOverrides]
minimum_commitment: Optional[MinimumCommitmentOverrides]
usage_thresholds: Optional[UsageThresholdsOverrides]
tax_codes: Optional[List[str]]
35 changes: 35 additions & 0 deletions lago_python_client/models/usage_threshold.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from typing import Any, Dict, List, Optional

from lago_python_client.base_model import BaseModel

from ..base_model import BaseResponseModel



class UsageThreshold(BaseModel):
id: Optional[str]
threshold_display_name: Optional[str]
amount_cents: Optional[int]
recurring: Optional[bool]

class UsageThresholds(BaseModel):
__root__: List[UsageThreshold]

class UsageThresholdResponse(BaseResponseModel):
lago_id: str
amount_cents: int
threshold_display_name: Optional[str]
recurring: bool
created_at: Optional[str]
updated_at: Optional[str]

class UsageThresholdsResponse(BaseResponseModel):
__root__: List[UsageThresholdResponse]

class UsageThresholdOverrides(BaseModel):
amount_cents: Optional[int]
threshold_display_name: Optional[str]
recurring: Optional[bool]

class UsageThresholdsOverrides(BaseModel):
__root__: List[UsageThresholdOverrides]
5 changes: 2 additions & 3 deletions tests/fixtures/invoice.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"taxes_amount_cents": 20,
"coupons_amount_cents": 0,
"credit_notes_amount_cents": 0,
"progressive_billing_credit_amount_cents": 0,
"sub_total_excluding_taxes_amount_cents": 100,
"sub_total_including_taxes_amount_cents": 120,
"prepaid_credit_amount_cents": 0,
Expand Down Expand Up @@ -112,9 +113,7 @@
"name": "User Seats",
"invoice_display_name": "charge_invoice_display_name",
"filters": {
"region": [
"us-east-1"
]
"region": ["us-east-1"]
}
},
"amount_cents": 100,
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/invoice_index.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"taxes_amount_cents": 20,
"coupons_amount_cents": 0,
"credit_notes_amount_cents": 0,
"progressive_billing_credit_amount_cents": 0,
"sub_total_excluding_taxes_amount_cents": 100,
"sub_total_including_taxes_amount_cents": 120,
"prepaid_credit_amount_cents": 0,
Expand Down Expand Up @@ -53,6 +54,7 @@
"taxes_amount_cents": 20,
"coupons_amount_cents": 0,
"credit_notes_amount_cents": 0,
"progressive_billing_credit_amount_cents": 0,
"sub_total_excluding_taxes_amount_cents": 100,
"sub_total_including_taxes_amount_cents": 120,
"prepaid_credit_amount_cents": 0,
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/one_off_invoice.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"fees_amount_cents": 100,
"taxes_amount_cents": 20,
"coupons_amount_cents": 0,
"progressive_billing_credit_amount_cents": 0,
"credit_notes_amount_cents": 0,
"sub_total_excluding_taxes_amount_cents": 100,
"sub_total_including_taxes_amount_cents": 120,
Expand Down
16 changes: 10 additions & 6 deletions tests/fixtures/plan.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
"min_amount_cents": 0,
"properties": {
"amount": "0.22",
"grouped_by": [
"agent_name"
]
"grouped_by": ["agent_name"]
},
"filters": [
{
Expand All @@ -40,9 +38,7 @@
"amount": "0.33"
},
"values": {
"country": [
"France"
]
"country": ["France"]
}
}
],
Expand All @@ -69,6 +65,14 @@
"amount_cents": 1000,
"interval": "weekly"
},
"usage_thresholds": [
{
"lago_id": "85898fbd-0ec6-40a6-8ef1-f863d4b1668a",
"amount_cents": 20,
"threshold_display_name": "Threshold 1",
"recurring": false
}
],
"taxes": [
{
"lago_id": "b7ab2926-1de8-4428-9bcd-779314ac129b",
Expand Down
14 changes: 12 additions & 2 deletions tests/test_plan_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from lago_python_client.client import Client
from lago_python_client.exceptions import LagoApiError
from lago_python_client.models import Plan, Charge, Charges, MinimumCommitment
from lago_python_client.models import Plan, Charge, Charges, MinimumCommitment, UsageThreshold, UsageThresholds


def plan_object():
Expand All @@ -31,6 +31,14 @@ def plan_object():
)
charges = Charges(__root__=[charge])

usage_threshold = UsageThreshold(
threshold_display_name="Threshold 1",
amount_cents = 20,
recurring = False
)

usage_thresholds = UsageThresholds(__root__=[usage_threshold])

minimum_commitment = MinimumCommitment(
amount_cents=0,
invoice_display_name='Commitment (C1)'
Expand All @@ -46,7 +54,8 @@ def plan_object():
interval='weekly',
pay_in_advance=True,
charges=charges,
minimum_commitment=minimum_commitment
minimum_commitment=minimum_commitment,
usage_thresholds=usage_thresholds,
)


Expand Down Expand Up @@ -122,6 +131,7 @@ def test_valid_create_plan_request(httpx_mock: HTTPXMock):
assert response.invoice_display_name == 'test plan 1'
assert response.charges.__root__[0].invoice_display_name == 'Setup'
assert response.minimum_commitment.invoice_display_name == 'Minimum commitment (C1)'
assert response.usage_thresholds.__root__[0].threshold_display_name == 'Threshold 1'


def test_valid_create_graduated_plan_request(httpx_mock: HTTPXMock):
Expand Down

0 comments on commit d71ed7f

Please sign in to comment.