forked from noebs/noebs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mock_ebs.go
145 lines (114 loc) · 2.95 KB
/
mock_ebs.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
package main
import (
"encoding/json"
"fmt"
"math/rand"
"github.com/adonese/noebs/ebs_fields"
)
func MockEbsResponse(field interface{}, res *ebs_fields.EBSResponse) {
//code := getEbsErrorCodes()
n := getCodesNumber()
chosen := rand.Intn(len(n))
var status string
if chosen == 0 {
status = "Successful"
} else {
status = "Failed"
}
commonFields := ebs_fields.EBSResponse{
ResponseMessage: "Successful",
ResponseStatus: status,
ResponseCode: 0,
ReferenceNumber: "",
ApprovalCode: "",
}
*res = commonFields
switch field.(type) {
case mockCardTransferResponse:
res.ToCard = "9223421234567893212"
case mockWorkingKeyResponse:
fmt.Printf("in workingkey")
key, _ := getWorkingKey()
res.WorkingKey = key
case mockMiniStatementResponse:
res.MiniStatementRecords = nil
}
//res.ImportantEBSFields = commonFields
*res.AdditionalAmount = 544
//res.MiniStatementRecords = generateMiniStatement()
}
type ebsCodes map[int]string
func getEbsErrorCodes() ebsCodes {
code := ebsCodes{
0: "Approval",
103: "Format Error",
130: "Invalid Format",
178: "Original Request Not Found",
158: "Invalid Processing Code",
161: "Withdrawal Limit Exceeded",
191: "Destination Not Available",
194: "Duplicate Transaction",
196: "System Error",
201: "Contact Card Issuer",
205: "External Decline",
251: "Insufficient Fund",
281: "Wrong Customer Information",
338: "PIN Tries Limit Exceeded",
355: "Invalid PIN",
375: "PIN Tries Limit Reached",
362: "Encryption error",
389: "Invalid Terminal ID",
412: "Invalid Transaction",
413: "Merchant Limit Exceeded",
467: "Invalid Amount",
}
return code
}
// Return the corresponding EBS Code. To be used for indexing.
func getCodesNumber() []int {
return []int{0, 103, 130, 178, 158, 161, 191, 194, 196, 201, 205, 251, 281, 338, 355, 375, 362, 389, 412, 413, 467}
}
func getWorkingKey() (string, error) {
return "abcdef0123456789", nil
}
func generateMiniStatement() string {
miniStatement := make(map[string]string)
var l []map[string]string
for i := 0; i <= 12; i++ {
miniStatement["operationAmount"] = fmt.Sprintf("%03d", rand.Intn(999))
miniStatement["operationCode"] = fmt.Sprintf("%03d", rand.Intn(999))
miniStatement["operationSign"] = generateSign()
miniStatement["operationDate"] = generateDate()
l = append(l, miniStatement)
}
s, _ := json.Marshal(l)
return string(s)
}
func generateSign() string {
i := rand.Intn(2)
if i == 0 {
return "-"
}
return "+"
}
func generateDate() string {
m := rand.Intn(13)
d := rand.Intn(32)
return fmt.Sprintf("%02d%02d", d, m)
}
type mockPurchaseResponse struct {
ebs_fields.ImportantEBSFields
ebs_fields.EBSResponse
}
type mockWorkingKeyResponse struct {
ebs_fields.ImportantEBSFields
ebs_fields.EBSResponse
}
type mockMiniStatementResponse struct {
ebs_fields.ImportantEBSFields
ebs_fields.EBSResponse
}
type mockCardTransferResponse struct {
ebs_fields.ImportantEBSFields
ebs_fields.EBSResponse
}