Skip to content

Commit f8acf60

Browse files
committed
feat(subscriptions): add activation_rules, cancellation_reason and activated_at
1 parent f943162 commit f8acf60

5 files changed

Lines changed: 55 additions & 1 deletion

File tree

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python 3.12.5

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]
@@ -20,6 +25,7 @@ class Subscription(BaseModel):
2025
payment_method: Optional[PaymentMethod]
2126
invoice_custom_section: Optional[InvoiceCustomSectionInput]
2227
consolidate_invoice: Optional[bool]
28+
activation_rules: Optional[List[ActivationRuleInput]]
2329

2430

2531
class Subscriptions(BaseModel):
@@ -28,6 +34,16 @@ class Subscriptions(BaseModel):
2834
terminated_at: Optional[str]
2935

3036

37+
class ActivationRuleResponse(BaseResponseModel):
38+
lago_id: Optional[str]
39+
type: Optional[str]
40+
timeout_hours: Optional[int]
41+
status: Optional[str]
42+
expires_at: Optional[str]
43+
created_at: Optional[str]
44+
updated_at: Optional[str]
45+
46+
3147
class SubscriptionResponse(BaseResponseModel):
3248
lago_id: str
3349
lago_customer_id: Optional[str]
@@ -57,6 +73,9 @@ class SubscriptionResponse(BaseResponseModel):
5773
payment_method: Optional[PaymentMethod]
5874
applied_invoice_custom_sections: Optional[AppliedInvoiceCustomSections]
5975
consolidate_invoice: Optional[bool]
76+
cancellation_reason: Optional[str]
77+
activated_at: Optional[str]
78+
activation_rules: Optional[List[ActivationRuleResponse]]
6079

6180

6281
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)