forked from pagarme/pagarme-golang-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getBinResponse.go
76 lines (68 loc) · 1.84 KB
/
getBinResponse.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
package models
import (
"encoding/json"
"github.com/apimatic/go-core-runtime/types"
)
// Response object for getting a bin info
type GetBinResponse struct {
Brand types.Optional[string] `json:"brand"`
BrandName types.Optional[string] `json:"brandName"`
Gaps types.Optional[[]int] `json:"gaps"`
Lenghts types.Optional[[]int] `json:"lenghts"`
Mask types.Optional[string] `json:"mask"`
Input types.Optional[string] `json:"input"`
Cvv types.Optional[int] `json:"cvv"`
}
func (g *GetBinResponse) MarshalJSON() (
[]byte,
error) {
return json.Marshal(g.toMap())
}
func (g *GetBinResponse) toMap() map[string]any {
structMap := make(map[string]any)
if g.Brand.IsValueSet() {
structMap["brand"] = g.Brand.Value()
}
if g.BrandName.IsValueSet() {
structMap["brandName"] = g.BrandName.Value()
}
if g.Gaps.IsValueSet() {
structMap["gaps"] = g.Gaps.Value()
}
if g.Lenghts.IsValueSet() {
structMap["lenghts"] = g.Lenghts.Value()
}
if g.Mask.IsValueSet() {
structMap["mask"] = g.Mask.Value()
}
if g.Input.IsValueSet() {
structMap["input"] = g.Input.Value()
}
if g.Cvv.IsValueSet() {
structMap["cvv"] = g.Cvv.Value()
}
return structMap
}
func (g *GetBinResponse) UnmarshalJSON(input []byte) error {
temp := &struct {
Brand types.Optional[string] `json:"brand"`
BrandName types.Optional[string] `json:"brandName"`
Gaps types.Optional[[]int] `json:"gaps"`
Lenghts types.Optional[[]int] `json:"lenghts"`
Mask types.Optional[string] `json:"mask"`
Input types.Optional[string] `json:"input"`
Cvv types.Optional[int] `json:"cvv"`
}{}
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
g.Brand = temp.Brand
g.BrandName = temp.BrandName
g.Gaps = temp.Gaps
g.Lenghts = temp.Lenghts
g.Mask = temp.Mask
g.Input = temp.Input
g.Cvv = temp.Cvv
return nil
}