forked from pagarme/pagarme-golang-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getInvoiceItemResponse.go
75 lines (68 loc) · 2.49 KB
/
getInvoiceItemResponse.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
package models
import (
"encoding/json"
"github.com/apimatic/go-core-runtime/types"
)
// Response object for getting an invoice item
type GetInvoiceItemResponse struct {
Amount types.Optional[int] `json:"amount"`
Description types.Optional[string] `json:"description"`
PricingScheme types.Optional[GetPricingSchemeResponse] `json:"pricing_scheme"`
PriceBracket types.Optional[GetPriceBracketResponse] `json:"price_bracket"`
Quantity types.Optional[int] `json:"quantity"`
Name types.Optional[string] `json:"name"`
SubscriptionItemId types.Optional[string] `json:"subscription_item_id"`
}
func (g *GetInvoiceItemResponse) MarshalJSON() (
[]byte,
error) {
return json.Marshal(g.toMap())
}
func (g *GetInvoiceItemResponse) toMap() map[string]any {
structMap := make(map[string]any)
if g.Amount.IsValueSet() {
structMap["amount"] = g.Amount.Value()
}
if g.Description.IsValueSet() {
structMap["description"] = g.Description.Value()
}
if g.PricingScheme.IsValueSet() {
structMap["pricing_scheme"] = g.PricingScheme.Value()
}
if g.PriceBracket.IsValueSet() {
structMap["price_bracket"] = g.PriceBracket.Value()
}
if g.Quantity.IsValueSet() {
structMap["quantity"] = g.Quantity.Value()
}
if g.Name.IsValueSet() {
structMap["name"] = g.Name.Value()
}
if g.SubscriptionItemId.IsValueSet() {
structMap["subscription_item_id"] = g.SubscriptionItemId.Value()
}
return structMap
}
func (g *GetInvoiceItemResponse) UnmarshalJSON(input []byte) error {
temp := &struct {
Amount types.Optional[int] `json:"amount"`
Description types.Optional[string] `json:"description"`
PricingScheme types.Optional[GetPricingSchemeResponse] `json:"pricing_scheme"`
PriceBracket types.Optional[GetPriceBracketResponse] `json:"price_bracket"`
Quantity types.Optional[int] `json:"quantity"`
Name types.Optional[string] `json:"name"`
SubscriptionItemId types.Optional[string] `json:"subscription_item_id"`
}{}
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
g.Amount = temp.Amount
g.Description = temp.Description
g.PricingScheme = temp.PricingScheme
g.PriceBracket = temp.PriceBracket
g.Quantity = temp.Quantity
g.Name = temp.Name
g.SubscriptionItemId = temp.SubscriptionItemId
return nil
}