-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcustomercredit.go
240 lines (207 loc) · 9.87 KB
/
customercredit.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
// 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"
)
// CustomerCreditService 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 [NewCustomerCreditService] method instead.
type CustomerCreditService struct {
Options []option.RequestOption
}
// NewCustomerCreditService 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 NewCustomerCreditService(opts ...option.RequestOption) (r *CustomerCreditService) {
r = &CustomerCreditService{}
r.Options = opts
return
}
// Create a new credit at the customer level.
func (r *CustomerCreditService) New(ctx context.Context, body CustomerCreditNewParams, opts ...option.RequestOption) (res *CustomerCreditNewResponse, err error) {
opts = append(r.Options[:], opts...)
path := "contracts/customerCredits/create"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// List credits.
func (r *CustomerCreditService) List(ctx context.Context, body CustomerCreditListParams, opts ...option.RequestOption) (res *CustomerCreditListResponse, err error) {
opts = append(r.Options[:], opts...)
path := "contracts/customerCredits/list"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Update the end date of a credit
func (r *CustomerCreditService) UpdateEndDate(ctx context.Context, body CustomerCreditUpdateEndDateParams, opts ...option.RequestOption) (res *CustomerCreditUpdateEndDateResponse, err error) {
opts = append(r.Options[:], opts...)
path := "contracts/customerCredits/updateEndDate"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
type CustomerCreditNewResponse struct {
Data shared.ID `json:"data,required"`
JSON customerCreditNewResponseJSON `json:"-"`
}
// customerCreditNewResponseJSON contains the JSON metadata for the struct
// [CustomerCreditNewResponse]
type customerCreditNewResponseJSON struct {
Data apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CustomerCreditNewResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r customerCreditNewResponseJSON) RawJSON() string {
return r.raw
}
type CustomerCreditListResponse struct {
Data []shared.Credit `json:"data,required"`
NextPage string `json:"next_page,required,nullable"`
JSON customerCreditListResponseJSON `json:"-"`
}
// customerCreditListResponseJSON contains the JSON metadata for the struct
// [CustomerCreditListResponse]
type customerCreditListResponseJSON struct {
Data apijson.Field
NextPage apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CustomerCreditListResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r customerCreditListResponseJSON) RawJSON() string {
return r.raw
}
type CustomerCreditUpdateEndDateResponse struct {
Data shared.ID `json:"data,required"`
JSON customerCreditUpdateEndDateResponseJSON `json:"-"`
}
// customerCreditUpdateEndDateResponseJSON contains the JSON metadata for the
// struct [CustomerCreditUpdateEndDateResponse]
type customerCreditUpdateEndDateResponseJSON struct {
Data apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CustomerCreditUpdateEndDateResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r customerCreditUpdateEndDateResponseJSON) RawJSON() string {
return r.raw
}
type CustomerCreditNewParams struct {
// Schedule for distributing the credit to the customer.
AccessSchedule param.Field[CustomerCreditNewParamsAccessSchedule] `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"`
ProductID param.Field[string] `json:"product_id,required" format:"uuid"`
// Which contract the credit applies to. If not provided, the credit applies to all
// contracts.
ApplicableContractIDs param.Field[[]string] `json:"applicable_contract_ids"`
// Which products the credit applies to. If both applicable_product_ids and
// applicable_product_tags are not provided, the credit applies to all products.
ApplicableProductIDs param.Field[[]string] `json:"applicable_product_ids" format:"uuid"`
// Which tags the credit applies to. If both applicable_product_ids and
// applicable_product_tags are not provided, the credit 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"`
// 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[CustomerCreditNewParamsRateType] `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 CustomerCreditNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Schedule for distributing the credit to the customer.
type CustomerCreditNewParamsAccessSchedule struct {
ScheduleItems param.Field[[]CustomerCreditNewParamsAccessScheduleScheduleItem] `json:"schedule_items,required"`
// Defaults to USD (cents) if not passed
CreditTypeID param.Field[string] `json:"credit_type_id" format:"uuid"`
}
func (r CustomerCreditNewParamsAccessSchedule) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type CustomerCreditNewParamsAccessScheduleScheduleItem 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 CustomerCreditNewParamsAccessScheduleScheduleItem) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type CustomerCreditNewParamsRateType string
const (
CustomerCreditNewParamsRateTypeCommitRate CustomerCreditNewParamsRateType = "COMMIT_RATE"
CustomerCreditNewParamsRateTypeListRate CustomerCreditNewParamsRateType = "LIST_RATE"
)
func (r CustomerCreditNewParamsRateType) IsKnown() bool {
switch r {
case CustomerCreditNewParamsRateTypeCommitRate, CustomerCreditNewParamsRateTypeListRate:
return true
}
return false
}
type CustomerCreditListParams struct {
CustomerID param.Field[string] `json:"customer_id,required" format:"uuid"`
// Return only credits that have access schedules that "cover" the provided date
CoveringDate param.Field[time.Time] `json:"covering_date" format:"date-time"`
CreditID param.Field[string] `json:"credit_id" format:"uuid"`
// Include only credits that have any access before the provided date (exclusive)
EffectiveBefore param.Field[time.Time] `json:"effective_before" format:"date-time"`
// Include credits 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 credits on the contract level.
IncludeContractCredits param.Field[bool] `json:"include_contract_credits"`
// Include credit 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 credits that have any access on or after the provided date
StartingAt param.Field[time.Time] `json:"starting_at" format:"date-time"`
}
func (r CustomerCreditListParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type CustomerCreditUpdateEndDateParams struct {
// RFC 3339 timestamp indicating when access to the credit will end and it will no
// longer be possible to draw it down (exclusive).
AccessEndingBefore param.Field[time.Time] `json:"access_ending_before,required" format:"date-time"`
// ID of the commit to update
CreditID param.Field[string] `json:"credit_id,required" format:"uuid"`
// ID of the customer whose credit is to be updated
CustomerID param.Field[string] `json:"customer_id,required" format:"uuid"`
}
func (r CustomerCreditUpdateEndDateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}