/
options.go
104 lines (92 loc) · 2.53 KB
/
options.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
package checkout
// Option - checkout option model
type Option struct {
UseSandbox bool
Process Type
MerchantID string `validate:"required"`
SuccessURL string
CancelURL string
IPNURL string
FailureURL string
ExpiresAfter int
MerchantOrderID string
TotalItemsDeliveryFee float64
TotalItemsTax1 float64
TotalItemsTax2 float64
TotalItemsDiscount float64
TotalItemsHandlingFee float64
}
// OptionsParams - arugment for constructor
type OptionsParams Option
// GetExpressFields - Return Only Required Fields for Express Checkout
// I.e. Exclude all Fields that start with 'Total'
func (option *Option) GetExpressFields() interface{} {
return struct {
UseSandbox bool
Process Type
MerchantID string
SuccessURL string
CancelURL string
IPNURL string
FailureURL string
ExpiresAfter int
MerchantOrderID string
}{
option.UseSandbox,
option.Process,
option.MerchantID,
option.SuccessURL,
option.CancelURL,
option.IPNURL,
option.FailureURL,
option.ExpiresAfter,
option.MerchantOrderID,
}
}
// // Validate and Marshal Option to JSON format
// func (option *Option) ToJSON(forCart bool) (string, error) {
// var fields interface{}
// if !forCart {
// fields = option.GetExpressFields()
// } else {
// fields = option
// }
// var validate *validator.Validate = validator.New()
// err := validate.Struct(option)
// if err != nil {
// return "", err
// } else {
// data, _ := json.Marshal(fields)
// return string(data), nil
// }
// }
// SetOrderFees - Set Order Total Fees
// I.e. Set Fields that start with 'Total'
func (option *Option) SetOrderFees(totalItemsDeliveryFee float64, totalItemsDiscount float64, totalItemsHandlingFee float64, totalItemsTax1, totalItemsTax2 float64) {
option.TotalItemsDeliveryFee = totalItemsDeliveryFee
option.TotalItemsDiscount = totalItemsDiscount
option.TotalItemsHandlingFee = totalItemsHandlingFee
option.TotalItemsTax1 = totalItemsTax1
option.TotalItemsTax2 = totalItemsTax2
}
// NewOption - Option Constructor
func NewOption(
params OptionsParams,
) *Option {
return &Option{
params.UseSandbox,
params.Process,
params.MerchantID,
params.SuccessURL,
params.CancelURL,
params.IPNURL,
params.FailureURL,
params.ExpiresAfter,
params.MerchantOrderID,
params.TotalItemsDeliveryFee,
params.TotalItemsTax1,
params.TotalItemsTax2,
params.TotalItemsDiscount,
params.TotalItemsHandlingFee,
}
}