Skip to content

Commit f4c710e

Browse files
authored
feat(subscriptions): document payment-gated subscription activation (#543)
Add the API surface introduced by payment-gated subscription activation: - `activation_rules` on subscription create/update inputs and on the subscription response object - `cancellation_reason` and activated_at on the subscription response - `incomplete` subscription status - `subscription.incomplete` and `subscription.canceled` webhook events
1 parent 92ac3b1 commit f4c710e

10 files changed

Lines changed: 398 additions & 2 deletions

openapi.yaml

Lines changed: 197 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/openapi.yaml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
type: object
2+
required:
3+
- type
4+
properties:
5+
type:
6+
type: string
7+
description: The type of the activation rule. Only `payment` is currently supported. A `payment` rule gates the subscription activation on a successful payment of the first invoice.
8+
example: "payment"
9+
enum:
10+
- payment
11+
timeout_hours:
12+
type: integer
13+
description: The number of hours the subscription stays in the `incomplete` state waiting for the payment to succeed before it is automatically canceled. Must be a positive integer or zero.
14+
example: 48
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
type: object
2+
required:
3+
- lago_id
4+
- type
5+
- timeout_hours
6+
- status
7+
- created_at
8+
- updated_at
9+
properties:
10+
lago_id:
11+
type: string
12+
format: "uuid"
13+
example: "1a901a90-1a90-1a90-1a90-1a901a901a90"
14+
description: Unique identifier assigned to the activation rule within the Lago application. This ID is exclusively created by Lago.
15+
type:
16+
type: string
17+
description: The type of the activation rule. Only `payment` is currently supported. A `payment` rule gates the subscription activation on a successful payment of the first invoice.
18+
example: "payment"
19+
enum:
20+
- payment
21+
timeout_hours:
22+
type: integer
23+
description: The number of hours the subscription stays in the `incomplete` state waiting for the payment to succeed before it is automatically canceled.
24+
example: 48
25+
status:
26+
type: string
27+
description: |-
28+
The evaluation status of the activation rule:
29+
- `inactive`: the rule has not been evaluated yet.
30+
- `pending`: the rule is applicable and is waiting to be satisfied (e.g. waiting for the payment).
31+
- `satisfied`: the rule has been satisfied and no longer blocks activation.
32+
- `declined`: the rule was applicable but was declined.
33+
- `failed`: the rule could not be satisfied (e.g. the payment failed).
34+
- `expired`: the rule was not satisfied before its timeout elapsed.
35+
- `not_applicable`: the rule did not apply to this subscription.
36+
example: "pending"
37+
enum:
38+
- inactive
39+
- pending
40+
- satisfied
41+
- declined
42+
- failed
43+
- expired
44+
- not_applicable
45+
expires_at:
46+
type:
47+
- string
48+
- "null"
49+
format: "date-time"
50+
example: "2022-08-10T00:00:00Z"
51+
description: The date and time when the rule expires, after which an unsatisfied rule causes the subscription to be canceled. Represented in ISO 8601 datetime format and expressed in Coordinated Universal Time (UTC). Null until the rule starts being evaluated.
52+
created_at:
53+
type: string
54+
format: "date-time"
55+
example: "2022-08-08T00:00:00Z"
56+
description: The creation date of the activation rule, represented in ISO 8601 datetime format and expressed in Coordinated Universal Time (UTC).
57+
updated_at:
58+
type: string
59+
format: "date-time"
60+
example: "2022-08-08T00:00:00Z"
61+
description: The last update date of the activation rule, represented in ISO 8601 datetime format and expressed in Coordinated Universal Time (UTC).

src/schemas/SubscriptionCreateInput.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,9 @@ properties:
8585
8686
- `true` (default): the subscription is included in the customer's standard invoice grouping (by billing entity, currency and payment method).
8787
- `false`: the subscription is excluded from consolidation and always billed on its own dedicated invoice.
88+
activation_rules:
89+
type: array
90+
items:
91+
$ref: "./SubscriptionActivationRuleInput.yaml"
92+
description: |
93+
Optional list of activation rules that gate the subscription activation. When a `payment` rule is provided and the plan is paid in advance (and the subscription is not in a trial), the subscription is created in the `incomplete` state and is only activated once the gating payment succeeds. If the payment fails or the rule's `timeout_hours` elapses, the subscription is canceled.

src/schemas/SubscriptionObject.yaml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,15 @@ properties:
7575
description: |-
7676
The status of the subscription, which can have the following values:
7777
- `active`: the subscription is currently active and applied to the customer.
78-
- `canceled`: the subscription has been stopped before its activation. This can occur when two consecutive downgrades have been applied to a customer or when a subscription with a pending status is terminated.
78+
- `canceled`: the subscription has been stopped before its activation. This can occur when two consecutive downgrades have been applied to a customer, when a subscription with a pending status is terminated, or when a payment-gated subscription fails to be paid (or its activation rule expires) before activation. When caused by payment gating, the `cancellation_reason` field is set.
79+
- `incomplete`: the subscription was created with a payment activation rule and is waiting for the gating payment to succeed before it becomes `active`. It is automatically `canceled` if the payment fails or the activation rule expires.
7980
- `pending`: a previous subscription has been downgraded, and the current one is awaiting automatic activation at the end of the billing period.
8081
- `terminated`: the subscription is no longer active.
8182
example: active
8283
enum:
8384
- active
8485
- canceled
86+
- incomplete
8587
- pending
8688
- terminated
8789
created_at:
@@ -213,3 +215,30 @@ properties:
213215
214216
- `true` (default): the subscription is included in the customer's standard invoice grouping (by billing entity, currency and payment method).
215217
- `false`: the subscription is excluded from consolidation and always billed on its own dedicated invoice, regardless of other grouping criteria.
218+
cancellation_reason:
219+
type:
220+
- string
221+
- "null"
222+
example: "payment_failed"
223+
enum:
224+
- payment_failed
225+
- timeout
226+
description: |
227+
The reason a payment-gated subscription was canceled before activation. Null unless the subscription was canceled by payment gating.
228+
229+
- `payment_failed`: the gating payment failed.
230+
- `timeout`: the activation rule expired before the payment succeeded.
231+
activated_at:
232+
type:
233+
- string
234+
- "null"
235+
format: "date-time"
236+
example: "2022-08-08T00:00:00Z"
237+
description: |
238+
The date and time when a payment-gated subscription was activated (i.e. moved from `incomplete` to `active` once the gating payment succeeded), represented in ISO 8601 datetime format and expressed in Coordinated Universal Time (UTC). Null while the subscription is still `incomplete`.
239+
activation_rules:
240+
type: array
241+
items:
242+
$ref: "./SubscriptionActivationRuleObject.yaml"
243+
description: |
244+
The activation rules attached to the subscription. A payment activation rule gates activation on a successful first payment, keeping the subscription in the `incomplete` state until the payment succeeds or the rule expires.

0 commit comments

Comments
 (0)