forked from pagarme/pagarme-golang-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getPricingSchemeResponse.go
63 lines (56 loc) · 1.9 KB
/
getPricingSchemeResponse.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
package models
import (
"encoding/json"
"github.com/apimatic/go-core-runtime/types"
)
// Response object for getting a pricing scheme
type GetPricingSchemeResponse struct {
Price types.Optional[int] `json:"price"`
SchemeType types.Optional[string] `json:"scheme_type"`
PriceBrackets types.Optional[[]GetPriceBracketResponse] `json:"price_brackets"`
MinimumPrice types.Optional[int] `json:"minimum_price"`
Percentage types.Optional[float64] `json:"percentage"`
}
func (g *GetPricingSchemeResponse) MarshalJSON() (
[]byte,
error) {
return json.Marshal(g.toMap())
}
func (g *GetPricingSchemeResponse) toMap() map[string]any {
structMap := make(map[string]any)
if g.Price.IsValueSet() {
structMap["price"] = g.Price.Value()
}
if g.SchemeType.IsValueSet() {
structMap["scheme_type"] = g.SchemeType.Value()
}
if g.PriceBrackets.IsValueSet() {
structMap["price_brackets"] = g.PriceBrackets.Value()
}
if g.MinimumPrice.IsValueSet() {
structMap["minimum_price"] = g.MinimumPrice.Value()
}
if g.Percentage.IsValueSet() {
structMap["percentage"] = g.Percentage.Value()
}
return structMap
}
func (g *GetPricingSchemeResponse) UnmarshalJSON(input []byte) error {
temp := &struct {
Price types.Optional[int] `json:"price"`
SchemeType types.Optional[string] `json:"scheme_type"`
PriceBrackets types.Optional[[]GetPriceBracketResponse] `json:"price_brackets"`
MinimumPrice types.Optional[int] `json:"minimum_price"`
Percentage types.Optional[float64] `json:"percentage"`
}{}
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
g.Price = temp.Price
g.SchemeType = temp.SchemeType
g.PriceBrackets = temp.PriceBrackets
g.MinimumPrice = temp.MinimumPrice
g.Percentage = temp.Percentage
return nil
}