-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.go
286 lines (257 loc) · 7.51 KB
/
model.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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
package simpay
import (
"crypto"
"fmt"
"strings"
"time"
)
const dateTimeFormat = "2006-01-02T15:04:05-07:00"
type Time struct {
time.Time
}
func (t *Time) UnmarshalJSON(b []byte) error {
s := strings.Trim(string(b), "\"")
var err error
t.Time, err = time.Parse(dateTimeFormat, s)
return err
}
func (t Time) MarshalJSON() ([]byte, error) {
return []byte(`"` + t.Format(dateTimeFormat) + `"`), nil
}
type Response struct {
Success bool `json:"success"`
Errors map[string][]string `json:"errors"`
}
type PaginatedResponse struct {
Response
Pagination struct {
Total int `json:"total"`
Count int `json:"count"`
PerPage int `json:"per_page"`
CurrentPage int `json:"current_page"`
TotalPages int `json:"total_pages"`
Links struct {
NextPage string `json:"next_page"`
PrevPage string `json:"prev_page"`
} `json:"links"`
} `json:"pagination"`
}
type SmsServiceListResponse struct {
PaginatedResponse
ServiceList []struct {
Id int `json:"id"`
Type string `json:"type"`
Status string `json:"status"`
Name string `json:"name"`
Prefix string `json:"prefix"`
Suffix string `json:"suffix"`
Adult bool `json:"adult"`
CreatedAt Time `json:"created_at"`
} `json:"data"`
}
type SmsServiceDetailsResponse struct {
Response
ServiceDetails struct {
Id int `json:"id"`
Type string `json:"type"`
Status string `json:"status"`
Name string `json:"name"`
Prefix string `json:"prefix"`
Suffix string `json:"suffix"`
Description string `json:"description"`
Adult bool `json:"adult"`
Numbers []string `json:"numbers"`
CreatedAt Time `json:"created_at"`
} `json:"data"`
}
type SmsTransactionListResponse struct {
PaginatedResponse
TransactionList []struct {
Id int `json:"id"`
From int64 `json:"from"`
Code string `json:"code"`
Used bool `json:"used"`
SendAt Time `json:"send_at"`
} `json:"data"`
}
type SmsTransactionDetailsResponse struct {
Response
TransactionDetails struct {
Id int `json:"id"`
From int64 `json:"from"`
Code string `json:"code"`
Used bool `json:"used"`
SendNumber int `json:"send_number"`
Value float64 `json:"value"`
SendAt Time `json:"send_at"`
} `json:"data"`
}
type NumberDetails struct {
Number int `json:"number"`
Value float64 `json:"value"`
ValueGross float64 `json:"value_gross"`
Adult bool `json:"adult"`
}
type ServiceNumberListResponse struct {
PaginatedResponse
NumberList []NumberDetails `json:"data"`
}
type NumberDetailsResponse struct {
Response
NumberDetails NumberDetails `json:"data"`
}
type NumberListResponse struct {
PaginatedResponse
NumberList []NumberDetails `json:"data"`
}
type CodeVerifyRequest struct {
Code string
Number int64
}
type CodeVerificationResponse struct {
Success bool `json:"success"`
CodeVerification struct {
Used bool `json:"used"`
Code string `json:"code"`
Test bool `json:"test"`
From string `json:"from"`
Number int `json:"number"`
Value float64 `json:"value"`
UsedAt Time `json:"used_at"`
} `json:"data"`
}
type DirectBillingServiceListResponse struct {
PaginatedResponse
ServiceList []struct {
Id int `json:"id"`
Name string `json:"name"`
Suffix string `json:"suffix"`
Status string `json:"status"`
CreatedAt Time `json:"created_at"`
} `json:"data"`
}
type CommissionPercent struct {
Commission0 string `json:"commission_0"`
Commission9 string `json:"commission_9"`
Commission25 string `json:"commission_25"`
}
type DirectBillingServiceDetailsResponse struct {
Response
ServiceDetails struct {
Id int `json:"id"`
Name string `json:"name"`
Suffix string `json:"suffix"`
Status string `json:"status"`
Api struct {
Complete string `json:"complete"`
Failure string `json:"failure"`
} `json:"api"`
Providers struct {
TMobile bool `json:"t-mobile"`
Orange bool `json:"orange"`
Play bool `json:"play"`
Plus bool `json:"plus"`
} `json:"providers"`
Commissions struct {
TMobile CommissionPercent `json:"t-mobile"`
Orange CommissionPercent `json:"orange"`
Play CommissionPercent `json:"play"`
Plus CommissionPercent `json:"plus"`
} `json:"commissions"`
MaxValues struct {
TMobile string `json:"t-mobile"`
Orange string `json:"orange"`
Play string `json:"play"`
Plus string `json:"plus"`
} `json:"maxValues"`
CreatedAt Time `json:"created_at"`
} `json:"data"`
}
type CommissionValue struct {
Net float64 `json:"net"`
Gross float64 `json:"gross"`
}
type CalculateCommissionResponse struct {
Response
CalculateCommission struct {
Orange CommissionValue `json:"orange"`
Play CommissionValue `json:"play"`
TMobile CommissionValue `json:"t-mobile"`
Plus CommissionValue `json:"plus"`
} `json:"data"`
}
type DirectBillingTransactionListResponse struct {
PaginatedResponse
TransactionList []struct {
Id string `json:"id"`
Status string `json:"status"`
Value float64 `json:"value"`
ValueNetto float64 `json:"value_netto"`
Operator string `json:"operator"`
CreatedAt Time `json:"created_at"`
UpdatedAt Time `json:"updated_at"`
} `json:"data"`
}
type DirectBillingTransactionDetailsResponse struct {
Response
TransactionDetails struct {
Id string `json:"id"`
Status string `json:"status"`
PhoneNumber interface{} `json:"phoneNumber"`
Control string `json:"control"`
Value float64 `json:"value"`
ValueNetto float64 `json:"value_netto"`
Operator string `json:"operator"`
Notify struct {
IsSend bool `json:"is_send"`
LastSendAt Time `json:"last_send_at"`
Count int `json:"count"`
} `json:"notify"`
CreatedAt Time `json:"created_at"`
UpdatedAt Time `json:"updated_at"`
} `json:"data"`
}
type GenerateTransactionRequest struct {
Amount float64 `json:"amount"`
AmountType string `json:"amountType"`
Description string `json:"description"`
Control string `json:"control"`
Returns struct {
Success string `json:"success"`
Failure string `json:"failure"`
} `json:"returns"`
PhoneNumber string `json:"phoneNumber"`
Signature string `json:"signature"`
}
func (r GenerateTransactionRequest) Sign(key string) {
fields := []string{fmt.Sprintf("%f", r.Amount), r.AmountType, r.Description, r.Control, r.Returns.Success, r.Returns.Failure, r.PhoneNumber, key}
r.Signature = string(crypto.SHA256.New().Sum([]byte(strings.Join(fields, "|"))))
}
func (r GenerateTransactionRequest) SignWithAmountAndControl(key string) {
r.Signature = string(crypto.SHA256.New().Sum([]byte(strings.Join([]string{fmt.Sprintf("%f", r.Amount), r.Control, key}, "|"))))
}
type DirectBillingGenerateTransactionResponse struct {
Response
Data struct {
TransactionId string `json:"transactionId"`
RedirectUrl string `json:"redirectUrl"`
} `json:"data"`
}
type DirectBillingTransactionNotification struct {
Id string `json:"id"`
ServiceId int `json:"service_id"`
Status string `json:"status"`
Values struct {
Net float64 `json:"net"`
Gross float64 `json:"gross"`
Partner float64 `json:"partner"`
} `json:"values"`
Returns struct {
Complete string `json:"complete"`
Failure string `json:"failure"`
} `json:"returns"`
Control string `json:"control"`
NumberFrom string `json:"number_from"`
Provider int `json:"provider"`
Signature string `json:"Signature"`
}