-
Notifications
You must be signed in to change notification settings - Fork 4
/
config.go
263 lines (230 loc) · 7.33 KB
/
config.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
package fedex
import (
"github.com/ottemo/commerce/env"
"github.com/ottemo/commerce/utils"
"github.com/ottemo/commerce/app/models"
)
// setupConfig setups package configuration values for a system
func setupConfig() error {
if config := env.GetConfig(); config != nil {
err := config.RegisterItem(env.StructConfigItem{
Path: ConstConfigPathGroup,
Value: nil,
Type: env.ConstConfigTypeGroup,
Editor: "",
Options: nil,
Label: "FedEx",
Description: "Federal express shipping method",
Image: "",
}, nil)
if err != nil {
return env.ErrorDispatch(err)
}
err = config.RegisterItem(env.StructConfigItem{
Path: ConstConfigPathEnabled,
Value: false,
Type: env.ConstConfigTypeBoolean,
Editor: "boolean",
Options: nil,
Label: "Enabled",
Description: "enables/disables shipping method in checkout",
Image: "",
}, func(value interface{}) (interface{}, error) { return utils.InterfaceToBool(value), nil })
if err != nil {
return env.ErrorDispatch(err)
}
err = config.RegisterItem(env.StructConfigItem{
Path: ConstConfigPathTitle,
Value: "Federal Express",
Type: env.ConstConfigTypeVarchar,
Editor: "line_text",
Options: nil,
Label: "Title",
Description: "shipping method name in checkout",
Image: "",
}, func(value interface{}) (interface{}, error) {
if utils.CheckIsBlank(value) {
err := env.ErrorNew(ConstErrorModule, env.ConstErrorLevelStartStop, "e37e8ab2-ab87-40d0-b368-4e2f930d79b1", "can't be blank")
return nil, env.ErrorDispatch(err)
}
return value, nil
})
if err != nil {
return env.ErrorDispatch(err)
}
err = config.RegisterItem(env.StructConfigItem{
Path: ConstConfigPathGateway,
Value: "https://wsbeta.fedex.com:443/web-services",
Type: env.ConstConfigTypeVarchar,
Editor: "line_text",
Options: nil,
Label: "Gateway",
Description: "web services gateway",
Image: "",
}, nil)
if err != nil {
return env.ErrorDispatch(err)
}
err = config.RegisterItem(env.StructConfigItem{
Path: ConstConfigPathKey,
Value: "",
Type: env.ConstConfigTypeVarchar,
Editor: "line_text",
Options: nil,
Label: "Account Key",
Description: "FedEx account key",
Image: "",
}, nil)
if err != nil {
return env.ErrorDispatch(err)
}
err = config.RegisterItem(env.StructConfigItem{
Path: ConstConfigPathPassword,
Value: "",
Type: env.ConstConfigTypeSecret,
Editor: "password",
Options: nil,
Label: "Account Password",
Description: "FedEx account password",
Image: "",
}, nil)
if err != nil {
return env.ErrorDispatch(err)
}
err = config.RegisterItem(env.StructConfigItem{
Path: ConstConfigPathNumber,
Value: "",
Type: env.ConstConfigTypeVarchar,
Editor: "line_text",
Options: nil,
Label: "Account Number",
Description: "FedEx account number",
Image: "",
}, nil)
if err != nil {
return env.ErrorDispatch(err)
}
err = config.RegisterItem(env.StructConfigItem{
Path: ConstConfigPathMeter,
Value: "",
Type: env.ConstConfigTypeVarchar,
Editor: "line_text",
Options: nil,
Label: "Account Meter",
Description: "FedEx account meter value",
Image: "",
}, nil)
if err != nil {
return env.ErrorDispatch(err)
}
err = config.RegisterItem(env.StructConfigItem{
Path: ConstConfigPathDefaultWeight,
Value: 0.1,
Type: env.ConstConfigTypeDecimal,
Editor: "decimal",
Options: nil,
Label: "Default weight",
Description: "Will be used if product do not have this value (in pounds)",
Image: "",
}, nil)
if err != nil {
return env.ErrorDispatch(err)
}
err = config.RegisterItem(env.StructConfigItem{
Path: ConstConfigPathAllowedMethods,
Value: "",
Type: env.ConstConfigTypeVarchar,
Editor: "multi_select",
Options: ConstShippingMethods,
Label: "Allowed methods",
Description: "To customer will be proposed only allowed methods",
Image: "",
}, nil)
if err != nil {
return env.ErrorDispatch(err)
}
err = config.RegisterItem(env.StructConfigItem{
Path: ConstConfigPathDropoff,
Value: "REGULAR_PICKUP",
Type: env.ConstConfigTypeVarchar,
Editor: "select",
Options: ConstShippingDropoff,
Label: "Dropoff",
Description: "dropoff method",
Image: "",
}, func(value interface{}) (interface{}, error) {
stringValue := utils.InterfaceToString(value)
if _, present := ConstShippingDropoff[stringValue]; !present {
err := env.ErrorNew(ConstErrorModule, env.ConstErrorLevelStartStop, "c2129328-0477-4741-a09f-fc96863e936d", "wrong value")
return nil, env.ErrorDispatch(err)
}
return value, nil
})
if err != nil {
return env.ErrorDispatch(err)
}
err = config.RegisterItem(env.StructConfigItem{
Path: ConstConfigPathPackaging,
Value: "FEDEX_PAK",
Type: env.ConstConfigTypeVarchar,
Editor: "select",
Options: ConstShippingPackaging,
Label: "Packing",
Description: "packing method",
Image: "",
}, func(value interface{}) (interface{}, error) {
stringValue := utils.InterfaceToString(value)
if _, present := ConstShippingPackaging[stringValue]; !present {
err := env.ErrorNew(ConstErrorModule, env.ConstErrorLevelStartStop, "890ae42a-b890-4481-81ba-5165a78acd18", "wrong value")
return nil, env.ErrorDispatch(err)
}
return value, nil
})
if err != nil {
return env.ErrorDispatch(err)
}
err = config.RegisterItem(env.StructConfigItem{
Path: ConstConfigPathDebugLog,
Value: false,
Type: env.ConstConfigTypeBoolean,
Editor: "boolean",
Options: nil,
Label: "Debug log",
Description: "enables/disables shipping method debug log",
Image: "",
}, func(value interface{}) (interface{}, error) { return utils.InterfaceToBool(value), nil })
if err != nil {
return env.ErrorDispatch(err)
}
err = config.RegisterItem(env.StructConfigItem{
Path: ConstConfigPathAllowCountries,
Value: "",
Type: env.ConstConfigTypeVarchar,
Editor: "multi_select",
Options: utils.EncodeToJSONString(models.ConstCountriesList),
Label: "Allow countries",
Description: "",
Image: "",
}, nil)
if err != nil {
return env.ErrorDispatch(err)
}
err = config.RegisterItem(env.StructConfigItem{
Path: ConstConfigPathResidential,
Value: true,
Type: env.ConstConfigTypeBoolean,
Editor: "boolean",
Options: nil,
Label: "Residential Delivery",
Description: "Indicates whether this delivery residential (as opposed to commercial).",
Image: "",
}, func(value interface{}) (interface{}, error) { return utils.InterfaceToBool(value), nil })
if err != nil {
return env.ErrorDispatch(err)
}
} else {
err := env.ErrorNew(ConstErrorModule, env.ConstErrorLevelStartStop, "ba621a64-5ab2-4f65-8953-1165e4a401ac", "Unable to obtain configuration for FedEx")
return env.ErrorDispatch(err)
}
return nil
}