Skip to content

Commit f6f35a4

Browse files
authored
feat(subscriptions): add activation_rules, cancellation_reason and activated_at (#404)
* feat(subscriptions): add activation_rules, cancellation_reason and activated_at * chore: untrack .tool-versions and gitignore version-manager pins .tool-versions pins a single Python patch, which is a local-dev concern inconsistent with a published library that supports a range (setup.cfg python_requires + CI matrix 3.9-3.13). Matches existing handling of .python-version and mise.toml.
1 parent 36ba01c commit f6f35a4

5 files changed

Lines changed: 56 additions & 1 deletion

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,7 @@ Untitled.ipynb
7272
*.iml
7373
# End of https://www.toptal.com/developers/gitignore/api/python
7474

75+
# asdf / mise version managers (local dev only; supported versions live in setup.cfg + CI)
76+
.tool-versions
7577
mise.toml
7678
.claude

lago_python_client/models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@
234234
from .payment_request import PaymentRequest as PaymentRequest
235235
from .payment_method import PaymentMethod as PaymentMethod, PaymentMethodResponse as PaymentMethodResponse
236236
from .plan import Plan as Plan
237-
from .subscription import Subscription as Subscription
237+
from .subscription import ActivationRuleInput as ActivationRuleInput, Subscription as Subscription
238238
from .tax import (
239239
Tax as Tax,
240240
)

lago_python_client/models/subscription.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
from .plan import PlanOverrides
99

1010

11+
class ActivationRuleInput(BaseModel):
12+
type: Optional[str]
13+
timeout_hours: Optional[int]
14+
15+
1116
class Subscription(BaseModel):
1217
plan_code: Optional[str]
1318
external_customer_id: Optional[str]
@@ -21,6 +26,7 @@ class Subscription(BaseModel):
2126
invoice_custom_section: Optional[InvoiceCustomSectionInput]
2227
consolidate_invoice: Optional[bool]
2328
billing_entity_code: Optional[str]
29+
activation_rules: Optional[List[ActivationRuleInput]]
2430

2531

2632
class Subscriptions(BaseModel):
@@ -29,6 +35,16 @@ class Subscriptions(BaseModel):
2935
terminated_at: Optional[str]
3036

3137

38+
class ActivationRuleResponse(BaseResponseModel):
39+
lago_id: Optional[str]
40+
type: Optional[str]
41+
timeout_hours: Optional[int]
42+
status: Optional[str]
43+
expires_at: Optional[str]
44+
created_at: Optional[str]
45+
updated_at: Optional[str]
46+
47+
3248
class SubscriptionResponse(BaseResponseModel):
3349
lago_id: str
3450
lago_customer_id: Optional[str]
@@ -59,6 +75,9 @@ class SubscriptionResponse(BaseResponseModel):
5975
applied_invoice_custom_sections: Optional[AppliedInvoiceCustomSections]
6076
consolidate_invoice: Optional[bool]
6177
billing_entity_code: Optional[str]
78+
cancellation_reason: Optional[str]
79+
activated_at: Optional[str]
80+
activation_rules: Optional[List[ActivationRuleResponse]]
6281

6382

6483
class SubscriptionsResponse(BaseResponseModel):

tests/fixtures/subscription.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@
3737
"name": "Section Name"
3838
}
3939
}
40+
],
41+
"cancellation_reason": "payment_failed",
42+
"activated_at": "2022-04-29T09:00:00Z",
43+
"activation_rules": [
44+
{
45+
"lago_id": "ar_123",
46+
"type": "payment",
47+
"timeout_hours": 48,
48+
"status": "pending",
49+
"expires_at": "2022-04-29T10:59:51Z",
50+
"created_at": "2022-04-29T08:59:51Z",
51+
"updated_at": "2022-04-29T08:59:51Z"
52+
}
4053
]
4154
}
4255
}

tests/test_subscription_client.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from lago_python_client.exceptions import LagoApiError
99
from lago_python_client.mixins import DEFAULT_TIMEOUT
1010
from lago_python_client.models import (
11+
ActivationRuleInput,
1112
Charge,
1213
ChargeFilter,
1314
FixedCharge,
@@ -108,6 +109,26 @@ def test_valid_create_subscriptions_request_with_payment_method(httpx_mock: HTTP
108109
assert response.payment_method.payment_method_id == "pm_123"
109110

110111

112+
def test_valid_create_subscriptions_request_with_activation_rules(httpx_mock: HTTPXMock):
113+
client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d")
114+
115+
httpx_mock.add_response(
116+
method="POST",
117+
url="https://api.getlago.com/api/v1/subscriptions",
118+
content=mock_response(),
119+
)
120+
subscription = create_subscription()
121+
subscription.activation_rules = [ActivationRuleInput(type="payment", timeout_hours=48)]
122+
response = client.subscriptions.create(subscription)
123+
124+
assert response.external_customer_id == "5eb02857-a71e-4ea2-bcf9-57d3a41bc6ba"
125+
assert response.cancellation_reason == "payment_failed"
126+
assert response.activated_at == "2022-04-29T09:00:00Z"
127+
assert response.activation_rules[0].type == "payment"
128+
assert response.activation_rules[0].timeout_hours == 48
129+
assert response.activation_rules[0].status == "pending"
130+
131+
111132
def test_invalid_create_subscriptions_request(httpx_mock: HTTPXMock):
112133
client = Client(api_key="invalid")
113134

0 commit comments

Comments
 (0)