Skip to content
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lago_python_client/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
19 changes: 19 additions & 0 deletions lago_python_client/models/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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):
Expand All @@ -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]
Expand Down Expand Up @@ -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):
Expand Down
13 changes: 13 additions & 0 deletions tests/fixtures/subscription.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
}
21 changes: 21 additions & 0 deletions tests/test_subscription_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")

Expand Down
Loading