-
Notifications
You must be signed in to change notification settings - Fork 1
/
managementoperation.go
448 lines (388 loc) · 22.2 KB
/
managementoperation.go
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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package lithic
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"time"
"github.com/lithic-com/lithic-go/internal/apijson"
"github.com/lithic-com/lithic-go/internal/apiquery"
"github.com/lithic-com/lithic-go/internal/param"
"github.com/lithic-com/lithic-go/internal/requestconfig"
"github.com/lithic-com/lithic-go/option"
"github.com/lithic-com/lithic-go/packages/pagination"
)
// ManagementOperationService contains methods and other services that help with
// interacting with the lithic API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewManagementOperationService] method instead.
type ManagementOperationService struct {
Options []option.RequestOption
}
// NewManagementOperationService generates a new service that applies the given
// options to each request. These options are applied after the parent client's
// options (if there is one), and before any request-specific options.
func NewManagementOperationService(opts ...option.RequestOption) (r *ManagementOperationService) {
r = &ManagementOperationService{}
r.Options = opts
return
}
// Create management operation
func (r *ManagementOperationService) New(ctx context.Context, body ManagementOperationNewParams, opts ...option.RequestOption) (res *ManagementOperationTransaction, err error) {
opts = append(r.Options[:], opts...)
path := "v1/management_operations"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Get management operation
func (r *ManagementOperationService) Get(ctx context.Context, managementOperationToken string, opts ...option.RequestOption) (res *ManagementOperationTransaction, err error) {
opts = append(r.Options[:], opts...)
if managementOperationToken == "" {
err = errors.New("missing required management_operation_token parameter")
return
}
path := fmt.Sprintf("v1/management_operations/%s", managementOperationToken)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// List management operations
func (r *ManagementOperationService) List(ctx context.Context, query ManagementOperationListParams, opts ...option.RequestOption) (res *pagination.CursorPage[ManagementOperationTransaction], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "v1/management_operations"
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// List management operations
func (r *ManagementOperationService) ListAutoPaging(ctx context.Context, query ManagementOperationListParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[ManagementOperationTransaction] {
return pagination.NewCursorPageAutoPager(r.List(ctx, query, opts...))
}
// Reverse a management operation
func (r *ManagementOperationService) Reverse(ctx context.Context, managementOperationToken string, body ManagementOperationReverseParams, opts ...option.RequestOption) (res *ManagementOperationTransaction, err error) {
opts = append(r.Options[:], opts...)
if managementOperationToken == "" {
err = errors.New("missing required management_operation_token parameter")
return
}
path := fmt.Sprintf("v1/management_operations/%s/reverse", managementOperationToken)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
type ManagementOperationTransaction struct {
Token string `json:"token,required" format:"uuid"`
Category ManagementOperationTransactionCategory `json:"category,required"`
Created time.Time `json:"created,required" format:"date-time"`
Currency string `json:"currency,required"`
Direction ManagementOperationTransactionDirection `json:"direction,required"`
Events []ManagementOperationTransactionEvent `json:"events,required"`
FinancialAccountToken string `json:"financial_account_token,required" format:"uuid"`
PendingAmount int64 `json:"pending_amount,required"`
Result ManagementOperationTransactionResult `json:"result,required"`
SettledAmount int64 `json:"settled_amount,required"`
Status ManagementOperationTransactionStatus `json:"status,required"`
Updated time.Time `json:"updated,required" format:"date-time"`
UserDefinedID string `json:"user_defined_id"`
JSON managementOperationTransactionJSON `json:"-"`
}
// managementOperationTransactionJSON contains the JSON metadata for the struct
// [ManagementOperationTransaction]
type managementOperationTransactionJSON struct {
Token apijson.Field
Category apijson.Field
Created apijson.Field
Currency apijson.Field
Direction apijson.Field
Events apijson.Field
FinancialAccountToken apijson.Field
PendingAmount apijson.Field
Result apijson.Field
SettledAmount apijson.Field
Status apijson.Field
Updated apijson.Field
UserDefinedID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ManagementOperationTransaction) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r managementOperationTransactionJSON) RawJSON() string {
return r.raw
}
type ManagementOperationTransactionCategory string
const (
ManagementOperationTransactionCategoryManagementFee ManagementOperationTransactionCategory = "MANAGEMENT_FEE"
ManagementOperationTransactionCategoryManagementDispute ManagementOperationTransactionCategory = "MANAGEMENT_DISPUTE"
ManagementOperationTransactionCategoryManagementReward ManagementOperationTransactionCategory = "MANAGEMENT_REWARD"
ManagementOperationTransactionCategoryManagementAdjustment ManagementOperationTransactionCategory = "MANAGEMENT_ADJUSTMENT"
)
func (r ManagementOperationTransactionCategory) IsKnown() bool {
switch r {
case ManagementOperationTransactionCategoryManagementFee, ManagementOperationTransactionCategoryManagementDispute, ManagementOperationTransactionCategoryManagementReward, ManagementOperationTransactionCategoryManagementAdjustment:
return true
}
return false
}
type ManagementOperationTransactionDirection string
const (
ManagementOperationTransactionDirectionCredit ManagementOperationTransactionDirection = "CREDIT"
ManagementOperationTransactionDirectionDebit ManagementOperationTransactionDirection = "DEBIT"
)
func (r ManagementOperationTransactionDirection) IsKnown() bool {
switch r {
case ManagementOperationTransactionDirectionCredit, ManagementOperationTransactionDirectionDebit:
return true
}
return false
}
type ManagementOperationTransactionEvent struct {
Token string `json:"token,required" format:"uuid"`
Amount int64 `json:"amount,required"`
Created time.Time `json:"created,required" format:"date-time"`
DetailedResults []ManagementOperationTransactionEventsDetailedResult `json:"detailed_results,required"`
EffectiveDate time.Time `json:"effective_date,required" format:"date"`
Memo string `json:"memo,required"`
Result ManagementOperationTransactionEventsResult `json:"result,required"`
Type ManagementOperationTransactionEventsType `json:"type,required"`
Subtype string `json:"subtype"`
JSON managementOperationTransactionEventJSON `json:"-"`
}
// managementOperationTransactionEventJSON contains the JSON metadata for the
// struct [ManagementOperationTransactionEvent]
type managementOperationTransactionEventJSON struct {
Token apijson.Field
Amount apijson.Field
Created apijson.Field
DetailedResults apijson.Field
EffectiveDate apijson.Field
Memo apijson.Field
Result apijson.Field
Type apijson.Field
Subtype apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ManagementOperationTransactionEvent) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r managementOperationTransactionEventJSON) RawJSON() string {
return r.raw
}
type ManagementOperationTransactionEventsDetailedResult string
const (
ManagementOperationTransactionEventsDetailedResultApproved ManagementOperationTransactionEventsDetailedResult = "APPROVED"
)
func (r ManagementOperationTransactionEventsDetailedResult) IsKnown() bool {
switch r {
case ManagementOperationTransactionEventsDetailedResultApproved:
return true
}
return false
}
type ManagementOperationTransactionEventsResult string
const (
ManagementOperationTransactionEventsResultApproved ManagementOperationTransactionEventsResult = "APPROVED"
ManagementOperationTransactionEventsResultDeclined ManagementOperationTransactionEventsResult = "DECLINED"
)
func (r ManagementOperationTransactionEventsResult) IsKnown() bool {
switch r {
case ManagementOperationTransactionEventsResultApproved, ManagementOperationTransactionEventsResultDeclined:
return true
}
return false
}
type ManagementOperationTransactionEventsType string
const (
ManagementOperationTransactionEventsTypeCashBack ManagementOperationTransactionEventsType = "CASH_BACK"
ManagementOperationTransactionEventsTypeCurrencyConversion ManagementOperationTransactionEventsType = "CURRENCY_CONVERSION"
ManagementOperationTransactionEventsTypeInterest ManagementOperationTransactionEventsType = "INTEREST"
ManagementOperationTransactionEventsTypeLatePayment ManagementOperationTransactionEventsType = "LATE_PAYMENT"
ManagementOperationTransactionEventsTypeBillingError ManagementOperationTransactionEventsType = "BILLING_ERROR"
ManagementOperationTransactionEventsTypeProvisionalCredit ManagementOperationTransactionEventsType = "PROVISIONAL_CREDIT"
ManagementOperationTransactionEventsTypeCashBackReversal ManagementOperationTransactionEventsType = "CASH_BACK_REVERSAL"
ManagementOperationTransactionEventsTypeCurrencyConversionReversal ManagementOperationTransactionEventsType = "CURRENCY_CONVERSION_REVERSAL"
ManagementOperationTransactionEventsTypeInterestReversal ManagementOperationTransactionEventsType = "INTEREST_REVERSAL"
ManagementOperationTransactionEventsTypeLatePaymentReversal ManagementOperationTransactionEventsType = "LATE_PAYMENT_REVERSAL"
ManagementOperationTransactionEventsTypeBillingErrorReversal ManagementOperationTransactionEventsType = "BILLING_ERROR_REVERSAL"
ManagementOperationTransactionEventsTypeProvisionalCreditReversal ManagementOperationTransactionEventsType = "PROVISIONAL_CREDIT_REVERSAL"
)
func (r ManagementOperationTransactionEventsType) IsKnown() bool {
switch r {
case ManagementOperationTransactionEventsTypeCashBack, ManagementOperationTransactionEventsTypeCurrencyConversion, ManagementOperationTransactionEventsTypeInterest, ManagementOperationTransactionEventsTypeLatePayment, ManagementOperationTransactionEventsTypeBillingError, ManagementOperationTransactionEventsTypeProvisionalCredit, ManagementOperationTransactionEventsTypeCashBackReversal, ManagementOperationTransactionEventsTypeCurrencyConversionReversal, ManagementOperationTransactionEventsTypeInterestReversal, ManagementOperationTransactionEventsTypeLatePaymentReversal, ManagementOperationTransactionEventsTypeBillingErrorReversal, ManagementOperationTransactionEventsTypeProvisionalCreditReversal:
return true
}
return false
}
type ManagementOperationTransactionResult string
const (
ManagementOperationTransactionResultApproved ManagementOperationTransactionResult = "APPROVED"
ManagementOperationTransactionResultDeclined ManagementOperationTransactionResult = "DECLINED"
)
func (r ManagementOperationTransactionResult) IsKnown() bool {
switch r {
case ManagementOperationTransactionResultApproved, ManagementOperationTransactionResultDeclined:
return true
}
return false
}
type ManagementOperationTransactionStatus string
const (
ManagementOperationTransactionStatusPending ManagementOperationTransactionStatus = "PENDING"
ManagementOperationTransactionStatusSettled ManagementOperationTransactionStatus = "SETTLED"
ManagementOperationTransactionStatusDeclined ManagementOperationTransactionStatus = "DECLINED"
ManagementOperationTransactionStatusReversed ManagementOperationTransactionStatus = "REVERSED"
ManagementOperationTransactionStatusCanceled ManagementOperationTransactionStatus = "CANCELED"
)
func (r ManagementOperationTransactionStatus) IsKnown() bool {
switch r {
case ManagementOperationTransactionStatusPending, ManagementOperationTransactionStatusSettled, ManagementOperationTransactionStatusDeclined, ManagementOperationTransactionStatusReversed, ManagementOperationTransactionStatusCanceled:
return true
}
return false
}
type ManagementOperationNewParams struct {
Amount param.Field[int64] `json:"amount,required"`
Category param.Field[ManagementOperationNewParamsCategory] `json:"category,required"`
Direction param.Field[ManagementOperationNewParamsDirection] `json:"direction,required"`
EffectiveDate param.Field[time.Time] `json:"effective_date,required" format:"date"`
EventType param.Field[ManagementOperationNewParamsEventType] `json:"event_type,required"`
FinancialAccountToken param.Field[string] `json:"financial_account_token,required" format:"uuid"`
Token param.Field[string] `json:"token" format:"uuid"`
Memo param.Field[string] `json:"memo"`
Subtype param.Field[string] `json:"subtype"`
UserDefinedID param.Field[string] `json:"user_defined_id"`
}
func (r ManagementOperationNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type ManagementOperationNewParamsCategory string
const (
ManagementOperationNewParamsCategoryManagementFee ManagementOperationNewParamsCategory = "MANAGEMENT_FEE"
ManagementOperationNewParamsCategoryManagementDispute ManagementOperationNewParamsCategory = "MANAGEMENT_DISPUTE"
ManagementOperationNewParamsCategoryManagementReward ManagementOperationNewParamsCategory = "MANAGEMENT_REWARD"
ManagementOperationNewParamsCategoryManagementAdjustment ManagementOperationNewParamsCategory = "MANAGEMENT_ADJUSTMENT"
)
func (r ManagementOperationNewParamsCategory) IsKnown() bool {
switch r {
case ManagementOperationNewParamsCategoryManagementFee, ManagementOperationNewParamsCategoryManagementDispute, ManagementOperationNewParamsCategoryManagementReward, ManagementOperationNewParamsCategoryManagementAdjustment:
return true
}
return false
}
type ManagementOperationNewParamsDirection string
const (
ManagementOperationNewParamsDirectionCredit ManagementOperationNewParamsDirection = "CREDIT"
ManagementOperationNewParamsDirectionDebit ManagementOperationNewParamsDirection = "DEBIT"
)
func (r ManagementOperationNewParamsDirection) IsKnown() bool {
switch r {
case ManagementOperationNewParamsDirectionCredit, ManagementOperationNewParamsDirectionDebit:
return true
}
return false
}
type ManagementOperationNewParamsEventType string
const (
ManagementOperationNewParamsEventTypeCashBack ManagementOperationNewParamsEventType = "CASH_BACK"
ManagementOperationNewParamsEventTypeCurrencyConversion ManagementOperationNewParamsEventType = "CURRENCY_CONVERSION"
ManagementOperationNewParamsEventTypeInterest ManagementOperationNewParamsEventType = "INTEREST"
ManagementOperationNewParamsEventTypeLatePayment ManagementOperationNewParamsEventType = "LATE_PAYMENT"
ManagementOperationNewParamsEventTypeBillingError ManagementOperationNewParamsEventType = "BILLING_ERROR"
ManagementOperationNewParamsEventTypeProvisionalCredit ManagementOperationNewParamsEventType = "PROVISIONAL_CREDIT"
ManagementOperationNewParamsEventTypeCashBackReversal ManagementOperationNewParamsEventType = "CASH_BACK_REVERSAL"
ManagementOperationNewParamsEventTypeCurrencyConversionReversal ManagementOperationNewParamsEventType = "CURRENCY_CONVERSION_REVERSAL"
ManagementOperationNewParamsEventTypeInterestReversal ManagementOperationNewParamsEventType = "INTEREST_REVERSAL"
ManagementOperationNewParamsEventTypeLatePaymentReversal ManagementOperationNewParamsEventType = "LATE_PAYMENT_REVERSAL"
ManagementOperationNewParamsEventTypeBillingErrorReversal ManagementOperationNewParamsEventType = "BILLING_ERROR_REVERSAL"
ManagementOperationNewParamsEventTypeProvisionalCreditReversal ManagementOperationNewParamsEventType = "PROVISIONAL_CREDIT_REVERSAL"
)
func (r ManagementOperationNewParamsEventType) IsKnown() bool {
switch r {
case ManagementOperationNewParamsEventTypeCashBack, ManagementOperationNewParamsEventTypeCurrencyConversion, ManagementOperationNewParamsEventTypeInterest, ManagementOperationNewParamsEventTypeLatePayment, ManagementOperationNewParamsEventTypeBillingError, ManagementOperationNewParamsEventTypeProvisionalCredit, ManagementOperationNewParamsEventTypeCashBackReversal, ManagementOperationNewParamsEventTypeCurrencyConversionReversal, ManagementOperationNewParamsEventTypeInterestReversal, ManagementOperationNewParamsEventTypeLatePaymentReversal, ManagementOperationNewParamsEventTypeBillingErrorReversal, ManagementOperationNewParamsEventTypeProvisionalCreditReversal:
return true
}
return false
}
type ManagementOperationListParams struct {
// Date string in RFC 3339 format. Only entries created after the specified time
// will be included. UTC time zone.
Begin param.Field[time.Time] `query:"begin" format:"date-time"`
BusinessAccountToken param.Field[string] `query:"business_account_token" format:"uuid"`
// Management operation category to be returned.
Category param.Field[ManagementOperationListParamsCategory] `query:"category"`
// Date string in RFC 3339 format. Only entries created before the specified time
// will be included. UTC time zone.
End param.Field[time.Time] `query:"end" format:"date-time"`
// A cursor representing an item's token before which a page of results should end.
// Used to retrieve the previous page of results before this item.
EndingBefore param.Field[string] `query:"ending_before"`
// Globally unique identifier for the financial account. Accepted type dependent on
// the program's use case.
FinancialAccountToken param.Field[string] `query:"financial_account_token" format:"uuid"`
// Page size (for pagination).
PageSize param.Field[int64] `query:"page_size"`
// A cursor representing an item's token after which a page of results should
// begin. Used to retrieve the next page of results after this item.
StartingAfter param.Field[string] `query:"starting_after"`
// Management operation status to be returned.
Status param.Field[ManagementOperationListParamsStatus] `query:"status"`
}
// URLQuery serializes [ManagementOperationListParams]'s query parameters as
// `url.Values`.
func (r ManagementOperationListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
// Management operation category to be returned.
type ManagementOperationListParamsCategory string
const (
ManagementOperationListParamsCategoryManagementFee ManagementOperationListParamsCategory = "MANAGEMENT_FEE"
ManagementOperationListParamsCategoryManagementDispute ManagementOperationListParamsCategory = "MANAGEMENT_DISPUTE"
ManagementOperationListParamsCategoryManagementReward ManagementOperationListParamsCategory = "MANAGEMENT_REWARD"
ManagementOperationListParamsCategoryManagementAdjustment ManagementOperationListParamsCategory = "MANAGEMENT_ADJUSTMENT"
)
func (r ManagementOperationListParamsCategory) IsKnown() bool {
switch r {
case ManagementOperationListParamsCategoryManagementFee, ManagementOperationListParamsCategoryManagementDispute, ManagementOperationListParamsCategoryManagementReward, ManagementOperationListParamsCategoryManagementAdjustment:
return true
}
return false
}
// Management operation status to be returned.
type ManagementOperationListParamsStatus string
const (
ManagementOperationListParamsStatusPending ManagementOperationListParamsStatus = "PENDING"
ManagementOperationListParamsStatusSettled ManagementOperationListParamsStatus = "SETTLED"
ManagementOperationListParamsStatusDeclined ManagementOperationListParamsStatus = "DECLINED"
ManagementOperationListParamsStatusReversed ManagementOperationListParamsStatus = "REVERSED"
ManagementOperationListParamsStatusCanceled ManagementOperationListParamsStatus = "CANCELED"
)
func (r ManagementOperationListParamsStatus) IsKnown() bool {
switch r {
case ManagementOperationListParamsStatusPending, ManagementOperationListParamsStatusSettled, ManagementOperationListParamsStatusDeclined, ManagementOperationListParamsStatusReversed, ManagementOperationListParamsStatusCanceled:
return true
}
return false
}
type ManagementOperationReverseParams struct {
EffectiveDate param.Field[time.Time] `json:"effective_date,required" format:"date"`
Memo param.Field[string] `json:"memo"`
}
func (r ManagementOperationReverseParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}