diff --git a/.gitignore b/.gitignore index 1d80fbf..23a38f5 100644 --- a/.gitignore +++ b/.gitignore @@ -72,5 +72,7 @@ Untitled.ipynb *.iml # End of https://www.toptal.com/developers/gitignore/api/python +# asdf / mise version managers (local dev only; supported versions live in setup.cfg + CI) +.tool-versions mise.toml .claude diff --git a/lago_python_client/models/__init__.py b/lago_python_client/models/__init__.py index fbd141a..7fcf802 100644 --- a/lago_python_client/models/__init__.py +++ b/lago_python_client/models/__init__.py @@ -234,7 +234,7 @@ from .payment_request import PaymentRequest as PaymentRequest from .payment_method import PaymentMethod as PaymentMethod, PaymentMethodResponse as PaymentMethodResponse from .plan import Plan as Plan -from .subscription import Subscription as Subscription +from .subscription import ActivationRuleInput as ActivationRuleInput, Subscription as Subscription from .tax import ( Tax as Tax, ) diff --git a/lago_python_client/models/subscription.py b/lago_python_client/models/subscription.py index 408ec60..807ca74 100644 --- a/lago_python_client/models/subscription.py +++ b/lago_python_client/models/subscription.py @@ -8,6 +8,11 @@ from .plan import PlanOverrides +class ActivationRuleInput(BaseModel): + type: Optional[str] + timeout_hours: Optional[int] + + class Subscription(BaseModel): plan_code: Optional[str] external_customer_id: Optional[str] @@ -20,6 +25,7 @@ class Subscription(BaseModel): payment_method: Optional[PaymentMethod] invoice_custom_section: Optional[InvoiceCustomSectionInput] consolidate_invoice: Optional[bool] + activation_rules: Optional[List[ActivationRuleInput]] class Subscriptions(BaseModel): @@ -28,6 +34,16 @@ class Subscriptions(BaseModel): terminated_at: Optional[str] +class ActivationRuleResponse(BaseResponseModel): + lago_id: Optional[str] + type: Optional[str] + timeout_hours: Optional[int] + status: Optional[str] + expires_at: Optional[str] + created_at: Optional[str] + updated_at: Optional[str] + + class SubscriptionResponse(BaseResponseModel): lago_id: str lago_customer_id: Optional[str] @@ -57,6 +73,9 @@ class SubscriptionResponse(BaseResponseModel): payment_method: Optional[PaymentMethod] applied_invoice_custom_sections: Optional[AppliedInvoiceCustomSections] consolidate_invoice: Optional[bool] + cancellation_reason: Optional[str] + activated_at: Optional[str] + activation_rules: Optional[List[ActivationRuleResponse]] class SubscriptionsResponse(BaseResponseModel): diff --git a/tests/fixtures/subscription.json b/tests/fixtures/subscription.json index 24412ab..ffc6074 100644 --- a/tests/fixtures/subscription.json +++ b/tests/fixtures/subscription.json @@ -37,6 +37,19 @@ "name": "Section Name" } } + ], + "cancellation_reason": "payment_failed", + "activated_at": "2022-04-29T09:00:00Z", + "activation_rules": [ + { + "lago_id": "ar_123", + "type": "payment", + "timeout_hours": 48, + "status": "pending", + "expires_at": "2022-04-29T10:59:51Z", + "created_at": "2022-04-29T08:59:51Z", + "updated_at": "2022-04-29T08:59:51Z" + } ] } } diff --git a/tests/test_subscription_client.py b/tests/test_subscription_client.py index 2512e42..b0af46b 100644 --- a/tests/test_subscription_client.py +++ b/tests/test_subscription_client.py @@ -8,6 +8,7 @@ from lago_python_client.exceptions import LagoApiError from lago_python_client.mixins import DEFAULT_TIMEOUT from lago_python_client.models import ( + ActivationRuleInput, Charge, ChargeFilter, FixedCharge, @@ -108,6 +109,26 @@ def test_valid_create_subscriptions_request_with_payment_method(httpx_mock: HTTP assert response.payment_method.payment_method_id == "pm_123" +def test_valid_create_subscriptions_request_with_activation_rules(httpx_mock: HTTPXMock): + client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d") + + httpx_mock.add_response( + method="POST", + url="https://api.getlago.com/api/v1/subscriptions", + content=mock_response(), + ) + subscription = create_subscription() + subscription.activation_rules = [ActivationRuleInput(type="payment", timeout_hours=48)] + response = client.subscriptions.create(subscription) + + assert response.external_customer_id == "5eb02857-a71e-4ea2-bcf9-57d3a41bc6ba" + assert response.cancellation_reason == "payment_failed" + assert response.activated_at == "2022-04-29T09:00:00Z" + assert response.activation_rules[0].type == "payment" + assert response.activation_rules[0].timeout_hours == 48 + assert response.activation_rules[0].status == "pending" + + def test_invalid_create_subscriptions_request(httpx_mock: HTTPXMock): client = Client(api_key="invalid")