orb-billing 5.48.0 → 5.76.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/CHANGELOG.md +249 -0
  2. package/core.js +2 -2
  3. package/core.js.map +1 -1
  4. package/core.mjs +2 -2
  5. package/core.mjs.map +1 -1
  6. package/index.d.ts.map +1 -1
  7. package/index.js +11 -0
  8. package/index.js.map +1 -1
  9. package/index.mjs +11 -0
  10. package/index.mjs.map +1 -1
  11. package/package.json +1 -1
  12. package/resources/alerts.d.ts +140 -3
  13. package/resources/alerts.d.ts.map +1 -1
  14. package/resources/alerts.js.map +1 -1
  15. package/resources/alerts.mjs.map +1 -1
  16. package/resources/beta/beta.d.ts +738 -7570
  17. package/resources/beta/beta.d.ts.map +1 -1
  18. package/resources/beta/beta.js.map +1 -1
  19. package/resources/beta/beta.mjs.map +1 -1
  20. package/resources/beta/external-plan-id.d.ts +664 -7572
  21. package/resources/beta/external-plan-id.d.ts.map +1 -1
  22. package/resources/coupons/coupons.d.ts +29 -0
  23. package/resources/coupons/coupons.d.ts.map +1 -1
  24. package/resources/coupons/coupons.js +21 -0
  25. package/resources/coupons/coupons.js.map +1 -1
  26. package/resources/coupons/coupons.mjs +21 -0
  27. package/resources/coupons/coupons.mjs.map +1 -1
  28. package/resources/coupons/subscriptions.d.ts +10 -0
  29. package/resources/coupons/subscriptions.d.ts.map +1 -1
  30. package/resources/coupons/subscriptions.js.map +1 -1
  31. package/resources/coupons/subscriptions.mjs.map +1 -1
  32. package/resources/credit-blocks.d.ts +138 -7
  33. package/resources/credit-blocks.d.ts.map +1 -1
  34. package/resources/credit-blocks.js +10 -7
  35. package/resources/credit-blocks.js.map +1 -1
  36. package/resources/credit-blocks.mjs +10 -7
  37. package/resources/credit-blocks.mjs.map +1 -1
  38. package/resources/credit-notes.d.ts +28 -0
  39. package/resources/credit-notes.d.ts.map +1 -1
  40. package/resources/credit-notes.js +20 -0
  41. package/resources/credit-notes.js.map +1 -1
  42. package/resources/credit-notes.mjs +20 -0
  43. package/resources/credit-notes.mjs.map +1 -1
  44. package/resources/customers/credits/credits.d.ts +129 -0
  45. package/resources/customers/credits/credits.d.ts.map +1 -1
  46. package/resources/customers/credits/credits.js.map +1 -1
  47. package/resources/customers/credits/credits.mjs.map +1 -1
  48. package/resources/customers/credits/ledger.d.ts +34 -20
  49. package/resources/customers/credits/ledger.d.ts.map +1 -1
  50. package/resources/customers/credits/ledger.js +28 -14
  51. package/resources/customers/credits/ledger.js.map +1 -1
  52. package/resources/customers/credits/ledger.mjs +28 -14
  53. package/resources/customers/credits/ledger.mjs.map +1 -1
  54. package/resources/customers/customers.d.ts +89 -6
  55. package/resources/customers/customers.d.ts.map +1 -1
  56. package/resources/customers/customers.js.map +1 -1
  57. package/resources/customers/customers.mjs.map +1 -1
  58. package/resources/dimensional-price-groups/dimensional-price-groups.d.ts +35 -1
  59. package/resources/dimensional-price-groups/dimensional-price-groups.d.ts.map +1 -1
  60. package/resources/dimensional-price-groups/dimensional-price-groups.js +26 -0
  61. package/resources/dimensional-price-groups/dimensional-price-groups.js.map +1 -1
  62. package/resources/dimensional-price-groups/dimensional-price-groups.mjs +26 -0
  63. package/resources/dimensional-price-groups/dimensional-price-groups.mjs.map +1 -1
  64. package/resources/dimensional-price-groups/external-dimensional-price-group-id.d.ts +16 -0
  65. package/resources/dimensional-price-groups/external-dimensional-price-group-id.d.ts.map +1 -1
  66. package/resources/dimensional-price-groups/external-dimensional-price-group-id.js +16 -0
  67. package/resources/dimensional-price-groups/external-dimensional-price-group-id.js.map +1 -1
  68. package/resources/dimensional-price-groups/external-dimensional-price-group-id.mjs +16 -0
  69. package/resources/dimensional-price-groups/external-dimensional-price-group-id.mjs.map +1 -1
  70. package/resources/events/backfills.d.ts +37 -0
  71. package/resources/events/backfills.d.ts.map +1 -1
  72. package/resources/events/backfills.js +29 -0
  73. package/resources/events/backfills.js.map +1 -1
  74. package/resources/events/backfills.mjs +29 -0
  75. package/resources/events/backfills.mjs.map +1 -1
  76. package/resources/events/events.d.ts +41 -33
  77. package/resources/events/events.d.ts.map +1 -1
  78. package/resources/events/events.js +39 -31
  79. package/resources/events/events.js.map +1 -1
  80. package/resources/events/events.mjs +39 -31
  81. package/resources/events/events.mjs.map +1 -1
  82. package/resources/events/volume.d.ts +7 -0
  83. package/resources/events/volume.d.ts.map +1 -1
  84. package/resources/events/volume.js +7 -0
  85. package/resources/events/volume.js.map +1 -1
  86. package/resources/events/volume.mjs +7 -0
  87. package/resources/events/volume.mjs.map +1 -1
  88. package/resources/invoice-line-items.d.ts +89 -1
  89. package/resources/invoice-line-items.d.ts.map +1 -1
  90. package/resources/invoice-line-items.js +12 -0
  91. package/resources/invoice-line-items.js.map +1 -1
  92. package/resources/invoice-line-items.mjs +12 -0
  93. package/resources/invoice-line-items.mjs.map +1 -1
  94. package/resources/invoices.d.ts +200 -12
  95. package/resources/invoices.d.ts.map +1 -1
  96. package/resources/invoices.js +64 -0
  97. package/resources/invoices.js.map +1 -1
  98. package/resources/invoices.mjs +64 -0
  99. package/resources/invoices.mjs.map +1 -1
  100. package/resources/items.d.ts +30 -0
  101. package/resources/items.d.ts.map +1 -1
  102. package/resources/items.js +22 -0
  103. package/resources/items.js.map +1 -1
  104. package/resources/items.mjs +22 -0
  105. package/resources/items.mjs.map +1 -1
  106. package/resources/licenses/external-licenses.d.ts +13 -1
  107. package/resources/licenses/external-licenses.d.ts.map +1 -1
  108. package/resources/licenses/external-licenses.js +12 -0
  109. package/resources/licenses/external-licenses.js.map +1 -1
  110. package/resources/licenses/external-licenses.mjs +12 -0
  111. package/resources/licenses/external-licenses.mjs.map +1 -1
  112. package/resources/licenses/licenses.d.ts +44 -0
  113. package/resources/licenses/licenses.d.ts.map +1 -1
  114. package/resources/licenses/licenses.js +44 -0
  115. package/resources/licenses/licenses.js.map +1 -1
  116. package/resources/licenses/licenses.mjs +44 -0
  117. package/resources/licenses/licenses.mjs.map +1 -1
  118. package/resources/licenses/usage.d.ts +17 -2
  119. package/resources/licenses/usage.d.ts.map +1 -1
  120. package/resources/licenses/usage.js +8 -0
  121. package/resources/licenses/usage.js.map +1 -1
  122. package/resources/licenses/usage.mjs +8 -0
  123. package/resources/licenses/usage.mjs.map +1 -1
  124. package/resources/metrics.d.ts +42 -5
  125. package/resources/metrics.d.ts.map +1 -1
  126. package/resources/metrics.js +27 -2
  127. package/resources/metrics.js.map +1 -1
  128. package/resources/metrics.mjs +27 -2
  129. package/resources/metrics.mjs.map +1 -1
  130. package/resources/plans/external-plan-id.d.ts +6 -2
  131. package/resources/plans/external-plan-id.d.ts.map +1 -1
  132. package/resources/plans/external-plan-id.js +2 -2
  133. package/resources/plans/external-plan-id.mjs +2 -2
  134. package/resources/plans/migrations.d.ts +42 -0
  135. package/resources/plans/migrations.d.ts.map +1 -1
  136. package/resources/plans/migrations.js.map +1 -1
  137. package/resources/plans/migrations.mjs.map +1 -1
  138. package/resources/plans/plans.d.ts +382 -3754
  139. package/resources/plans/plans.d.ts.map +1 -1
  140. package/resources/plans/plans.js +2 -2
  141. package/resources/plans/plans.js.map +1 -1
  142. package/resources/plans/plans.mjs +2 -2
  143. package/resources/plans/plans.mjs.map +1 -1
  144. package/resources/prices/external-price-id.d.ts +14 -0
  145. package/resources/prices/external-price-id.d.ts.map +1 -1
  146. package/resources/prices/external-price-id.js +14 -0
  147. package/resources/prices/external-price-id.js.map +1 -1
  148. package/resources/prices/external-price-id.mjs +14 -0
  149. package/resources/prices/external-price-id.mjs.map +1 -1
  150. package/resources/prices/prices.d.ts +1632 -393
  151. package/resources/prices/prices.d.ts.map +1 -1
  152. package/resources/prices/prices.js +46 -0
  153. package/resources/prices/prices.js.map +1 -1
  154. package/resources/prices/prices.mjs +46 -0
  155. package/resources/prices/prices.mjs.map +1 -1
  156. package/resources/shared.d.ts +922 -52
  157. package/resources/shared.d.ts.map +1 -1
  158. package/resources/shared.js.map +1 -1
  159. package/resources/shared.mjs.map +1 -1
  160. package/resources/subscription-changes.d.ts +72 -1
  161. package/resources/subscription-changes.d.ts.map +1 -1
  162. package/resources/subscription-changes.js.map +1 -1
  163. package/resources/subscription-changes.mjs.map +1 -1
  164. package/resources/subscriptions.d.ts +3075 -464
  165. package/resources/subscriptions.d.ts.map +1 -1
  166. package/resources/subscriptions.js +111 -0
  167. package/resources/subscriptions.js.map +1 -1
  168. package/resources/subscriptions.mjs +111 -0
  169. package/resources/subscriptions.mjs.map +1 -1
  170. package/src/core.ts +2 -2
  171. package/src/index.ts +12 -0
  172. package/src/resources/alerts.ts +161 -3
  173. package/src/resources/beta/beta.ts +828 -8988
  174. package/src/resources/beta/external-plan-id.ts +745 -8997
  175. package/src/resources/coupons/coupons.ts +29 -0
  176. package/src/resources/coupons/subscriptions.ts +10 -0
  177. package/src/resources/credit-blocks.ts +166 -7
  178. package/src/resources/credit-notes.ts +28 -0
  179. package/src/resources/customers/credits/credits.ts +157 -0
  180. package/src/resources/customers/credits/ledger.ts +34 -20
  181. package/src/resources/customers/customers.ts +99 -6
  182. package/src/resources/dimensional-price-groups/dimensional-price-groups.ts +35 -1
  183. package/src/resources/dimensional-price-groups/external-dimensional-price-group-id.ts +16 -0
  184. package/src/resources/events/backfills.ts +37 -0
  185. package/src/resources/events/events.ts +41 -33
  186. package/src/resources/events/volume.ts +7 -0
  187. package/src/resources/invoice-line-items.ts +104 -0
  188. package/src/resources/invoices.ts +215 -11
  189. package/src/resources/items.ts +30 -0
  190. package/src/resources/licenses/external-licenses.ts +13 -1
  191. package/src/resources/licenses/licenses.ts +44 -0
  192. package/src/resources/licenses/usage.ts +17 -2
  193. package/src/resources/metrics.ts +43 -5
  194. package/src/resources/plans/external-plan-id.ts +7 -2
  195. package/src/resources/plans/migrations.ts +42 -0
  196. package/src/resources/plans/plans.ts +456 -4482
  197. package/src/resources/prices/external-price-id.ts +14 -0
  198. package/src/resources/prices/prices.ts +1743 -264
  199. package/src/resources/shared.ts +1172 -50
  200. package/src/resources/subscription-changes.ts +88 -1
  201. package/src/resources/subscriptions.ts +4707 -1585
  202. package/src/version.ts +1 -1
  203. package/version.d.ts +1 -1
  204. package/version.js +1 -1
  205. package/version.mjs +1 -1
@@ -17,6 +17,17 @@ export class Coupons extends APIResource {
17
17
  /**
18
18
  * This endpoint allows the creation of coupons, which can then be redeemed at
19
19
  * subscription creation or plan change.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * const coupon = await client.coupons.create({
24
+ * discount: {
25
+ * discount_type: 'percentage',
26
+ * percentage_discount: 0,
27
+ * },
28
+ * redemption_code: 'HALFOFF',
29
+ * });
30
+ * ```
20
31
  */
21
32
  create(body: CouponCreateParams, options?: Core.RequestOptions): Core.APIPromise<Coupon> {
22
33
  return this._client.post('/coupons', { body, ...options });
@@ -28,6 +39,14 @@ export class Coupons extends APIResource {
28
39
  * The list of coupons is ordered starting from the most recently created coupon.
29
40
  * The response also includes `pagination_metadata`, which lets the caller retrieve
30
41
  * the next page of results if they exist.
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * // Automatically fetches more pages as needed.
46
+ * for await (const coupon of client.coupons.list()) {
47
+ * // ...
48
+ * }
49
+ * ```
31
50
  */
32
51
  list(query?: CouponListParams, options?: Core.RequestOptions): Core.PagePromise<CouponsPage, Coupon>;
33
52
  list(options?: Core.RequestOptions): Core.PagePromise<CouponsPage, Coupon>;
@@ -45,6 +64,11 @@ export class Coupons extends APIResource {
45
64
  * This endpoint allows a coupon to be archived. Archived coupons can no longer be
46
65
  * redeemed, and will be hidden from lists of active coupons. Additionally, once a
47
66
  * coupon is archived, its redemption code can be reused for a different coupon.
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * const coupon = await client.coupons.archive('coupon_id');
71
+ * ```
48
72
  */
49
73
  archive(couponId: string, options?: Core.RequestOptions): Core.APIPromise<Coupon> {
50
74
  return this._client.post(`/coupons/${couponId}/archive`, options);
@@ -54,6 +78,11 @@ export class Coupons extends APIResource {
54
78
  * This endpoint retrieves a coupon by its ID. To fetch coupons by their redemption
55
79
  * code, use the [List coupons](list-coupons) endpoint with the redemption_code
56
80
  * parameter.
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * const coupon = await client.coupons.fetch('coupon_id');
85
+ * ```
57
86
  */
58
87
  fetch(couponId: string, options?: Core.RequestOptions): Core.APIPromise<Coupon> {
59
88
  return this._client.get(`/coupons/${couponId}`, options);
@@ -16,6 +16,16 @@ export class Subscriptions extends APIResource {
16
16
  * coupon as a [paginated](/api-reference/pagination) list, ordered starting from
17
17
  * the most recently created subscription. For a full discussion of the
18
18
  * subscription resource, see [Subscription](/core-concepts#subscription).
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * // Automatically fetches more pages as needed.
23
+ * for await (const subscription of client.coupons.subscriptions.list(
24
+ * 'coupon_id',
25
+ * )) {
26
+ * // ...
27
+ * }
28
+ * ```
19
29
  */
20
30
  list(
21
31
  couponId: string,
@@ -42,14 +42,17 @@ export class CreditBlocks extends APIResource {
42
42
  /**
43
43
  * This endpoint returns the credit block and its associated purchasing invoices.
44
44
  *
45
- * If a credit block was purchased (as opposed to being manually added or allocated
46
- * from a subscription), this endpoint returns the invoices that were created to
47
- * charge the customer for the credit block. For credit blocks with payment
48
- * schedules spanning multiple periods (e.g., monthly payments over 12 months),
49
- * multiple invoices will be returned.
45
+ * If a credit block was purchased (as opposed to being manually added), this
46
+ * endpoint returns the invoices that were created to charge the customer for the
47
+ * credit block. For credit blocks with payment schedules spanning multiple periods
48
+ * (e.g., monthly payments over 12 months), multiple invoices will be returned.
50
49
  *
51
- * If the credit block was not purchased (e.g., manual increment, allocation), an
52
- * empty invoices list is returned.
50
+ * For credit blocks created by subscription allocation prices, this endpoint
51
+ * returns the subscription invoice containing the allocation line item that
52
+ * created the block.
53
+ *
54
+ * If the credit block was not purchased (e.g., manual increment), an empty
55
+ * invoices list is returned.
53
56
  *
54
57
  * **Note: This endpoint is currently experimental and its interface may change in
55
58
  * future releases. Please contact support before building production integrations
@@ -71,6 +74,15 @@ export interface CreditBlockRetrieveResponse {
71
74
 
72
75
  balance: number;
73
76
 
77
+ /**
78
+ * How this credit block was created: `allocation` (a subscription's recurring
79
+ * credit allocation), `top_up` (an automatic balance-threshold top-up),
80
+ * `commitment` (a subscription commitment true-up rolled forward as credit), or
81
+ * `manual` (a manual credit ledger increment, including credits voided or expired
82
+ * off another block).
83
+ */
84
+ credit_block_source: 'allocation' | 'top_up' | 'commitment' | 'manual';
85
+
74
86
  effective_date: string | null;
75
87
 
76
88
  expiry_date: string | null;
@@ -90,6 +102,18 @@ export interface CreditBlockRetrieveResponse {
90
102
  per_unit_cost_basis: string | null;
91
103
 
92
104
  status: 'active' | 'pending_payment';
105
+
106
+ /**
107
+ * The credit allocation that funded a block. Extends the allocation resource
108
+ * serialized on prices with the catalog-item attribution of the funding price.
109
+ */
110
+ credit_allocation?: CreditBlockRetrieveResponse.CreditAllocation | null;
111
+
112
+ /**
113
+ * The subscription commitment whose true-up rolled forward into this credit block.
114
+ * Present only when `credit_block_source` is `commitment`.
115
+ */
116
+ credit_commitment?: CreditBlockRetrieveResponse.CreditCommitment | null;
93
117
  }
94
118
 
95
119
  export namespace CreditBlockRetrieveResponse {
@@ -109,6 +133,63 @@ export namespace CreditBlockRetrieveResponse {
109
133
  */
110
134
  values: Array<string>;
111
135
  }
136
+
137
+ /**
138
+ * The credit allocation that funded a block. Extends the allocation resource
139
+ * serialized on prices with the catalog-item attribution of the funding price.
140
+ */
141
+ export interface CreditAllocation {
142
+ allows_rollover: boolean;
143
+
144
+ currency: string;
145
+
146
+ custom_expiration: Shared.CustomExpiration | null;
147
+
148
+ /**
149
+ * The ID of the catalog item this block was allocated from, derived from the
150
+ * allocation's price.
151
+ */
152
+ item_id: string;
153
+
154
+ filters?: Array<CreditAllocation.Filter>;
155
+
156
+ license_type_id?: string | null;
157
+ }
158
+
159
+ export namespace CreditAllocation {
160
+ export interface Filter {
161
+ /**
162
+ * The property of the price to filter on.
163
+ */
164
+ field: 'price_id' | 'item_id' | 'price_type' | 'currency' | 'pricing_unit_id';
165
+
166
+ /**
167
+ * Should prices that match the filter be included or excluded.
168
+ */
169
+ operator: 'includes' | 'excludes';
170
+
171
+ /**
172
+ * The IDs or values that match this filter.
173
+ */
174
+ values: Array<string>;
175
+ }
176
+ }
177
+
178
+ /**
179
+ * The subscription commitment whose true-up rolled forward into this credit block.
180
+ * Present only when `credit_block_source` is `commitment`.
181
+ */
182
+ export interface CreditCommitment {
183
+ /**
184
+ * The ID of the subscription commitment this block was rolled forward from.
185
+ */
186
+ id: string;
187
+
188
+ /**
189
+ * The subscription the commitment belongs to.
190
+ */
191
+ subscription_id?: string | null;
192
+ }
112
193
  }
113
194
 
114
195
  export interface CreditBlockListInvoicesResponse {
@@ -129,6 +210,15 @@ export namespace CreditBlockListInvoicesResponse {
129
210
 
130
211
  balance: number;
131
212
 
213
+ /**
214
+ * How this credit block was created: `allocation` (a subscription's recurring
215
+ * credit allocation), `top_up` (an automatic balance-threshold top-up),
216
+ * `commitment` (a subscription commitment true-up rolled forward as credit), or
217
+ * `manual` (a manual credit ledger increment, including credits voided or expired
218
+ * off another block).
219
+ */
220
+ credit_block_source: 'allocation' | 'top_up' | 'commitment' | 'manual';
221
+
132
222
  effective_date: string | null;
133
223
 
134
224
  expiry_date: string | null;
@@ -148,6 +238,18 @@ export namespace CreditBlockListInvoicesResponse {
148
238
  per_unit_cost_basis: string | null;
149
239
 
150
240
  status: 'active' | 'pending_payment';
241
+
242
+ /**
243
+ * The credit allocation that funded a block. Extends the allocation resource
244
+ * serialized on prices with the catalog-item attribution of the funding price.
245
+ */
246
+ credit_allocation?: Block.CreditAllocation | null;
247
+
248
+ /**
249
+ * The subscription commitment whose true-up rolled forward into this credit block.
250
+ * Present only when `credit_block_source` is `commitment`.
251
+ */
252
+ credit_commitment?: Block.CreditCommitment | null;
151
253
  }
152
254
 
153
255
  export namespace Block {
@@ -167,6 +269,63 @@ export namespace CreditBlockListInvoicesResponse {
167
269
  */
168
270
  values: Array<string>;
169
271
  }
272
+
273
+ /**
274
+ * The credit allocation that funded a block. Extends the allocation resource
275
+ * serialized on prices with the catalog-item attribution of the funding price.
276
+ */
277
+ export interface CreditAllocation {
278
+ allows_rollover: boolean;
279
+
280
+ currency: string;
281
+
282
+ custom_expiration: Shared.CustomExpiration | null;
283
+
284
+ /**
285
+ * The ID of the catalog item this block was allocated from, derived from the
286
+ * allocation's price.
287
+ */
288
+ item_id: string;
289
+
290
+ filters?: Array<CreditAllocation.Filter>;
291
+
292
+ license_type_id?: string | null;
293
+ }
294
+
295
+ export namespace CreditAllocation {
296
+ export interface Filter {
297
+ /**
298
+ * The property of the price to filter on.
299
+ */
300
+ field: 'price_id' | 'item_id' | 'price_type' | 'currency' | 'pricing_unit_id';
301
+
302
+ /**
303
+ * Should prices that match the filter be included or excluded.
304
+ */
305
+ operator: 'includes' | 'excludes';
306
+
307
+ /**
308
+ * The IDs or values that match this filter.
309
+ */
310
+ values: Array<string>;
311
+ }
312
+ }
313
+
314
+ /**
315
+ * The subscription commitment whose true-up rolled forward into this credit block.
316
+ * Present only when `credit_block_source` is `commitment`.
317
+ */
318
+ export interface CreditCommitment {
319
+ /**
320
+ * The ID of the subscription commitment this block was rolled forward from.
321
+ */
322
+ id: string;
323
+
324
+ /**
325
+ * The subscription the commitment belongs to.
326
+ */
327
+ subscription_id?: string | null;
328
+ }
170
329
  }
171
330
 
172
331
  export interface Invoice {
@@ -40,6 +40,19 @@ export class CreditNotes extends APIResource {
40
40
  * Note: Both start_date and end_date are inclusive - the service period will cover
41
41
  * both the start date and end date completely (from start of start_date to end of
42
42
  * end_date).
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * const creditNote = await client.creditNotes.create({
47
+ * line_items: [
48
+ * {
49
+ * amount: 'amount',
50
+ * invoice_line_item_id: '4khy3nwzktxv7',
51
+ * },
52
+ * ],
53
+ * reason: 'duplicate',
54
+ * });
55
+ * ```
43
56
  */
44
57
  create(body: CreditNoteCreateParams, options?: Core.RequestOptions): Core.APIPromise<Shared.CreditNote> {
45
58
  return this._client.post('/credit_notes', { body, ...options });
@@ -49,6 +62,14 @@ export class CreditNotes extends APIResource {
49
62
  * Get a paginated list of CreditNotes. Users can also filter by customer_id,
50
63
  * subscription_id, or external_customer_id. The credit notes will be returned in
51
64
  * reverse chronological order by `creation_time`.
65
+ *
66
+ * @example
67
+ * ```ts
68
+ * // Automatically fetches more pages as needed.
69
+ * for await (const creditNote of client.creditNotes.list()) {
70
+ * // ...
71
+ * }
72
+ * ```
52
73
  */
53
74
  list(
54
75
  query?: CreditNoteListParams,
@@ -68,6 +89,13 @@ export class CreditNotes extends APIResource {
68
89
  /**
69
90
  * This endpoint is used to fetch a single [`Credit Note`](/invoicing/credit-notes)
70
91
  * given an identifier.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * const creditNote = await client.creditNotes.fetch(
96
+ * 'credit_note_id',
97
+ * );
98
+ * ```
71
99
  */
72
100
  fetch(creditNoteId: string, options?: Core.RequestOptions): Core.APIPromise<Shared.CreditNote> {
73
101
  return this._client.get(`/credit_notes/${creditNoteId}`, options);
@@ -3,6 +3,7 @@
3
3
  import { APIResource } from '../../../resource';
4
4
  import { isRequestOptions } from '../../../core';
5
5
  import * as Core from '../../../core';
6
+ import * as Shared from '../../shared';
6
7
  import * as LedgerAPI from './ledger';
7
8
  import {
8
9
  AffectedBlock,
@@ -134,6 +135,15 @@ export interface CreditListResponse {
134
135
 
135
136
  balance: number;
136
137
 
138
+ /**
139
+ * How this credit block was created: `allocation` (a subscription's recurring
140
+ * credit allocation), `top_up` (an automatic balance-threshold top-up),
141
+ * `commitment` (a subscription commitment true-up rolled forward as credit), or
142
+ * `manual` (a manual credit ledger increment, including credits voided or expired
143
+ * off another block).
144
+ */
145
+ credit_block_source: 'allocation' | 'top_up' | 'commitment' | 'manual';
146
+
137
147
  effective_date: string | null;
138
148
 
139
149
  expiry_date: string | null;
@@ -153,6 +163,18 @@ export interface CreditListResponse {
153
163
  per_unit_cost_basis: string | null;
154
164
 
155
165
  status: 'active' | 'pending_payment';
166
+
167
+ /**
168
+ * The credit allocation that funded a block. Extends the allocation resource
169
+ * serialized on prices with the catalog-item attribution of the funding price.
170
+ */
171
+ credit_allocation?: CreditListResponse.CreditAllocation | null;
172
+
173
+ /**
174
+ * The subscription commitment whose true-up rolled forward into this credit block.
175
+ * Present only when `credit_block_source` is `commitment`.
176
+ */
177
+ credit_commitment?: CreditListResponse.CreditCommitment | null;
156
178
  }
157
179
 
158
180
  export namespace CreditListResponse {
@@ -175,6 +197,63 @@ export namespace CreditListResponse {
175
197
  */
176
198
  values: Array<string>;
177
199
  }
200
+
201
+ /**
202
+ * The credit allocation that funded a block. Extends the allocation resource
203
+ * serialized on prices with the catalog-item attribution of the funding price.
204
+ */
205
+ export interface CreditAllocation {
206
+ allows_rollover: boolean;
207
+
208
+ currency: string;
209
+
210
+ custom_expiration: Shared.CustomExpiration | null;
211
+
212
+ /**
213
+ * The ID of the catalog item this block was allocated from, derived from the
214
+ * allocation's price.
215
+ */
216
+ item_id: string;
217
+
218
+ filters?: Array<CreditAllocation.Filter>;
219
+
220
+ license_type_id?: string | null;
221
+ }
222
+
223
+ export namespace CreditAllocation {
224
+ export interface Filter {
225
+ /**
226
+ * The property of the price to filter on.
227
+ */
228
+ field: 'price_id' | 'item_id' | 'price_type' | 'currency' | 'pricing_unit_id';
229
+
230
+ /**
231
+ * Should prices that match the filter be included or excluded.
232
+ */
233
+ operator: 'includes' | 'excludes';
234
+
235
+ /**
236
+ * The IDs or values that match this filter.
237
+ */
238
+ values: Array<string>;
239
+ }
240
+ }
241
+
242
+ /**
243
+ * The subscription commitment whose true-up rolled forward into this credit block.
244
+ * Present only when `credit_block_source` is `commitment`.
245
+ */
246
+ export interface CreditCommitment {
247
+ /**
248
+ * The ID of the subscription commitment this block was rolled forward from.
249
+ */
250
+ id: string;
251
+
252
+ /**
253
+ * The subscription the commitment belongs to.
254
+ */
255
+ subscription_id?: string | null;
256
+ }
178
257
  }
179
258
 
180
259
  export interface CreditListByExternalIDResponse {
@@ -182,6 +261,15 @@ export interface CreditListByExternalIDResponse {
182
261
 
183
262
  balance: number;
184
263
 
264
+ /**
265
+ * How this credit block was created: `allocation` (a subscription's recurring
266
+ * credit allocation), `top_up` (an automatic balance-threshold top-up),
267
+ * `commitment` (a subscription commitment true-up rolled forward as credit), or
268
+ * `manual` (a manual credit ledger increment, including credits voided or expired
269
+ * off another block).
270
+ */
271
+ credit_block_source: 'allocation' | 'top_up' | 'commitment' | 'manual';
272
+
185
273
  effective_date: string | null;
186
274
 
187
275
  expiry_date: string | null;
@@ -201,6 +289,18 @@ export interface CreditListByExternalIDResponse {
201
289
  per_unit_cost_basis: string | null;
202
290
 
203
291
  status: 'active' | 'pending_payment';
292
+
293
+ /**
294
+ * The credit allocation that funded a block. Extends the allocation resource
295
+ * serialized on prices with the catalog-item attribution of the funding price.
296
+ */
297
+ credit_allocation?: CreditListByExternalIDResponse.CreditAllocation | null;
298
+
299
+ /**
300
+ * The subscription commitment whose true-up rolled forward into this credit block.
301
+ * Present only when `credit_block_source` is `commitment`.
302
+ */
303
+ credit_commitment?: CreditListByExternalIDResponse.CreditCommitment | null;
204
304
  }
205
305
 
206
306
  export namespace CreditListByExternalIDResponse {
@@ -223,6 +323,63 @@ export namespace CreditListByExternalIDResponse {
223
323
  */
224
324
  values: Array<string>;
225
325
  }
326
+
327
+ /**
328
+ * The credit allocation that funded a block. Extends the allocation resource
329
+ * serialized on prices with the catalog-item attribution of the funding price.
330
+ */
331
+ export interface CreditAllocation {
332
+ allows_rollover: boolean;
333
+
334
+ currency: string;
335
+
336
+ custom_expiration: Shared.CustomExpiration | null;
337
+
338
+ /**
339
+ * The ID of the catalog item this block was allocated from, derived from the
340
+ * allocation's price.
341
+ */
342
+ item_id: string;
343
+
344
+ filters?: Array<CreditAllocation.Filter>;
345
+
346
+ license_type_id?: string | null;
347
+ }
348
+
349
+ export namespace CreditAllocation {
350
+ export interface Filter {
351
+ /**
352
+ * The property of the price to filter on.
353
+ */
354
+ field: 'price_id' | 'item_id' | 'price_type' | 'currency' | 'pricing_unit_id';
355
+
356
+ /**
357
+ * Should prices that match the filter be included or excluded.
358
+ */
359
+ operator: 'includes' | 'excludes';
360
+
361
+ /**
362
+ * The IDs or values that match this filter.
363
+ */
364
+ values: Array<string>;
365
+ }
366
+ }
367
+
368
+ /**
369
+ * The subscription commitment whose true-up rolled forward into this credit block.
370
+ * Present only when `credit_block_source` is `commitment`.
371
+ */
372
+ export interface CreditCommitment {
373
+ /**
374
+ * The ID of the subscription commitment this block was rolled forward from.
375
+ */
376
+ id: string;
377
+
378
+ /**
379
+ * The subscription the commitment belongs to.
380
+ */
381
+ subscription_id?: string | null;
382
+ }
226
383
  }
227
384
 
228
385
  export interface CreditListParams extends PageParams {
@@ -155,8 +155,9 @@ export class Ledger extends APIResource {
155
155
  * }
156
156
  * ```
157
157
  *
158
- * Note that by default, Orb will always first increment any _negative_ balance in
159
- * existing blocks before adding the remaining amount to the desired credit block.
158
+ * Note that an `increment` entry always creates a new credit block (defined by the
159
+ * optional `effective_date` and `expiry_date`); it never modifies an existing
160
+ * block.
160
161
  *
161
162
  * ### Invoicing for credits
162
163
  *
@@ -177,11 +178,17 @@ export class Ledger extends APIResource {
177
178
  * ## Deducting Credits
178
179
  *
179
180
  * Orb allows you to deduct credits from a customer by creating an entry of type
180
- * `decrement`. Orb matches the algorithm for automatic deductions for determining
181
- * which credit blocks to decrement from. In the case that the deduction leads to
182
- * multiple ledger entries, the response from this endpoint will be the final
183
- * deduction. Orb also optionally allows specifying a description to assist with
184
- * auditing.
181
+ * `decrement`. A `decrement` entry records credits as usage and immediately
182
+ * recognizes revenue at the block's `per_unit_cost_basis`.
183
+ *
184
+ * For most credit removals, use `void` (no revenue impact) or `expiration_change`
185
+ * (revenue recognized on expiration) instead. Only use `decrement` when credits
186
+ * were genuinely consumed outside of normal event ingestion.
187
+ *
188
+ * Orb matches the algorithm for automatic deductions for determining which credit
189
+ * blocks to decrement from. In the case that the deduction leads to multiple
190
+ * ledger entries, the response from this endpoint will be the final deduction. Orb
191
+ * also optionally allows specifying a description to assist with auditing.
185
192
  *
186
193
  * The following snippet illustrates a sample request body to decrement credits.
187
194
  *
@@ -282,8 +289,9 @@ export class Ledger extends APIResource {
282
289
  * }
283
290
  * ```
284
291
  *
285
- * Note that by default, Orb will always first increment any _negative_ balance in
286
- * existing blocks before adding the remaining amount to the desired credit block.
292
+ * Note that an `increment` entry always creates a new credit block (defined by the
293
+ * optional `effective_date` and `expiry_date`); it never modifies an existing
294
+ * block.
287
295
  *
288
296
  * ### Invoicing for credits
289
297
  *
@@ -304,11 +312,17 @@ export class Ledger extends APIResource {
304
312
  * ## Deducting Credits
305
313
  *
306
314
  * Orb allows you to deduct credits from a customer by creating an entry of type
307
- * `decrement`. Orb matches the algorithm for automatic deductions for determining
308
- * which credit blocks to decrement from. In the case that the deduction leads to
309
- * multiple ledger entries, the response from this endpoint will be the final
310
- * deduction. Orb also optionally allows specifying a description to assist with
311
- * auditing.
315
+ * `decrement`. A `decrement` entry records credits as usage and immediately
316
+ * recognizes revenue at the block's `per_unit_cost_basis`.
317
+ *
318
+ * For most credit removals, use `void` (no revenue impact) or `expiration_change`
319
+ * (revenue recognized on expiration) instead. Only use `decrement` when credits
320
+ * were genuinely consumed outside of normal event ingestion.
321
+ *
322
+ * Orb matches the algorithm for automatic deductions for determining which credit
323
+ * blocks to decrement from. In the case that the deduction leads to multiple
324
+ * ledger entries, the response from this endpoint will be the final deduction. Orb
325
+ * also optionally allows specifying a description to assist with auditing.
312
326
  *
313
327
  * The following snippet illustrates a sample request body to decrement credits.
314
328
  *
@@ -1040,9 +1054,9 @@ export declare namespace LedgerCreateEntryParams {
1040
1054
  entry_type: 'expiration_change';
1041
1055
 
1042
1056
  /**
1043
- * A future date (specified in YYYY-MM-DD format) used for expiration change,
1044
- * denoting when credits transferred (as part of a partial block expiration) should
1045
- * expire.
1057
+ * A date (specified in YYYY-MM-DD format) used for expiration change, denoting
1058
+ * when credits transferred (as part of a partial block expiration) should expire.
1059
+ * This date must be on or after the effective date of the credit block.
1046
1060
  */
1047
1061
  target_expiry_date: string;
1048
1062
 
@@ -1344,9 +1358,9 @@ export declare namespace LedgerCreateEntryByExternalIDParams {
1344
1358
  entry_type: 'expiration_change';
1345
1359
 
1346
1360
  /**
1347
- * A future date (specified in YYYY-MM-DD format) used for expiration change,
1348
- * denoting when credits transferred (as part of a partial block expiration) should
1349
- * expire.
1361
+ * A date (specified in YYYY-MM-DD format) used for expiration change, denoting
1362
+ * when credits transferred (as part of a partial block expiration) should expire.
1363
+ * This date must be on or after the effective date of the credit block.
1350
1364
  */
1351
1365
  target_expiry_date: string;
1352
1366