forked from labd/commercetools-go-sdk
/
types_tax_category.go
406 lines (361 loc) · 13.9 KB
/
types_tax_category.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
package platform
// Generated file, please do not change!!!
import (
"encoding/json"
"errors"
"time"
)
/**
* It is used to calculate the [taxPortions](/../api/projects/carts#taxedprice) field in a Cart or Order.
*/
type SubRate struct {
// Name of the SubRate.
Name string `json:"name"`
Amount float64 `json:"amount"`
}
type TaxCategory struct {
// Unique identifier of the TaxCategory.
ID string `json:"id"`
// Current version of the TaxCategory.
Version int `json:"version"`
// Date and time (UTC) the TaxCategory was initially created.
CreatedAt time.Time `json:"createdAt"`
// Date and time (UTC) the TaxCategory was last updated.
LastModifiedAt time.Time `json:"lastModifiedAt"`
// Present on resources created after 1 February 2019 except for [events not tracked](/../api/client-logging#events-tracked).
LastModifiedBy *LastModifiedBy `json:"lastModifiedBy,omitempty"`
// Present on resources created after 1 February 2019 except for [events not tracked](/../api/client-logging#events-tracked).
CreatedBy *CreatedBy `json:"createdBy,omitempty"`
// Name of the TaxCategory.
Name string `json:"name"`
// Description of the TaxCategory.
Description *string `json:"description,omitempty"`
// Tax rates and subrates of states and countries. Each TaxRate in the array has a unique ID.
Rates []TaxRate `json:"rates"`
// User-defined unique identifier of the TaxCategory.
Key *string `json:"key,omitempty"`
}
type TaxCategoryDraft struct {
// Name of the TaxCategory.
Name string `json:"name"`
// Description of the TaxCategory.
Description *string `json:"description,omitempty"`
// Tax rates and subrates of states and countries.
Rates []TaxRateDraft `json:"rates"`
// User-defined unique identifier for the TaxCategory.
Key *string `json:"key,omitempty"`
}
// MarshalJSON override to set the discriminator value or remove
// optional nil slices
func (obj TaxCategoryDraft) MarshalJSON() ([]byte, error) {
type Alias TaxCategoryDraft
data, err := json.Marshal(struct {
*Alias
}{Alias: (*Alias)(&obj)})
if err != nil {
return nil, err
}
raw := make(map[string]interface{})
if err := json.Unmarshal(data, &raw); err != nil {
return nil, err
}
if raw["rates"] == nil {
delete(raw, "rates")
}
return json.Marshal(raw)
}
/**
* [PagedQueryResult](/../api/general-concepts#pagedqueryresult) with `results` containing an array of [TaxCategory](ctp:api:type:TaxCategory).
*
*/
type TaxCategoryPagedQueryResponse struct {
// Number of [results requested](/../api/general-concepts#limit).
Limit int `json:"limit"`
// Number of [elements skipped](/../api/general-concepts#offset).
Offset int `json:"offset"`
// Actual number of results returned.
Count int `json:"count"`
// Total number of results matching the query.
// This number is an estimation that is not [strongly consistent](/../api/general-concepts#strong-consistency).
// This field is returned by default.
// For improved performance, calculating this field can be deactivated by using the query parameter `withTotal=false`.
// When the results are filtered with a [Query Predicate](/../api/predicates/query), `total` is subject to a [limit](/../api/limits#queries).
Total *int `json:"total,omitempty"`
// [TaxCategories](ctp:api:type:TaxCategory) matching the query.
Results []TaxCategory `json:"results"`
}
/**
* [Reference](ctp:api:type:Reference) to a [TaxCategory](ctp:api:type:TaxCategory).
*
*/
type TaxCategoryReference struct {
// Unique identifier of the referenced [TaxCategory](ctp:api:type:TaxCategory).
ID string `json:"id"`
// Contains the representation of the expanded TaxCategory. Only present in responses to requests with [Reference Expansion](/../api/general-concepts#reference-expansion) for TaxCategories.
Obj *TaxCategory `json:"obj,omitempty"`
}
// MarshalJSON override to set the discriminator value or remove
// optional nil slices
func (obj TaxCategoryReference) MarshalJSON() ([]byte, error) {
type Alias TaxCategoryReference
return json.Marshal(struct {
Action string `json:"typeId"`
*Alias
}{Action: "tax-category", Alias: (*Alias)(&obj)})
}
/**
* [ResourceIdentifier](ctp:api:type:ResourceIdentifier) to a [TaxCategory](ctp:api:type:TaxCategory).
*
*/
type TaxCategoryResourceIdentifier struct {
// Unique identifier of the referenced [TaxCategory](ctp:api:type:TaxCategory). Either `id` or `key` is required.
ID *string `json:"id,omitempty"`
// User-defined unique identifier of the referenced [TaxCategory](ctp:api:type:TaxCategory). Either `id` or `key` is required.
Key *string `json:"key,omitempty"`
}
// MarshalJSON override to set the discriminator value or remove
// optional nil slices
func (obj TaxCategoryResourceIdentifier) MarshalJSON() ([]byte, error) {
type Alias TaxCategoryResourceIdentifier
return json.Marshal(struct {
Action string `json:"typeId"`
*Alias
}{Action: "tax-category", Alias: (*Alias)(&obj)})
}
type TaxCategoryUpdate struct {
// Expected version of the TaxCategory on which the changes should be applied. If the expected version does not match the actual version, a [ConcurrentModification](ctp:api:type:ConcurrentModificationError) error is returned.
Version int `json:"version"`
// Update actions to be performed on the TaxCategory.
Actions []TaxCategoryUpdateAction `json:"actions"`
}
// UnmarshalJSON override to deserialize correct attribute types based
// on the discriminator value
func (obj *TaxCategoryUpdate) UnmarshalJSON(data []byte) error {
type Alias TaxCategoryUpdate
if err := json.Unmarshal(data, (*Alias)(obj)); err != nil {
return err
}
for i := range obj.Actions {
var err error
obj.Actions[i], err = mapDiscriminatorTaxCategoryUpdateAction(obj.Actions[i])
if err != nil {
return err
}
}
return nil
}
type TaxCategoryUpdateAction interface{}
func mapDiscriminatorTaxCategoryUpdateAction(input interface{}) (TaxCategoryUpdateAction, error) {
var discriminator string
if data, ok := input.(map[string]interface{}); ok {
discriminator, ok = data["action"].(string)
if !ok {
return nil, errors.New("error processing discriminator field 'action'")
}
} else {
return nil, errors.New("invalid data")
}
switch discriminator {
case "addTaxRate":
obj := TaxCategoryAddTaxRateAction{}
if err := decodeStruct(input, &obj); err != nil {
return nil, err
}
return obj, nil
case "changeName":
obj := TaxCategoryChangeNameAction{}
if err := decodeStruct(input, &obj); err != nil {
return nil, err
}
return obj, nil
case "removeTaxRate":
obj := TaxCategoryRemoveTaxRateAction{}
if err := decodeStruct(input, &obj); err != nil {
return nil, err
}
return obj, nil
case "replaceTaxRate":
obj := TaxCategoryReplaceTaxRateAction{}
if err := decodeStruct(input, &obj); err != nil {
return nil, err
}
return obj, nil
case "setDescription":
obj := TaxCategorySetDescriptionAction{}
if err := decodeStruct(input, &obj); err != nil {
return nil, err
}
return obj, nil
case "setKey":
obj := TaxCategorySetKeyAction{}
if err := decodeStruct(input, &obj); err != nil {
return nil, err
}
return obj, nil
}
return nil, nil
}
type TaxRate struct {
// Present if the TaxRate is part of a [TaxCategory](ctp:api:type:TaxCategory).
// Absent for external TaxRates in [LineItem](ctp:api:type:LineItem), [CustomLineItem](ctp:api:type:CustomLineItem), and [ShippingInfo](ctp:api:type:ShippingInfo).
ID *string `json:"id,omitempty"`
// User-defined unique identifier of the TaxRate.
// Present when set using [TaxRateDraft](ctp:api:type:TaxRateDraft). Not available for external TaxRates created using [ExternalTaxRateDraft](ctp:api:type:ExternalTaxRateDraft).
Key *string `json:"key,omitempty"`
// Name of the TaxRate.
Name string `json:"name"`
// Tax rate. If subrates are used, the amount must be the sum of all subrates.
Amount float64 `json:"amount"`
// If `true`, tax is included in [Embedded Prices](ctp:api:type:Price) or [Standalone Prices](ctp:api:type:StandalonePrice), and the `taxedPrice` is present on [LineItems](ctp:api:type:LineItem). In this case, the `totalNet` price on [TaxedPrice](ctp:api:type:TaxedPrice) includes the TaxRate.
IncludedInPrice bool `json:"includedInPrice"`
// Country in which the tax rate is applied in [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) format.
Country string `json:"country"`
// State within the country, such as Texas in the United States.
State *string `json:"state,omitempty"`
// Used to calculate the [taxPortions](/../api/projects/carts#taxedprice) field in a Cart or Order. It is useful if the total tax of a country (such as the US) is a combination of multiple taxes (such as state and local taxes).
SubRates []SubRate `json:"subRates"`
}
// MarshalJSON override to set the discriminator value or remove
// optional nil slices
func (obj TaxRate) MarshalJSON() ([]byte, error) {
type Alias TaxRate
data, err := json.Marshal(struct {
*Alias
}{Alias: (*Alias)(&obj)})
if err != nil {
return nil, err
}
raw := make(map[string]interface{})
if err := json.Unmarshal(data, &raw); err != nil {
return nil, err
}
if raw["subRates"] == nil {
delete(raw, "subRates")
}
return json.Marshal(raw)
}
type TaxRateDraft struct {
// Name of the TaxRate.
Name string `json:"name"`
// Tax rate.
// Must be supplied if no `subRates` are specified.
// If `subRates` are specified, this field can be omitted or it must be the sum of amounts of all `subRates`.
Amount *float64 `json:"amount,omitempty"`
// If `true`, tax is included in [Embedded Prices](ctp:api:type:Price) or [Standalone Prices](ctp:api:type:StandalonePrice), and the `taxedPrice` is present on [LineItems](ctp:api:type:LineItem). In this case, the `totalNet` price on [TaxedPrice](ctp:api:type:TaxedPrice) includes the TaxRate.
IncludedInPrice bool `json:"includedInPrice"`
// Country in which the tax rate is applied in [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) format.
Country string `json:"country"`
// State within the country, such as Texas in the United States.
State *string `json:"state,omitempty"`
// Used to calculate the [taxPortions](/../api/projects/carts#taxedprice) field in a Cart or Order. It is useful if the total tax of a country (such as the US) is a combination of multiple taxes (such as state and local taxes).
SubRates []SubRate `json:"subRates"`
// User-defined unique identifier of the TaxRate.
Key *string `json:"key,omitempty"`
}
// MarshalJSON override to set the discriminator value or remove
// optional nil slices
func (obj TaxRateDraft) MarshalJSON() ([]byte, error) {
type Alias TaxRateDraft
data, err := json.Marshal(struct {
*Alias
}{Alias: (*Alias)(&obj)})
if err != nil {
return nil, err
}
raw := make(map[string]interface{})
if err := json.Unmarshal(data, &raw); err != nil {
return nil, err
}
if raw["subRates"] == nil {
delete(raw, "subRates")
}
return json.Marshal(raw)
}
type TaxCategoryAddTaxRateAction struct {
// Value to append to the `rates` array.
TaxRate TaxRateDraft `json:"taxRate"`
}
// MarshalJSON override to set the discriminator value or remove
// optional nil slices
func (obj TaxCategoryAddTaxRateAction) MarshalJSON() ([]byte, error) {
type Alias TaxCategoryAddTaxRateAction
return json.Marshal(struct {
Action string `json:"action"`
*Alias
}{Action: "addTaxRate", Alias: (*Alias)(&obj)})
}
type TaxCategoryChangeNameAction struct {
// New value to set. Must not be empty.
Name string `json:"name"`
}
// MarshalJSON override to set the discriminator value or remove
// optional nil slices
func (obj TaxCategoryChangeNameAction) MarshalJSON() ([]byte, error) {
type Alias TaxCategoryChangeNameAction
return json.Marshal(struct {
Action string `json:"action"`
*Alias
}{Action: "changeName", Alias: (*Alias)(&obj)})
}
type TaxCategoryRemoveTaxRateAction struct {
// ID of the TaxRate to remove.
// Either `taxRateId` or `taxRateKey` is required for this update action.
TaxRateId *string `json:"taxRateId,omitempty"`
// Key of the TaxRate to remove.
// Either `taxRateId` or `taxRateKey` is required for this update action.
TaxRateKey *string `json:"taxRateKey,omitempty"`
}
// MarshalJSON override to set the discriminator value or remove
// optional nil slices
func (obj TaxCategoryRemoveTaxRateAction) MarshalJSON() ([]byte, error) {
type Alias TaxCategoryRemoveTaxRateAction
return json.Marshal(struct {
Action string `json:"action"`
*Alias
}{Action: "removeTaxRate", Alias: (*Alias)(&obj)})
}
type TaxCategoryReplaceTaxRateAction struct {
// ID of the TaxRate to replace.
// Either `taxRateId` or `taxRateKey` is required for this update action.
TaxRateId *string `json:"taxRateId,omitempty"`
// Key of the TaxRate to replace.
// Either `taxRateId` or `taxRateKey` is required for this update action.
TaxRateKey *string `json:"taxRateKey,omitempty"`
// New TaxRate to replace with.
TaxRate TaxRateDraft `json:"taxRate"`
}
// MarshalJSON override to set the discriminator value or remove
// optional nil slices
func (obj TaxCategoryReplaceTaxRateAction) MarshalJSON() ([]byte, error) {
type Alias TaxCategoryReplaceTaxRateAction
return json.Marshal(struct {
Action string `json:"action"`
*Alias
}{Action: "replaceTaxRate", Alias: (*Alias)(&obj)})
}
type TaxCategorySetDescriptionAction struct {
// Value to set. If empty, any existing value will be removed.
Description *string `json:"description,omitempty"`
}
// MarshalJSON override to set the discriminator value or remove
// optional nil slices
func (obj TaxCategorySetDescriptionAction) MarshalJSON() ([]byte, error) {
type Alias TaxCategorySetDescriptionAction
return json.Marshal(struct {
Action string `json:"action"`
*Alias
}{Action: "setDescription", Alias: (*Alias)(&obj)})
}
type TaxCategorySetKeyAction struct {
// Value to set. If empty, any existing value will be removed.
Key *string `json:"key,omitempty"`
}
// MarshalJSON override to set the discriminator value or remove
// optional nil slices
func (obj TaxCategorySetKeyAction) MarshalJSON() ([]byte, error) {
type Alias TaxCategorySetKeyAction
return json.Marshal(struct {
Action string `json:"action"`
*Alias
}{Action: "setKey", Alias: (*Alias)(&obj)})
}