-
Notifications
You must be signed in to change notification settings - Fork 1
/
invoice_customer.go
105 lines (98 loc) · 3.6 KB
/
invoice_customer.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
package models
import (
"encoding/json"
)
// InvoiceCustomer represents a InvoiceCustomer struct.
// Information about the customer who is owner or recipient the invoiced subscription.
type InvoiceCustomer struct {
ChargifyId Optional[int] `json:"chargify_id"`
FirstName *string `json:"first_name,omitempty"`
LastName *string `json:"last_name,omitempty"`
Organization Optional[string] `json:"organization"`
Email *string `json:"email,omitempty"`
VatNumber Optional[string] `json:"vat_number"`
Reference Optional[string] `json:"reference"`
AdditionalProperties map[string]any `json:"_"`
}
// MarshalJSON implements the json.Marshaler interface for InvoiceCustomer.
// It customizes the JSON marshaling process for InvoiceCustomer objects.
func (i InvoiceCustomer) MarshalJSON() (
[]byte,
error) {
return json.Marshal(i.toMap())
}
// toMap converts the InvoiceCustomer object to a map representation for JSON marshaling.
func (i InvoiceCustomer) toMap() map[string]any {
structMap := make(map[string]any)
MapAdditionalProperties(structMap, i.AdditionalProperties)
if i.ChargifyId.IsValueSet() {
if i.ChargifyId.Value() != nil {
structMap["chargify_id"] = i.ChargifyId.Value()
} else {
structMap["chargify_id"] = nil
}
}
if i.FirstName != nil {
structMap["first_name"] = i.FirstName
}
if i.LastName != nil {
structMap["last_name"] = i.LastName
}
if i.Organization.IsValueSet() {
if i.Organization.Value() != nil {
structMap["organization"] = i.Organization.Value()
} else {
structMap["organization"] = nil
}
}
if i.Email != nil {
structMap["email"] = i.Email
}
if i.VatNumber.IsValueSet() {
if i.VatNumber.Value() != nil {
structMap["vat_number"] = i.VatNumber.Value()
} else {
structMap["vat_number"] = nil
}
}
if i.Reference.IsValueSet() {
if i.Reference.Value() != nil {
structMap["reference"] = i.Reference.Value()
} else {
structMap["reference"] = nil
}
}
return structMap
}
// UnmarshalJSON implements the json.Unmarshaler interface for InvoiceCustomer.
// It customizes the JSON unmarshaling process for InvoiceCustomer objects.
func (i *InvoiceCustomer) UnmarshalJSON(input []byte) error {
var temp invoiceCustomer
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
additionalProperties, err := UnmarshalAdditionalProperties(input, "chargify_id", "first_name", "last_name", "organization", "email", "vat_number", "reference")
if err != nil {
return err
}
i.AdditionalProperties = additionalProperties
i.ChargifyId = temp.ChargifyId
i.FirstName = temp.FirstName
i.LastName = temp.LastName
i.Organization = temp.Organization
i.Email = temp.Email
i.VatNumber = temp.VatNumber
i.Reference = temp.Reference
return nil
}
// invoiceCustomer is a temporary struct used for validating the fields of InvoiceCustomer.
type invoiceCustomer struct {
ChargifyId Optional[int] `json:"chargify_id"`
FirstName *string `json:"first_name,omitempty"`
LastName *string `json:"last_name,omitempty"`
Organization Optional[string] `json:"organization"`
Email *string `json:"email,omitempty"`
VatNumber Optional[string] `json:"vat_number"`
Reference Optional[string] `json:"reference"`
}