-
Notifications
You must be signed in to change notification settings - Fork 4
/
token.i_object.go
125 lines (97 loc) · 2.97 KB
/
token.i_object.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package token
import (
"strings"
"github.com/ottemo/commerce/app/models"
"github.com/ottemo/commerce/env"
"github.com/ottemo/commerce/utils"
)
// Get will return the requested attribute when provided a string representation of the attribute
func (it *DefaultVisitorCard) Get(attribute string) interface{} {
switch strings.ToLower(attribute) {
case "_id", "id":
return it.id
case "visitor_id":
return it.visitorID
case "token_id":
return it.tokenID
case "customer_id":
return it.customerID
case "holder":
return it.Holder
case "payment":
return it.Payment
case "type":
return it.Type
case "number":
return it.Number
case "expiration_date":
return it.ExpirationDate
case "token_updated":
return it.TokenUpdated
case "created_at":
return it.CreatedAt
}
return nil
}
// Set will set a Visitor Token attribute and requiring a name and a value
func (it *DefaultVisitorCard) Set(attribute string, value interface{}) error {
switch strings.ToLower(attribute) {
case "_id", "id":
it.id = utils.InterfaceToString(value)
case "visitor_id":
it.visitorID = utils.InterfaceToString(value)
case "token_id":
it.tokenID = utils.InterfaceToString(value)
case "customer_id":
it.customerID = utils.InterfaceToString(value)
case "holder":
it.Holder = utils.InterfaceToString(value)
case "payment":
it.Payment = utils.InterfaceToString(value)
case "type":
it.Type = utils.InterfaceToString(value)
case "number":
it.Number = utils.InterfaceToString(value)
case "expiration_date":
it.ExpirationDate = utils.InterfaceToString(value)
case "expire_year":
it.ExpirationYear = utils.InterfaceToInt(value)
case "expire_month":
it.ExpirationMonth = utils.InterfaceToInt(value)
case "token_updated":
it.TokenUpdated = utils.InterfaceToTime(value)
case "created_at":
it.CreatedAt = utils.InterfaceToTime(value)
}
return nil
}
// FromHashMap will take a map[string]interface and apply the attribute values to the Visitor Token
func (it *DefaultVisitorCard) FromHashMap(input map[string]interface{}) error {
for attribute, value := range input {
if err := it.Set(attribute, value); err != nil {
_ = env.ErrorDispatch(err)
}
}
return nil
}
// ToHashMap will return a set of Visitor Token attributes in a map[string]interface
func (it *DefaultVisitorCard) ToHashMap() map[string]interface{} {
result := make(map[string]interface{})
result["_id"] = it.id
result["visitor_id"] = it.visitorID
result["holder"] = it.Holder
result["payment"] = it.Payment
result["type"] = it.Type
result["number"] = it.Number
result["expiration_date"] = it.ExpirationDate
result["created_at"] = it.CreatedAt
result["token_updated"] = it.TokenUpdated
result["token_id"] = it.tokenID
result["customer_id"] = it.customerID
return result
}
// GetAttributesInfo will return a set of Vistor Token attributes in []models.StructAttributeInfo
func (it *DefaultVisitorCard) GetAttributesInfo() []models.StructAttributeInfo {
info := []models.StructAttributeInfo{}
return info
}