-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcredit-blocks.ts
More file actions
193 lines (157 loc) · 5.64 KB
/
credit-blocks.ts
File metadata and controls
193 lines (157 loc) · 5.64 KB
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
185
186
187
188
189
190
191
192
193
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../resource';
import * as Core from '../core';
import * as Shared from './shared';
/**
* The [Credit Ledger Entry resource](/product-catalog/prepurchase) models prepaid credits within Orb.
*/
export class CreditBlocks extends APIResource {
/**
* This endpoint returns a credit block identified by its block_id.
*/
retrieve(blockId: string, options?: Core.RequestOptions): Core.APIPromise<CreditBlockRetrieveResponse> {
return this._client.get(`/credit_blocks/${blockId}`, options);
}
/**
* This endpoint deletes a credit block by its ID.
*
* When a credit block is deleted:
*
* - The block is removed from the customer's credit ledger.
* - Any usage of the credit block is reversed, and the ledger is replayed as if
* the block never existed.
* - If invoices were generated from the purchase of the credit block, they will be
* deleted if in draft status, voided if issued, or a credit note will be issued
* if the invoice is paid.
*
* <Note>
* Issued invoices that had credits applied from this block will not be regenerated, but the ledger will
* reflect the state as if credits from the deleted block were never applied.
* </Note>
*/
delete(blockId: string, options?: Core.RequestOptions): Core.APIPromise<void> {
return this._client.delete(`/credit_blocks/${blockId}`, {
...options,
headers: { Accept: '*/*', ...options?.headers },
});
}
/**
* This endpoint returns the credit block and its associated purchasing invoices.
*
* If a credit block was purchased (as opposed to being manually added), this
* endpoint returns the invoices that were created to charge the customer for the
* credit block. For credit blocks with payment schedules spanning multiple periods
* (e.g., monthly payments over 12 months), multiple invoices will be returned.
*
* For credit blocks created by subscription allocation prices, this endpoint
* returns the subscription invoice containing the allocation line item that
* created the block.
*
* If the credit block was not purchased (e.g., manual increment), an empty
* invoices list is returned.
*
* **Note: This endpoint is currently experimental and its interface may change in
* future releases. Please contact support before building production integrations
* against this endpoint.**
*/
listInvoices(
blockId: string,
options?: Core.RequestOptions,
): Core.APIPromise<CreditBlockListInvoicesResponse> {
return this._client.get(`/credit_blocks/${blockId}/invoices`, options);
}
}
/**
* The Credit Block resource models prepaid credits within Orb.
*/
export interface CreditBlockRetrieveResponse {
id: string;
balance: number;
effective_date: string | null;
expiry_date: string | null;
filters: Array<CreditBlockRetrieveResponse.Filter>;
maximum_initial_balance: number | null;
/**
* User specified key-value pairs for the resource. If not present, this defaults
* to an empty dictionary. Individual keys can be removed by setting the value to
* `null`, and the entire metadata mapping can be cleared by setting `metadata` to
* `null`.
*/
metadata: { [key: string]: string };
per_unit_cost_basis: string | null;
status: 'active' | 'pending_payment';
}
export namespace CreditBlockRetrieveResponse {
export interface Filter {
/**
* The property of the price to filter on.
*/
field: 'price_id' | 'item_id' | 'price_type' | 'currency' | 'pricing_unit_id';
/**
* Should prices that match the filter be included or excluded.
*/
operator: 'includes' | 'excludes';
/**
* The IDs or values that match this filter.
*/
values: Array<string>;
}
}
export interface CreditBlockListInvoicesResponse {
/**
* The Credit Block resource models prepaid credits within Orb.
*/
block: CreditBlockListInvoicesResponse.Block;
invoices: Array<CreditBlockListInvoicesResponse.Invoice>;
}
export namespace CreditBlockListInvoicesResponse {
/**
* The Credit Block resource models prepaid credits within Orb.
*/
export interface Block {
id: string;
balance: number;
effective_date: string | null;
expiry_date: string | null;
filters: Array<Block.Filter>;
maximum_initial_balance: number | null;
/**
* User specified key-value pairs for the resource. If not present, this defaults
* to an empty dictionary. Individual keys can be removed by setting the value to
* `null`, and the entire metadata mapping can be cleared by setting `metadata` to
* `null`.
*/
metadata: { [key: string]: string };
per_unit_cost_basis: string | null;
status: 'active' | 'pending_payment';
}
export namespace Block {
export interface Filter {
/**
* The property of the price to filter on.
*/
field: 'price_id' | 'item_id' | 'price_type' | 'currency' | 'pricing_unit_id';
/**
* Should prices that match the filter be included or excluded.
*/
operator: 'includes' | 'excludes';
/**
* The IDs or values that match this filter.
*/
values: Array<string>;
}
}
export interface Invoice {
id: string;
customer: Shared.CustomerMinified;
invoice_number: string;
status: 'issued' | 'paid' | 'synced' | 'void' | 'draft';
subscription: Shared.SubscriptionMinified | null;
}
}
export declare namespace CreditBlocks {
export {
type CreditBlockRetrieveResponse as CreditBlockRetrieveResponse,
type CreditBlockListInvoicesResponse as CreditBlockListInvoicesResponse,
};
}