forked from checkout/checkout-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
responses.go
75 lines (66 loc) · 1.78 KB
/
responses.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
package issuing
import (
"encoding/json"
"fmt"
"time"
"github.com/PaddleHQ/checkout-sdk-go/common"
"github.com/PaddleHQ/checkout-sdk-go/errors"
)
type (
CardControlData struct {
HttpMetadata common.HttpMetadata
ControlType ControlType `json:"control_type,omitempty"`
Id string `json:"id,omitempty"`
Description string `json:"description,omitempty"`
TargetId string `json:"target_id,omitempty"`
CreatedDate *time.Time `json:"created_date,omitempty"`
LastModifiedDate *time.Time `json:"last_modified_date,omitempty"`
}
CardControlResponse struct {
CardControlData
Limit CardLimit `json:"limit,omitempty"`
}
CardLimit interface {
GetType() ControlType
}
)
func (l VelocityLimit) GetType() ControlType {
return VelocityLimitType
}
func (l MccLimit) GetType() ControlType {
return MccLimitType
}
func (s *CardControlResponse) UnmarshalJSON(data []byte) error {
var controlData CardControlData
if err := json.Unmarshal(data, &controlData); err != nil {
return err
}
s.CardControlData = controlData
switch controlData.ControlType {
case VelocityLimitType:
var limit = struct {
VelocityLimit VelocityLimit `json:"velocity_limit,omitempty"`
}{}
if err := json.Unmarshal(data, &limit); err != nil {
return nil
}
s.Limit = limit.VelocityLimit
case MccLimitType:
var limit = struct {
MccLimit MccLimit `json:"mcc_limit,omitempty"`
}{}
if err := json.Unmarshal(data, &limit); err != nil {
return nil
}
s.Limit = limit.MccLimit
default:
return errors.UnsupportedTypeError(fmt.Sprintf("%s unsupported", controlData.ControlType))
}
return nil
}
type (
CardControlsQueryResponse struct {
HttpMetadata common.HttpMetadata
Controls []CardControlResponse `json:"controls,omitempty"`
}
)