-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcustomercommit.go
374 lines (326 loc) · 17.4 KB
/
customercommit.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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package metronome
import (
"context"
"net/http"
"time"
"github.com/Metronome-Industries/metronome-go/internal/apijson"
"github.com/Metronome-Industries/metronome-go/internal/param"
"github.com/Metronome-Industries/metronome-go/internal/requestconfig"
"github.com/Metronome-Industries/metronome-go/option"
"github.com/Metronome-Industries/metronome-go/shared"
)
// CustomerCommitService contains methods and other services that help with
// interacting with the metronome 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 [NewCustomerCommitService] method instead.
type CustomerCommitService struct {
Options []option.RequestOption
}
// NewCustomerCommitService 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 NewCustomerCommitService(opts ...option.RequestOption) (r *CustomerCommitService) {
r = &CustomerCommitService{}
r.Options = opts
return
}
// Create a new commit at the customer level.
func (r *CustomerCommitService) New(ctx context.Context, body CustomerCommitNewParams, opts ...option.RequestOption) (res *CustomerCommitNewResponse, err error) {
opts = append(r.Options[:], opts...)
path := "contracts/customerCommits/create"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// List commits.
func (r *CustomerCommitService) List(ctx context.Context, body CustomerCommitListParams, opts ...option.RequestOption) (res *CustomerCommitListResponse, err error) {
opts = append(r.Options[:], opts...)
path := "contracts/customerCommits/list"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Update the end date of a PREPAID commit
func (r *CustomerCommitService) UpdateEndDate(ctx context.Context, body CustomerCommitUpdateEndDateParams, opts ...option.RequestOption) (res *CustomerCommitUpdateEndDateResponse, err error) {
opts = append(r.Options[:], opts...)
path := "contracts/customerCommits/updateEndDate"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
type CustomerCommitNewResponse struct {
Data shared.ID `json:"data,required"`
JSON customerCommitNewResponseJSON `json:"-"`
}
// customerCommitNewResponseJSON contains the JSON metadata for the struct
// [CustomerCommitNewResponse]
type customerCommitNewResponseJSON struct {
Data apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CustomerCommitNewResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r customerCommitNewResponseJSON) RawJSON() string {
return r.raw
}
type CustomerCommitListResponse struct {
Data []shared.Commit `json:"data,required"`
NextPage string `json:"next_page,required,nullable"`
JSON customerCommitListResponseJSON `json:"-"`
}
// customerCommitListResponseJSON contains the JSON metadata for the struct
// [CustomerCommitListResponse]
type customerCommitListResponseJSON struct {
Data apijson.Field
NextPage apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CustomerCommitListResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r customerCommitListResponseJSON) RawJSON() string {
return r.raw
}
type CustomerCommitUpdateEndDateResponse struct {
Data shared.ID `json:"data,required"`
JSON customerCommitUpdateEndDateResponseJSON `json:"-"`
}
// customerCommitUpdateEndDateResponseJSON contains the JSON metadata for the
// struct [CustomerCommitUpdateEndDateResponse]
type customerCommitUpdateEndDateResponseJSON struct {
Data apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CustomerCommitUpdateEndDateResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r customerCommitUpdateEndDateResponseJSON) RawJSON() string {
return r.raw
}
type CustomerCommitNewParams struct {
// Schedule for distributing the commit to the customer. For "POSTPAID" commits
// only one schedule item is allowed and amount must match invoice_schedule total.
AccessSchedule param.Field[CustomerCommitNewParamsAccessSchedule] `json:"access_schedule,required"`
CustomerID param.Field[string] `json:"customer_id,required" format:"uuid"`
// If multiple credits or commits are applicable, the one with the lower priority
// will apply first.
Priority param.Field[float64] `json:"priority,required"`
// ID of the fixed product associated with the commit. This is required because
// products are used to invoice the commit amount.
ProductID param.Field[string] `json:"product_id,required" format:"uuid"`
Type param.Field[CustomerCommitNewParamsType] `json:"type,required"`
// Which contract the commit applies to. If not provided, the commit applies to all
// contracts.
ApplicableContractIDs param.Field[[]string] `json:"applicable_contract_ids"`
// Which products the commit applies to. If both applicable_product_ids and
// applicable_product_tags are not provided, the commit applies to all products.
ApplicableProductIDs param.Field[[]string] `json:"applicable_product_ids" format:"uuid"`
// Which tags the commit applies to. If both applicable_product_ids and
// applicable_product_tags are not provided, the commit applies to all products.
ApplicableProductTags param.Field[[]string] `json:"applicable_product_tags"`
CustomFields param.Field[map[string]string] `json:"custom_fields"`
// Used only in UI/API. It is not exposed to end customers.
Description param.Field[string] `json:"description"`
// The contract that this commit will be billed on. This is required for "POSTPAID"
// commits and for "PREPAID" commits unless there is no invoice schedule above
// (i.e., the commit is 'free').
InvoiceContractID param.Field[string] `json:"invoice_contract_id" format:"uuid"`
// Required for "POSTPAID" commits: the true up invoice will be generated at this
// time and only one schedule item is allowed; the total must match
// accesss_schedule amount. Optional for "PREPAID" commits: if not provided, this
// will be a "complimentary" commit with no invoice.
InvoiceSchedule param.Field[CustomerCommitNewParamsInvoiceSchedule] `json:"invoice_schedule"`
// displayed on invoices
Name param.Field[string] `json:"name"`
// This field's availability is dependent on your client's configuration.
NetsuiteSalesOrderID param.Field[string] `json:"netsuite_sales_order_id"`
RateType param.Field[CustomerCommitNewParamsRateType] `json:"rate_type"`
// This field's availability is dependent on your client's configuration.
SalesforceOpportunityID param.Field[string] `json:"salesforce_opportunity_id"`
// Prevents the creation of duplicates. If a request to create a commit or credit
// is made with a uniqueness key that was previously used to create a commit or
// credit, a new record will not be created and the request will fail with a 409
// error.
UniquenessKey param.Field[string] `json:"uniqueness_key"`
}
func (r CustomerCommitNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Schedule for distributing the commit to the customer. For "POSTPAID" commits
// only one schedule item is allowed and amount must match invoice_schedule total.
type CustomerCommitNewParamsAccessSchedule struct {
ScheduleItems param.Field[[]CustomerCommitNewParamsAccessScheduleScheduleItem] `json:"schedule_items,required"`
// Defaults to USD (cents) if not passed
CreditTypeID param.Field[string] `json:"credit_type_id" format:"uuid"`
}
func (r CustomerCommitNewParamsAccessSchedule) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type CustomerCommitNewParamsAccessScheduleScheduleItem struct {
Amount param.Field[float64] `json:"amount,required"`
// RFC 3339 timestamp (exclusive)
EndingBefore param.Field[time.Time] `json:"ending_before,required" format:"date-time"`
// RFC 3339 timestamp (inclusive)
StartingAt param.Field[time.Time] `json:"starting_at,required" format:"date-time"`
}
func (r CustomerCommitNewParamsAccessScheduleScheduleItem) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type CustomerCommitNewParamsType string
const (
CustomerCommitNewParamsTypePrepaid CustomerCommitNewParamsType = "PREPAID"
CustomerCommitNewParamsTypePostpaid CustomerCommitNewParamsType = "POSTPAID"
)
func (r CustomerCommitNewParamsType) IsKnown() bool {
switch r {
case CustomerCommitNewParamsTypePrepaid, CustomerCommitNewParamsTypePostpaid:
return true
}
return false
}
// Required for "POSTPAID" commits: the true up invoice will be generated at this
// time and only one schedule item is allowed; the total must match
// accesss_schedule amount. Optional for "PREPAID" commits: if not provided, this
// will be a "complimentary" commit with no invoice.
type CustomerCommitNewParamsInvoiceSchedule struct {
// Defaults to USD (cents) if not passed.
CreditTypeID param.Field[string] `json:"credit_type_id" format:"uuid"`
// Enter the unit price and quantity for the charge or instead only send the
// amount. If amount is sent, the unit price is assumed to be the amount and
// quantity is inferred to be 1.
RecurringSchedule param.Field[CustomerCommitNewParamsInvoiceScheduleRecurringSchedule] `json:"recurring_schedule"`
// Either provide amount or provide both unit_price and quantity.
ScheduleItems param.Field[[]CustomerCommitNewParamsInvoiceScheduleScheduleItem] `json:"schedule_items"`
}
func (r CustomerCommitNewParamsInvoiceSchedule) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Enter the unit price and quantity for the charge or instead only send the
// amount. If amount is sent, the unit price is assumed to be the amount and
// quantity is inferred to be 1.
type CustomerCommitNewParamsInvoiceScheduleRecurringSchedule struct {
AmountDistribution param.Field[CustomerCommitNewParamsInvoiceScheduleRecurringScheduleAmountDistribution] `json:"amount_distribution,required"`
// RFC 3339 timestamp (exclusive).
EndingBefore param.Field[time.Time] `json:"ending_before,required" format:"date-time"`
Frequency param.Field[CustomerCommitNewParamsInvoiceScheduleRecurringScheduleFrequency] `json:"frequency,required"`
// RFC 3339 timestamp (inclusive).
StartingAt param.Field[time.Time] `json:"starting_at,required" format:"date-time"`
// Amount for the charge. Can be provided instead of unit_price and quantity. If
// amount is sent, the unit_price is assumed to be the amount and quantity is
// inferred to be 1.
Amount param.Field[float64] `json:"amount"`
// Quantity for the charge. Will be multiplied by unit_price to determine the
// amount and must be specified with unit_price. If specified amount cannot be
// provided.
Quantity param.Field[float64] `json:"quantity"`
// Unit price for the charge. Will be multiplied by quantity to determine the
// amount and must be specified with quantity. If specified amount cannot be
// provided.
UnitPrice param.Field[float64] `json:"unit_price"`
}
func (r CustomerCommitNewParamsInvoiceScheduleRecurringSchedule) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type CustomerCommitNewParamsInvoiceScheduleRecurringScheduleAmountDistribution string
const (
CustomerCommitNewParamsInvoiceScheduleRecurringScheduleAmountDistributionDivided CustomerCommitNewParamsInvoiceScheduleRecurringScheduleAmountDistribution = "DIVIDED"
CustomerCommitNewParamsInvoiceScheduleRecurringScheduleAmountDistributionDividedRounded CustomerCommitNewParamsInvoiceScheduleRecurringScheduleAmountDistribution = "DIVIDED_ROUNDED"
CustomerCommitNewParamsInvoiceScheduleRecurringScheduleAmountDistributionEach CustomerCommitNewParamsInvoiceScheduleRecurringScheduleAmountDistribution = "EACH"
)
func (r CustomerCommitNewParamsInvoiceScheduleRecurringScheduleAmountDistribution) IsKnown() bool {
switch r {
case CustomerCommitNewParamsInvoiceScheduleRecurringScheduleAmountDistributionDivided, CustomerCommitNewParamsInvoiceScheduleRecurringScheduleAmountDistributionDividedRounded, CustomerCommitNewParamsInvoiceScheduleRecurringScheduleAmountDistributionEach:
return true
}
return false
}
type CustomerCommitNewParamsInvoiceScheduleRecurringScheduleFrequency string
const (
CustomerCommitNewParamsInvoiceScheduleRecurringScheduleFrequencyMonthly CustomerCommitNewParamsInvoiceScheduleRecurringScheduleFrequency = "MONTHLY"
CustomerCommitNewParamsInvoiceScheduleRecurringScheduleFrequencyQuarterly CustomerCommitNewParamsInvoiceScheduleRecurringScheduleFrequency = "QUARTERLY"
CustomerCommitNewParamsInvoiceScheduleRecurringScheduleFrequencySemiAnnual CustomerCommitNewParamsInvoiceScheduleRecurringScheduleFrequency = "SEMI_ANNUAL"
CustomerCommitNewParamsInvoiceScheduleRecurringScheduleFrequencyAnnual CustomerCommitNewParamsInvoiceScheduleRecurringScheduleFrequency = "ANNUAL"
)
func (r CustomerCommitNewParamsInvoiceScheduleRecurringScheduleFrequency) IsKnown() bool {
switch r {
case CustomerCommitNewParamsInvoiceScheduleRecurringScheduleFrequencyMonthly, CustomerCommitNewParamsInvoiceScheduleRecurringScheduleFrequencyQuarterly, CustomerCommitNewParamsInvoiceScheduleRecurringScheduleFrequencySemiAnnual, CustomerCommitNewParamsInvoiceScheduleRecurringScheduleFrequencyAnnual:
return true
}
return false
}
type CustomerCommitNewParamsInvoiceScheduleScheduleItem struct {
// timestamp of the scheduled event
Timestamp param.Field[time.Time] `json:"timestamp,required" format:"date-time"`
// Amount for the charge. Can be provided instead of unit_price and quantity. If
// amount is sent, the unit_price is assumed to be the amount and quantity is
// inferred to be 1.
Amount param.Field[float64] `json:"amount"`
// Quantity for the charge. Will be multiplied by unit_price to determine the
// amount and must be specified with unit_price. If specified amount cannot be
// provided.
Quantity param.Field[float64] `json:"quantity"`
// Unit price for the charge. Will be multiplied by quantity to determine the
// amount and must be specified with quantity. If specified amount cannot be
// provided.
UnitPrice param.Field[float64] `json:"unit_price"`
}
func (r CustomerCommitNewParamsInvoiceScheduleScheduleItem) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type CustomerCommitNewParamsRateType string
const (
CustomerCommitNewParamsRateTypeCommitRate CustomerCommitNewParamsRateType = "COMMIT_RATE"
CustomerCommitNewParamsRateTypeListRate CustomerCommitNewParamsRateType = "LIST_RATE"
)
func (r CustomerCommitNewParamsRateType) IsKnown() bool {
switch r {
case CustomerCommitNewParamsRateTypeCommitRate, CustomerCommitNewParamsRateTypeListRate:
return true
}
return false
}
type CustomerCommitListParams struct {
CustomerID param.Field[string] `json:"customer_id,required" format:"uuid"`
CommitID param.Field[string] `json:"commit_id" format:"uuid"`
// Include only commits that have access schedules that "cover" the provided date
CoveringDate param.Field[time.Time] `json:"covering_date" format:"date-time"`
// Include only commits that have any access before the provided date (exclusive)
EffectiveBefore param.Field[time.Time] `json:"effective_before" format:"date-time"`
// Include commits from archived contracts.
IncludeArchived param.Field[bool] `json:"include_archived"`
// Include the balance in the response. Setting this flag may cause the query to be
// slower.
IncludeBalance param.Field[bool] `json:"include_balance"`
// Include commits on the contract level.
IncludeContractCommits param.Field[bool] `json:"include_contract_commits"`
// Include commit ledgers in the response. Setting this flag may cause the query to
// be slower.
IncludeLedgers param.Field[bool] `json:"include_ledgers"`
// The next page token from a previous response.
NextPage param.Field[string] `json:"next_page"`
// Include only commits that have any access on or after the provided date
StartingAt param.Field[time.Time] `json:"starting_at" format:"date-time"`
}
func (r CustomerCommitListParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type CustomerCommitUpdateEndDateParams struct {
// ID of the commit to update. Only supports "PREPAID" commits.
CommitID param.Field[string] `json:"commit_id,required" format:"uuid"`
// ID of the customer whose commit is to be updated
CustomerID param.Field[string] `json:"customer_id,required" format:"uuid"`
// RFC 3339 timestamp indicating when access to the commit will end and it will no
// longer be possible to draw it down (exclusive). If not provided, the access will
// not be updated.
AccessEndingBefore param.Field[time.Time] `json:"access_ending_before" format:"date-time"`
// RFC 3339 timestamp indicating when the commit will stop being invoiced
// (exclusive). If not provided, the invoice schedule will not be updated.
InvoicesEndingBefore param.Field[time.Time] `json:"invoices_ending_before" format:"date-time"`
}
func (r CustomerCommitUpdateEndDateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}