forked from pagarme/pagarme-golang-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getSplitResponse.go
69 lines (62 loc) · 1.87 KB
/
getSplitResponse.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
package models
import (
"encoding/json"
"github.com/apimatic/go-core-runtime/types"
)
// Split response
type GetSplitResponse struct {
Type types.Optional[string] `json:"type"`
Amount types.Optional[int] `json:"amount"`
Recipient types.Optional[GetRecipientResponse] `json:"recipient"`
GatewayId types.Optional[string] `json:"gateway_id"`
Options types.Optional[GetSplitOptionsResponse] `json:"options"`
Id types.Optional[string] `json:"id"`
}
func (g *GetSplitResponse) MarshalJSON() (
[]byte,
error) {
return json.Marshal(g.toMap())
}
func (g *GetSplitResponse) toMap() map[string]any {
structMap := make(map[string]any)
if g.Type.IsValueSet() {
structMap["type"] = g.Type.Value()
}
if g.Amount.IsValueSet() {
structMap["amount"] = g.Amount.Value()
}
if g.Recipient.IsValueSet() {
structMap["recipient"] = g.Recipient.Value()
}
if g.GatewayId.IsValueSet() {
structMap["gateway_id"] = g.GatewayId.Value()
}
if g.Options.IsValueSet() {
structMap["options"] = g.Options.Value()
}
if g.Id.IsValueSet() {
structMap["id"] = g.Id.Value()
}
return structMap
}
func (g *GetSplitResponse) UnmarshalJSON(input []byte) error {
temp := &struct {
Type types.Optional[string] `json:"type"`
Amount types.Optional[int] `json:"amount"`
Recipient types.Optional[GetRecipientResponse] `json:"recipient"`
GatewayId types.Optional[string] `json:"gateway_id"`
Options types.Optional[GetSplitOptionsResponse] `json:"options"`
Id types.Optional[string] `json:"id"`
}{}
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
g.Type = temp.Type
g.Amount = temp.Amount
g.Recipient = temp.Recipient
g.GatewayId = temp.GatewayId
g.Options = temp.Options
g.Id = temp.Id
return nil
}