forked from pagarme/pagarme-golang-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createPixPaymentRequest.go
57 lines (51 loc) · 1.58 KB
/
createPixPaymentRequest.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
package models
import (
"encoding/json"
"log"
"time"
)
// Contains information to create a pix payment
type CreatePixPaymentRequest struct {
ExpiresAt *time.Time `json:"expires_at,omitempty"`
ExpiresIn *int `json:"expires_in,omitempty"`
AdditionalInformation *[]PixAdditionalInformation `json:"additional_information,omitempty"`
}
func (c *CreatePixPaymentRequest) MarshalJSON() (
[]byte,
error) {
return json.Marshal(c.toMap())
}
func (c *CreatePixPaymentRequest) toMap() map[string]any {
structMap := make(map[string]any)
if c.ExpiresAt != nil {
structMap["expires_at"] = c.ExpiresAt.Format(time.RFC3339)
}
if c.ExpiresIn != nil {
structMap["expires_in"] = c.ExpiresIn
}
if c.AdditionalInformation != nil {
structMap["additional_information"] = c.AdditionalInformation
}
return structMap
}
func (c *CreatePixPaymentRequest) UnmarshalJSON(input []byte) error {
temp := &struct {
ExpiresAt *string `json:"expires_at,omitempty"`
ExpiresIn *int `json:"expires_in,omitempty"`
AdditionalInformation *[]PixAdditionalInformation `json:"additional_information,omitempty"`
}{}
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
if temp.ExpiresAt != nil {
ExpiresAtVal, err := time.Parse(time.RFC3339, *temp.ExpiresAt)
if err != nil {
log.Fatalf("Cannot Parse expires_at as % s format.", time.RFC3339)
}
c.ExpiresAt = &ExpiresAtVal
}
c.ExpiresIn = temp.ExpiresIn
c.AdditionalInformation = temp.AdditionalInformation
return nil
}