-
Notifications
You must be signed in to change notification settings - Fork 2
/
billing_manifest_item.go
132 lines (125 loc) · 5.99 KB
/
billing_manifest_item.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
package models
import (
"encoding/json"
)
// BillingManifestItem represents a BillingManifestItem struct.
type BillingManifestItem struct {
// A handle for the line item transaction type
TransactionType *LineItemTransactionType `json:"transaction_type,omitempty"`
// A handle for the billing manifest line item kind
Kind *BillingManifestLineItemKind `json:"kind,omitempty"`
AmountInCents *int64 `json:"amount_in_cents,omitempty"`
Memo *string `json:"memo,omitempty"`
DiscountAmountInCents *int64 `json:"discount_amount_in_cents,omitempty"`
TaxableAmountInCents *int64 `json:"taxable_amount_in_cents,omitempty"`
ComponentId *int `json:"component_id,omitempty"`
ComponentHandle *string `json:"component_handle,omitempty"`
ComponentName *string `json:"component_name,omitempty"`
ProductId *int `json:"product_id,omitempty"`
ProductHandle *string `json:"product_handle,omitempty"`
ProductName *string `json:"product_name,omitempty"`
PeriodRangeStart *string `json:"period_range_start,omitempty"`
PeriodRangeEnd *string `json:"period_range_end,omitempty"`
AdditionalProperties map[string]any `json:"_"`
}
// MarshalJSON implements the json.Marshaler interface for BillingManifestItem.
// It customizes the JSON marshaling process for BillingManifestItem objects.
func (b BillingManifestItem) MarshalJSON() (
[]byte,
error) {
return json.Marshal(b.toMap())
}
// toMap converts the BillingManifestItem object to a map representation for JSON marshaling.
func (b BillingManifestItem) toMap() map[string]any {
structMap := make(map[string]any)
MapAdditionalProperties(structMap, b.AdditionalProperties)
if b.TransactionType != nil {
structMap["transaction_type"] = b.TransactionType
}
if b.Kind != nil {
structMap["kind"] = b.Kind
}
if b.AmountInCents != nil {
structMap["amount_in_cents"] = b.AmountInCents
}
if b.Memo != nil {
structMap["memo"] = b.Memo
}
if b.DiscountAmountInCents != nil {
structMap["discount_amount_in_cents"] = b.DiscountAmountInCents
}
if b.TaxableAmountInCents != nil {
structMap["taxable_amount_in_cents"] = b.TaxableAmountInCents
}
if b.ComponentId != nil {
structMap["component_id"] = b.ComponentId
}
if b.ComponentHandle != nil {
structMap["component_handle"] = b.ComponentHandle
}
if b.ComponentName != nil {
structMap["component_name"] = b.ComponentName
}
if b.ProductId != nil {
structMap["product_id"] = b.ProductId
}
if b.ProductHandle != nil {
structMap["product_handle"] = b.ProductHandle
}
if b.ProductName != nil {
structMap["product_name"] = b.ProductName
}
if b.PeriodRangeStart != nil {
structMap["period_range_start"] = b.PeriodRangeStart
}
if b.PeriodRangeEnd != nil {
structMap["period_range_end"] = b.PeriodRangeEnd
}
return structMap
}
// UnmarshalJSON implements the json.Unmarshaler interface for BillingManifestItem.
// It customizes the JSON unmarshaling process for BillingManifestItem objects.
func (b *BillingManifestItem) UnmarshalJSON(input []byte) error {
var temp billingManifestItem
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
additionalProperties, err := UnmarshalAdditionalProperties(input, "transaction_type", "kind", "amount_in_cents", "memo", "discount_amount_in_cents", "taxable_amount_in_cents", "component_id", "component_handle", "component_name", "product_id", "product_handle", "product_name", "period_range_start", "period_range_end")
if err != nil {
return err
}
b.AdditionalProperties = additionalProperties
b.TransactionType = temp.TransactionType
b.Kind = temp.Kind
b.AmountInCents = temp.AmountInCents
b.Memo = temp.Memo
b.DiscountAmountInCents = temp.DiscountAmountInCents
b.TaxableAmountInCents = temp.TaxableAmountInCents
b.ComponentId = temp.ComponentId
b.ComponentHandle = temp.ComponentHandle
b.ComponentName = temp.ComponentName
b.ProductId = temp.ProductId
b.ProductHandle = temp.ProductHandle
b.ProductName = temp.ProductName
b.PeriodRangeStart = temp.PeriodRangeStart
b.PeriodRangeEnd = temp.PeriodRangeEnd
return nil
}
// billingManifestItem is a temporary struct used for validating the fields of BillingManifestItem.
type billingManifestItem struct {
TransactionType *LineItemTransactionType `json:"transaction_type,omitempty"`
Kind *BillingManifestLineItemKind `json:"kind,omitempty"`
AmountInCents *int64 `json:"amount_in_cents,omitempty"`
Memo *string `json:"memo,omitempty"`
DiscountAmountInCents *int64 `json:"discount_amount_in_cents,omitempty"`
TaxableAmountInCents *int64 `json:"taxable_amount_in_cents,omitempty"`
ComponentId *int `json:"component_id,omitempty"`
ComponentHandle *string `json:"component_handle,omitempty"`
ComponentName *string `json:"component_name,omitempty"`
ProductId *int `json:"product_id,omitempty"`
ProductHandle *string `json:"product_handle,omitempty"`
ProductName *string `json:"product_name,omitempty"`
PeriodRangeStart *string `json:"period_range_start,omitempty"`
PeriodRangeEnd *string `json:"period_range_end,omitempty"`
}