forked from pagarme/pagarme-golang-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createTransfer.go
48 lines (42 loc) · 1.03 KB
/
createTransfer.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
package models
import (
"encoding/json"
)
type CreateTransfer struct {
Amount int `json:"amount"`
SourceId string `json:"source_id"`
TargetId string `json:"target_id"`
Metadata *[]string `json:"metadata,omitempty"`
}
func (c *CreateTransfer) MarshalJSON() (
[]byte,
error) {
return json.Marshal(c.toMap())
}
func (c *CreateTransfer) toMap() map[string]any {
structMap := make(map[string]any)
structMap["amount"] = c.Amount
structMap["source_id"] = c.SourceId
structMap["target_id"] = c.TargetId
if c.Metadata != nil {
structMap["metadata"] = c.Metadata
}
return structMap
}
func (c *CreateTransfer) UnmarshalJSON(input []byte) error {
temp := &struct {
Amount int `json:"amount"`
SourceId string `json:"source_id"`
TargetId string `json:"target_id"`
Metadata *[]string `json:"metadata,omitempty"`
}{}
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
c.Amount = temp.Amount
c.SourceId = temp.SourceId
c.TargetId = temp.TargetId
c.Metadata = temp.Metadata
return nil
}