-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbalance-transactions.ts
More file actions
223 lines (190 loc) · 7.03 KB
/
balance-transactions.ts
File metadata and controls
223 lines (190 loc) · 7.03 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
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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../../resource';
import { isRequestOptions } from '../../core';
import * as Core from '../../core';
import * as Shared from '../shared';
import { Page, type PageParams } from '../../pagination';
/**
* A customer is a buyer of your products, and the other party to the billing relationship.
*
* In Orb, customers are assigned system generated identifiers automatically, but it's often desirable to have these
* match existing identifiers in your system. To avoid having to denormalize Orb ID information, you can pass in an
* `external_customer_id` with your own identifier. See
* [Customer ID Aliases](/events-and-metrics/customer-aliases) for further information about how these
* aliases work in Orb.
*
* In addition to having an identifier in your system, a customer may exist in a payment provider solution like
* Stripe. Use the `payment_provider_id` and the `payment_provider` enum field to express this mapping.
*
* A customer also has a timezone (from the standard [IANA timezone database](https://www.iana.org/time-zones)), which
* defaults to your account's timezone. See [Timezone localization](/essentials/timezones) for
* information on what this timezone parameter influences within Orb.
*/
export class BalanceTransactions extends APIResource {
/**
* Creates an immutable balance transaction that updates the customer's balance and
* returns back the newly created transaction.
*/
create(
customerId: string,
body: BalanceTransactionCreateParams,
options?: Core.RequestOptions,
): Core.APIPromise<BalanceTransactionCreateResponse> {
return this._client.post(`/customers/${customerId}/balance_transactions`, { body, ...options });
}
/**
* ## The customer balance
*
* The customer balance is an amount in the customer's currency, which Orb
* automatically applies to subsequent invoices. This balance can be adjusted
* manually via Orb's webapp on the customer details page. You can use this balance
* to provide a fixed mid-period credit to the customer. Commonly, this is done due
* to system downtime/SLA violation, or an adhoc adjustment discussed with the
* customer.
*
* If the balance is a positive value at the time of invoicing, it represents that
* the customer has credit that should be used to offset the amount due on the next
* issued invoice. In this case, Orb will automatically reduce the next invoice by
* the balance amount, and roll over any remaining balance if the invoice is fully
* discounted.
*
* If the balance is a negative value at the time of invoicing, Orb will increase
* the invoice's amount due with a positive adjustment, and reset the balance to 0.
*
* This endpoint retrieves all customer balance transactions in reverse
* chronological order for a single customer, providing a complete audit trail of
* all adjustments and invoice applications.
*/
list(
customerId: string,
query?: BalanceTransactionListParams,
options?: Core.RequestOptions,
): Core.PagePromise<BalanceTransactionListResponsesPage, BalanceTransactionListResponse>;
list(
customerId: string,
options?: Core.RequestOptions,
): Core.PagePromise<BalanceTransactionListResponsesPage, BalanceTransactionListResponse>;
list(
customerId: string,
query: BalanceTransactionListParams | Core.RequestOptions = {},
options?: Core.RequestOptions,
): Core.PagePromise<BalanceTransactionListResponsesPage, BalanceTransactionListResponse> {
if (isRequestOptions(query)) {
return this.list(customerId, {}, query);
}
return this._client.getAPIList(
`/customers/${customerId}/balance_transactions`,
BalanceTransactionListResponsesPage,
{ query, ...options },
);
}
}
export class BalanceTransactionListResponsesPage extends Page<BalanceTransactionListResponse> {}
export interface BalanceTransactionCreateResponse {
/**
* A unique id for this transaction.
*/
id: string;
action:
| 'applied_to_invoice'
| 'manual_adjustment'
| 'prorated_refund'
| 'revert_prorated_refund'
| 'return_from_voiding'
| 'credit_note_applied'
| 'credit_note_voided'
| 'overpayment_refund'
| 'external_payment'
| 'small_invoice_carryover';
/**
* The value of the amount changed in the transaction.
*/
amount: string;
/**
* The creation time of this transaction.
*/
created_at: string;
credit_note: Shared.CreditNoteTiny | null;
/**
* An optional description provided for manual customer balance adjustments.
*/
description: string | null;
/**
* The new value of the customer's balance prior to the transaction, in the
* customer's currency.
*/
ending_balance: string;
invoice: Shared.InvoiceTiny | null;
/**
* The original value of the customer's balance prior to the transaction, in the
* customer's currency.
*/
starting_balance: string;
type: 'increment' | 'decrement';
}
export interface BalanceTransactionListResponse {
/**
* A unique id for this transaction.
*/
id: string;
action:
| 'applied_to_invoice'
| 'manual_adjustment'
| 'prorated_refund'
| 'revert_prorated_refund'
| 'return_from_voiding'
| 'credit_note_applied'
| 'credit_note_voided'
| 'overpayment_refund'
| 'external_payment'
| 'small_invoice_carryover';
/**
* The value of the amount changed in the transaction.
*/
amount: string;
/**
* The creation time of this transaction.
*/
created_at: string;
credit_note: Shared.CreditNoteTiny | null;
/**
* An optional description provided for manual customer balance adjustments.
*/
description: string | null;
/**
* The new value of the customer's balance prior to the transaction, in the
* customer's currency.
*/
ending_balance: string;
invoice: Shared.InvoiceTiny | null;
/**
* The original value of the customer's balance prior to the transaction, in the
* customer's currency.
*/
starting_balance: string;
type: 'increment' | 'decrement';
}
export interface BalanceTransactionCreateParams {
amount: string;
type: 'increment' | 'decrement';
/**
* An optional description that can be specified around this entry.
*/
description?: string | null;
}
export interface BalanceTransactionListParams extends PageParams {
'operation_time[gt]'?: string | null;
'operation_time[gte]'?: string | null;
'operation_time[lt]'?: string | null;
'operation_time[lte]'?: string | null;
}
BalanceTransactions.BalanceTransactionListResponsesPage = BalanceTransactionListResponsesPage;
export declare namespace BalanceTransactions {
export {
type BalanceTransactionCreateResponse as BalanceTransactionCreateResponse,
type BalanceTransactionListResponse as BalanceTransactionListResponse,
BalanceTransactionListResponsesPage as BalanceTransactionListResponsesPage,
type BalanceTransactionCreateParams as BalanceTransactionCreateParams,
type BalanceTransactionListParams as BalanceTransactionListParams,
};
}