File size: 4,963 Bytes
1477a90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import "@typespec/openapi";
import "../shared/index.tsp";
import "../productcatalog/ratecard.tsp";

using TypeSpec.OpenAPI;

namespace Subscriptions;

/**
 * Subscription status.
 */
@friendlyName("BillingSubscriptionStatus")
enum SubscriptionStatus {
  Active: "active",
  Inactive: "inactive",
  Canceled: "canceled",
  Scheduled: "scheduled",
}

/**
 * Subscription edit timing. When immediate, the requested changes take effect
 * immediately. When next_billing_cycle, the requested changes take effect at the
 * next billing cycle.
 */
@friendlyName("BillingSubscriptionEditTimingEnum")
enum SubscriptionEditTimingEnum {
  Immediate: "immediate",
  NextBillingCycle: "next_billing_cycle",
}

/**
 * Subscription edit timing defined when the changes should take effect. If the
 * provided configuration is not supported by the subscription, an error will be
 * returned.
 */
@oneOf
@friendlyName("BillingSubscriptionEditTiming")
@example(SubscriptionEditTimingEnum.Immediate)
union SubscriptionEditTiming {
  Enum: SubscriptionEditTimingEnum,
  Custom: Shared.DateTime,
}

/**
 * Subscription create request.
 */
@friendlyName("BillingSubscriptionCreate")
model SubscriptionCreate {
  ...Shared.CreateRequest<OmitProperties<
    Subscription,
    "customer_id" | "plan_id" | "billing_anchor"
  >>;

  /**
   * The customer to create the subscription for.
   */
  customer: {
    /**
     * The ID of the customer to create the subscription for.
     *
     * Either customer ID or customer key must be provided. If both are provided, the
     * ID will be used.
     */
    @visibility(Lifecycle.Create)
    @summary("Customer ID")
    id?: Shared.ULID;

    /**
     * The key of the customer to create the subscription for.
     *
     * Either customer ID or customer key must be provided. If both are provided, the
     * ID will be used.
     */
    @visibility(Lifecycle.Create)
    @summary("Customer Key")
    key?: Shared.ExternalResourceKey;
  };

  /**
   * The plan reference of the subscription.
   */
  plan: {
    /**
     * The plan ID of the subscription. Set if subscription is created from a plan.
     *
     * ID or Key of the plan is required if creating a subscription from a plan. If
     * both are provided, the ID will be used.
     */
    @visibility(Lifecycle.Create)
    @summary("Plan ID")
    id?: Shared.ULID;

    /**
     * The plan Key of the subscription, if any. Set if subscription is created from a
     * plan.
     *
     * ID or Key of the plan is required if creating a subscription from a plan. If
     * both are provided, the ID will be used.
     */
    @visibility(Lifecycle.Create)
    @summary("Plan Key")
    key?: Shared.ResourceKey;

    /**
     * The plan version of the subscription, if any. If not provided, the latest
     * version of the plan will be used.
     */
    @visibility(Lifecycle.Create)
    @summary("Plan Version")
    version?: integer;
  };

  /**
   * A billing anchor is the fixed point in time that determines the subscription's
   * recurring billing cycle. It affects when charges occur and how prorations are
   * calculated. Common anchors:
   *
   * - Calendar month (1st of each month): `2025-01-01T00:00:00Z`
   * - Subscription anniversary (day customer signed up)
   * - Custom date (customer-specified day)
   *
   * If not provided, the subscription will be created with the subscription's
   * creation time as the billing anchor.
   */
  @visibility(Lifecycle.Create)
  @summary("Billing anchor")
  billing_anchor?: Shared.DateTime;
}

/**
 * Subscription.
 */
@friendlyName("BillingSubscription")
model Subscription {
  ...OmitProperties<Shared.Resource, "name" | "description">;

  /**
   * The customer ID of the subscription.
   */
  @visibility(Lifecycle.Read)
  @summary("Customer ID")
  customer_id: Shared.ULID;

  /**
   * The plan ID of the subscription. Set if subscription is created from a plan.
   */
  @visibility(Lifecycle.Read)
  @summary("Plan ID")
  plan_id?: Shared.ULID;

  /**
   * A billing anchor is the fixed point in time that determines the subscription's
   * recurring billing cycle. It affects when charges occur and how prorations are
   * calculated. Common anchors:
   *
   * - Calendar month (1st of each month): `2025-01-01T00:00:00Z`
   * - Subscription anniversary (day customer signed up)
   * - Custom date (customer-specified day)
   */
  @visibility(Lifecycle.Read)
  @summary("Billing anchor")
  billing_anchor: Shared.DateTime;

  /**
   * The status of the subscription.
   */
  @visibility(Lifecycle.Read)
  @summary("Status")
  status: SubscriptionStatus;

  /**
   * Settlement mode for billing.
   *
   * Values:
   *
   * - `credit_then_invoice`: Credits are applied first, then any remainder is
   *   invoiced.
   * - `credit_only`: Usage is settled exclusively against credits.
   */
  @visibility(Lifecycle.Create, Lifecycle.Read)
  @summary("Settlement Mode")
  settlement_mode?: ProductCatalog.SettlementMode;
}