-
Notifications
You must be signed in to change notification settings - Fork 1
/
update_component.go
127 lines (120 loc) · 5.12 KB
/
update_component.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
package models
import (
"encoding/json"
)
// UpdateComponent represents a UpdateComponent struct.
type UpdateComponent struct {
Handle *string `json:"handle,omitempty"`
// The name of the Component, suitable for display on statements. i.e. Text Messages.
Name *string `json:"name,omitempty"`
// The description of the component.
Description Optional[string] `json:"description"`
AccountingCode Optional[string] `json:"accounting_code"`
// Boolean flag describing whether a component is taxable or not.
Taxable *bool `json:"taxable,omitempty"`
// A string representing the tax code related to the component type. This is especially important when using the Avalara service to tax based on locale. This attribute has a max length of 10 characters.
TaxCode Optional[string] `json:"tax_code"`
// One of the following: Business Software, Consumer Software, Digital Services, Physical Goods, Other
ItemCategory Optional[ItemCategory] `json:"item_category"`
DisplayOnHostedPage *bool `json:"display_on_hosted_page,omitempty"`
// The type of credit to be created when upgrading/downgrading. Defaults to the component and then site setting if one is not provided.
// Available values: `full`, `prorated`, `none`.
UpgradeCharge Optional[CreditType] `json:"upgrade_charge"`
AdditionalProperties map[string]any `json:"_"`
}
// MarshalJSON implements the json.Marshaler interface for UpdateComponent.
// It customizes the JSON marshaling process for UpdateComponent objects.
func (u UpdateComponent) MarshalJSON() (
[]byte,
error) {
return json.Marshal(u.toMap())
}
// toMap converts the UpdateComponent object to a map representation for JSON marshaling.
func (u UpdateComponent) toMap() map[string]any {
structMap := make(map[string]any)
MapAdditionalProperties(structMap, u.AdditionalProperties)
if u.Handle != nil {
structMap["handle"] = u.Handle
}
if u.Name != nil {
structMap["name"] = u.Name
}
if u.Description.IsValueSet() {
if u.Description.Value() != nil {
structMap["description"] = u.Description.Value()
} else {
structMap["description"] = nil
}
}
if u.AccountingCode.IsValueSet() {
if u.AccountingCode.Value() != nil {
structMap["accounting_code"] = u.AccountingCode.Value()
} else {
structMap["accounting_code"] = nil
}
}
if u.Taxable != nil {
structMap["taxable"] = u.Taxable
}
if u.TaxCode.IsValueSet() {
if u.TaxCode.Value() != nil {
structMap["tax_code"] = u.TaxCode.Value()
} else {
structMap["tax_code"] = nil
}
}
if u.ItemCategory.IsValueSet() {
if u.ItemCategory.Value() != nil {
structMap["item_category"] = u.ItemCategory.Value()
} else {
structMap["item_category"] = nil
}
}
if u.DisplayOnHostedPage != nil {
structMap["display_on_hosted_page"] = u.DisplayOnHostedPage
}
if u.UpgradeCharge.IsValueSet() {
if u.UpgradeCharge.Value() != nil {
structMap["upgrade_charge"] = u.UpgradeCharge.Value()
} else {
structMap["upgrade_charge"] = nil
}
}
return structMap
}
// UnmarshalJSON implements the json.Unmarshaler interface for UpdateComponent.
// It customizes the JSON unmarshaling process for UpdateComponent objects.
func (u *UpdateComponent) UnmarshalJSON(input []byte) error {
var temp updateComponent
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
additionalProperties, err := UnmarshalAdditionalProperties(input, "handle", "name", "description", "accounting_code", "taxable", "tax_code", "item_category", "display_on_hosted_page", "upgrade_charge")
if err != nil {
return err
}
u.AdditionalProperties = additionalProperties
u.Handle = temp.Handle
u.Name = temp.Name
u.Description = temp.Description
u.AccountingCode = temp.AccountingCode
u.Taxable = temp.Taxable
u.TaxCode = temp.TaxCode
u.ItemCategory = temp.ItemCategory
u.DisplayOnHostedPage = temp.DisplayOnHostedPage
u.UpgradeCharge = temp.UpgradeCharge
return nil
}
// updateComponent is a temporary struct used for validating the fields of UpdateComponent.
type updateComponent struct {
Handle *string `json:"handle,omitempty"`
Name *string `json:"name,omitempty"`
Description Optional[string] `json:"description"`
AccountingCode Optional[string] `json:"accounting_code"`
Taxable *bool `json:"taxable,omitempty"`
TaxCode Optional[string] `json:"tax_code"`
ItemCategory Optional[ItemCategory] `json:"item_category"`
DisplayOnHostedPage *bool `json:"display_on_hosted_page,omitempty"`
UpgradeCharge Optional[CreditType] `json:"upgrade_charge"`
}