-
Notifications
You must be signed in to change notification settings - Fork 13
/
ledger-entries.ts
389 lines (327 loc) · 11.6 KB
/
ledger-entries.ts
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import * as Core from '../core';
import { APIResource } from '../resource';
import { isRequestOptions } from '../core';
import * as LedgerEntriesAPI from './ledger-entries';
import * as Shared from './shared';
import { Page, type PageParams } from '../pagination';
export class LedgerEntries extends APIResource {
/**
* Get details on a single ledger entry.
*/
retrieve(
id: string,
query?: LedgerEntryRetrieveParams,
options?: Core.RequestOptions,
): Core.APIPromise<LedgerEntry>;
retrieve(id: string, options?: Core.RequestOptions): Core.APIPromise<LedgerEntry>;
retrieve(
id: string,
query: LedgerEntryRetrieveParams | Core.RequestOptions = {},
options?: Core.RequestOptions,
): Core.APIPromise<LedgerEntry> {
if (isRequestOptions(query)) {
return this.retrieve(id, {}, query);
}
return this._client.get(`/api/ledger_entries/${id}`, { query, ...options });
}
/**
* Update the details of a ledger entry.
*/
update(
id: string,
body?: LedgerEntryUpdateParams,
options?: Core.RequestOptions,
): Core.APIPromise<LedgerEntry>;
update(id: string, options?: Core.RequestOptions): Core.APIPromise<LedgerEntry>;
update(
id: string,
body: LedgerEntryUpdateParams | Core.RequestOptions = {},
options?: Core.RequestOptions,
): Core.APIPromise<LedgerEntry> {
if (isRequestOptions(body)) {
return this.update(id, {}, body);
}
return this._client.patch(`/api/ledger_entries/${id}`, { body, ...options });
}
/**
* Get a list of all ledger entries.
*/
list(
query?: LedgerEntryListParams,
options?: Core.RequestOptions,
): Core.PagePromise<LedgerEntriesPage, LedgerEntry>;
list(options?: Core.RequestOptions): Core.PagePromise<LedgerEntriesPage, LedgerEntry>;
list(
query: LedgerEntryListParams | Core.RequestOptions = {},
options?: Core.RequestOptions,
): Core.PagePromise<LedgerEntriesPage, LedgerEntry> {
if (isRequestOptions(query)) {
return this.list({}, query);
}
return this._client.getAPIList('/api/ledger_entries', LedgerEntriesPage, { query, ...options });
}
}
export class LedgerEntriesPage extends Page<LedgerEntry> {}
export interface LedgerEntry {
id: string;
/**
* Value in specified currency's smallest unit. e.g. $10 would be represented
* as 1000. Can be any integer up to 36 digits.
*/
amount: number;
created_at: string;
/**
* One of `credit`, `debit`. Describes the direction money is flowing in the
* transaction. A `credit` moves money from your account to someone else's. A
* `debit` pulls money from someone else's account to your own. Note that wire,
* rtp, and check payments will always be `credit`.
*/
direction: Shared.TransactionDirection;
discarded_at: string | null;
/**
* The currency of the ledger account.
*/
ledger_account_currency: string;
/**
* The currency exponent of the ledger account.
*/
ledger_account_currency_exponent: number;
/**
* The ledger account that this ledger entry is associated with.
*/
ledger_account_id: string;
/**
* Lock version of the ledger account. This can be passed when creating a ledger
* transaction to only succeed if no ledger transactions have posted since the
* given version. See our post about Designing the Ledgers API with Optimistic
* Locking for more details.
*/
ledger_account_lock_version: number | null;
/**
* The ledger transaction that this ledger entry is associated with.
*/
ledger_transaction_id: string;
/**
* This field will be true if this object exists in the live environment or false
* if it exists in the test environment.
*/
live_mode: boolean;
/**
* Additional data represented as key-value pairs. Both the key and value must be
* strings.
*/
metadata: Record<string, string>;
object: string;
/**
* The pending, posted, and available balances for this ledger entry's ledger
* account. The posted balance is the sum of all posted entries on the account. The
* pending balance is the sum of all pending and posted entries on the account. The
* available balance is the posted incoming entries minus the sum of the pending
* and posted outgoing amounts. Please see
* https://docs.moderntreasury.com/docs/transaction-status-and-balances for more
* details.
*/
resulting_ledger_account_balances: LedgerEntry.ResultingLedgerAccountBalances | null;
/**
* Equal to the state of the ledger transaction when the ledger entry was created.
* One of `pending`, `posted`, or `archived`.
*/
status: 'archived' | 'pending' | 'posted';
updated_at: string;
}
export namespace LedgerEntry {
/**
* The pending, posted, and available balances for this ledger entry's ledger
* account. The posted balance is the sum of all posted entries on the account. The
* pending balance is the sum of all pending and posted entries on the account. The
* available balance is the posted incoming entries minus the sum of the pending
* and posted outgoing amounts. Please see
* https://docs.moderntreasury.com/docs/transaction-status-and-balances for more
* details.
*/
export interface ResultingLedgerAccountBalances {
/**
* The available_balance is the sum of all posted inbound entries and pending
* outbound entries. For credit normal, available_amount = posted_credits -
* pending_debits; for debit normal, available_amount = posted_debits -
* pending_credits.
*/
available_balance: ResultingLedgerAccountBalances.AvailableBalance;
/**
* The pending_balance is the sum of all pending and posted entries.
*/
pending_balance: ResultingLedgerAccountBalances.PendingBalance;
/**
* The posted_balance is the sum of all posted entries.
*/
posted_balance: ResultingLedgerAccountBalances.PostedBalance;
}
export namespace ResultingLedgerAccountBalances {
/**
* The available_balance is the sum of all posted inbound entries and pending
* outbound entries. For credit normal, available_amount = posted_credits -
* pending_debits; for debit normal, available_amount = posted_debits -
* pending_credits.
*/
export interface AvailableBalance {
amount: number;
credits: number;
/**
* The currency of the ledger account.
*/
currency: string;
/**
* The currency exponent of the ledger account.
*/
currency_exponent: number;
debits: number;
}
/**
* The pending_balance is the sum of all pending and posted entries.
*/
export interface PendingBalance {
amount: number;
credits: number;
/**
* The currency of the ledger account.
*/
currency: string;
/**
* The currency exponent of the ledger account.
*/
currency_exponent: number;
debits: number;
}
/**
* The posted_balance is the sum of all posted entries.
*/
export interface PostedBalance {
amount: number;
credits: number;
/**
* The currency of the ledger account.
*/
currency: string;
/**
* The currency exponent of the ledger account.
*/
currency_exponent: number;
debits: number;
}
}
}
export interface LedgerEntryRetrieveParams {
/**
* If true, response will include the balances attached to the ledger entry. If
* there is no balance available, null will be returned instead.
*/
show_balances?: boolean;
}
export interface LedgerEntryUpdateParams {
/**
* Additional data represented as key-value pairs. Both the key and value must be
* strings.
*/
metadata?: Record<string, string>;
}
export interface LedgerEntryListParams extends PageParams {
/**
* If you have specific IDs to retrieve in bulk, you can pass them as query
* parameters delimited with `id[]=`, for example `?id[]=123&id[]=abc`.
*/
id?: Array<string>;
/**
* Shows all ledger entries that were present on a ledger account at a particular
* `lock_version`. You must also specify `ledger_account_id`.
*/
as_of_lock_version?: number;
/**
* If true, response will include ledger entries that were deleted. When you update
* a ledger transaction to specify a new set of entries, the previous entries are
* deleted.
*/
direction?: Shared.TransactionDirection;
/**
* Use `gt` (>), `gte` (>=), `lt` (<), `lte` (<=), or `eq` (=) to filter by the
* transaction's effective time. Format ISO8601
*/
effective_at?: Record<string, string>;
/**
* Use `gt` (>), `gte` (>=), `lt` (<), `lte` (<=), or `eq` (=) to filter by the
* transaction's effective date. Format YYYY-MM-DD
*/
effective_date?: Record<string, string>;
/**
* Get all ledger entries that match the direction specified. One of `credit`,
* `debit`.
*/
ledger_account_category_id?: string;
ledger_account_id?: string;
/**
* Use `gt` (>), `gte` (>=), `lt` (<), `lte` (<=), or `eq` (=) to filter by the
* lock_version of a ledger account. For example, for all entries created at or
* before before lock_version 1000 of a ledger account, use
* `ledger_account_lock_version%5Blte%5D=1000`.
*/
ledger_account_lock_version?: Record<string, number>;
ledger_account_payout_id?: string;
ledger_account_settlement_id?: string;
/**
* Get all ledger entries that are included in the ledger account statement.
*/
ledger_account_statement_id?: string;
ledger_transaction_id?: string;
/**
* For example, if you want to query for records with metadata key `Type` and value
* `Loan`, the query would be `metadata%5BType%5D=Loan`. This encodes the query
* parameters.
*/
metadata?: Record<string, string>;
/**
* Order by `created_at` or `effective_at` in `asc` or `desc` order. For example,
* to order by `effective_at asc`, use `order_by%5Beffective_at%5D=asc`. Ordering
* by only one field at a time is supported.
*/
order_by?: LedgerEntryListParams.OrderBy;
/**
* If true, response will include the balances attached to the ledger entry. If
* there is no balance available, null will be returned instead.
*/
show_balances?: boolean;
/**
* If true, response will include ledger entries that were deleted. When you update
* a ledger transaction to specify a new set of entries, the previous entries are
* deleted.
*/
show_deleted?: boolean;
/**
* Get all ledger entries that match the status specified. One of `pending`,
* `posted`, or `archived`.
*/
status?: 'pending' | 'posted' | 'archived';
/**
* Use `gt` (>), `gte` (>=), `lt` (<), `lte` (<=), or `eq` (=) to filter by the
* posted at timestamp. For example, for all times after Jan 1 2000 12:00 UTC, use
* updated_at%5Bgt%5D=2000-01-01T12:00:00Z.
*/
updated_at?: Record<string, string>;
}
export namespace LedgerEntryListParams {
/**
* Order by `created_at` or `effective_at` in `asc` or `desc` order. For example,
* to order by `effective_at asc`, use `order_by%5Beffective_at%5D=asc`. Ordering
* by only one field at a time is supported.
*/
export interface OrderBy {
created_at?: 'asc' | 'desc';
effective_at?: 'asc' | 'desc';
}
}
export namespace LedgerEntries {
export import LedgerEntry = LedgerEntriesAPI.LedgerEntry;
export import LedgerEntriesPage = LedgerEntriesAPI.LedgerEntriesPage;
export import LedgerEntryRetrieveParams = LedgerEntriesAPI.LedgerEntryRetrieveParams;
export import LedgerEntryUpdateParams = LedgerEntriesAPI.LedgerEntryUpdateParams;
export import LedgerEntryListParams = LedgerEntriesAPI.LedgerEntryListParams;
}