-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtypes.go
279 lines (250 loc) · 13.8 KB
/
types.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
/*
Copyright (c) 2022-2023 Golang Tanzania
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package mpesa
import (
"net/http"
"sync"
"time"
)
const (
Address = "openapi.m-pesa.com"
Ssl = true
Port = 443
ProdEndpoint = "/openapi/ipg/v2/vodacomTZN/"
SandboxEndpoint = "/sandbox/ipg/v2/vodacomTZN/"
SessionEndPath = "getSession"
C2BPaymentPath = "c2bPayment/singleStage"
B2BPaymentPath = "b2bPayment"
B2CPaymentPath = "b2cPayment"
ReversalPath = "reversal"
QueryTxStatusPath = "queryTransactionStatus"
DirectDebitPath = "directDebitCreation"
DebitDBPaymentPath = "directDebitPayment"
QueryBeneficialPath = "queryBeneficiaryName"
QueryDirectDBPath = "queryDirectDebit"
CancelDirectDBPath = "directDebitCancel"
SandboxPublicKey = "MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEArv9yxA69XQKBo24BaF/D+fvlqmGdYjqLQ5WtNBb5tquqGvAvG3WMFETVUSow/LizQalxj2ElMVrUmzu5mGGkxK08bWEXF7a1DEvtVJs6nppIlFJc2SnrU14AOrIrB28ogm58JjAl5BOQawOXD5dfSk7MaAA82pVHoIqEu0FxA8BOKU+RGTihRU+ptw1j4bsAJYiPbSX6i71gfPvwHPYamM0bfI4CmlsUUR3KvCG24rB6FNPcRBhM3jDuv8ae2kC33w9hEq8qNB55uw51vK7hyXoAa+U7IqP1y6nBdlN25gkxEA8yrsl1678cspeXr+3ciRyqoRgj9RD/ONbJhhxFvt1cLBh+qwK2eqISfBb06eRnNeC71oBokDm3zyCnkOtMDGl7IvnMfZfEPFCfg5QgJVk1msPpRvQxmEsrX9MQRyFVzgy2CWNIb7c+jPapyrNwoUbANlN8adU1m6yOuoX7F49x+OjiG2se0EJ6nafeKUXw/+hiJZvELUYgzKUtMAZVTNZfT8jjb58j8GVtuS+6TM2AutbejaCV84ZK58E2CRJqhmjQibEUO6KPdD7oTlEkFy52Y1uOOBXgYpqMzufNPmfdqqqSM4dU70PO8ogyKGiLAIxCetMjjm6FCMEA3Kc8K0Ig7/XtFm9By6VxTJK1Mg36TlHaZKP6VzVLXMtesJECAwEAAQ=="
OpenapiPublicKey = "MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAietPTdEyyoV/wvxRjS5pSn3ZBQH9hnVtQC9SFLgM9IkomEX9Vu9fBg2MzWSSqkQlaYIGFGH3d69Q5NOWkRo+Y8p5a61sc9hZ+ItAiEL9KIbZzhnMwi12jUYCTff0bVTsTGSNUePQ2V42sToOIKCeBpUtwWKhhW3CSpK7S1iJhS9H22/BT/pk21Jd8btwMLUHfVD95iXbHNM8u6vFaYuHczx966T7gpa9RGGXRtiOr3ScJq1515tzOSOsHTPHLTun59nxxJiEjKoI4Lb9h6IlauvcGAQHp5q6/2XmxuqZdGzh39uLac8tMSmY3vC3fiHYC3iMyTb7eXqATIhDUOf9mOSbgZMS19iiVZvz8igDl950IMcelJwcj0qCLoufLE5y8ud5WIw47OCVkD7tcAEPmVWlCQ744SIM5afw+Jg50T1SEtu3q3GiL0UQ6KTLDyDEt5BL9HWXAIXsjFdPDpX1jtxZavVQV+Jd7FXhuPQuDbh12liTROREdzatYWRnrhzeOJ5Se9xeXLvYSj8DmAI4iFf2cVtWCzj/02uK4+iIGXlX7lHP1W+tycLS7Pe2RdtC2+oz5RSSqb5jI4+3iEY/vZjSMBVk69pCDzZy4ZE8LBgyEvSabJ/cddwWmShcRS+21XvGQ1uXYLv0FCTEHHobCfmn2y8bJBb/Hct53BaojWUCAwEAAQ=="
ReqNewSessionKeyBeforeExpiresIn = time.Duration(60) * time.Second
)
type Env int
const (
Sandbox Env = iota
Production
)
type (
Client struct {
mu sync.Mutex
Client *http.Client
Keys *Keys
Environment Env
SessionKey string
ExpiresAt time.Time
SessionLife int32
}
Keys struct {
PublicKey string
ApiKey string
}
SessionKeyResponse struct {
OutputResponseCode string `json:"output_ResponseCode"`
OutputResponseDesc string `json:"output_ResponseDesc"`
OutputSessionID string `json:"output_SessionID"`
}
C2BPaymentRequest struct {
Amount string `json:"input_Amount"`
CustomerMSISDN string `json:"input_CustomerMSISDN"`
Country string `json:"input_Country"`
Currency string `json:"input_Currency"`
ServiceProviderCode string `json:"input_ServiceProviderCode"`
TransactionReference string `json:"input_TransactionReference"`
ThirdPartyConversationID string `json:"input_ThirdPartyConversationID"`
PurchasedItemsDesc string `json:"input_PurchasedItemsDesc"`
}
C2BPaymentResponse struct {
ResponseCode string `json:"output_ResponseCode"`
ResponseDesc string `json:"output_ResponseDesc"`
TransactionID string `json:"output_TransactionID"`
ConversationID string `json:"output_ConversationID"`
ThirdPartyConversationID string `json:"output_ThirdPartyConversationID"`
}
B2BPaymentRequest struct {
Amount string `json:"input_Amount"`
ReceiverPartyCode string `json:"input_ReceiverPartyCode"`
Country string `json:"input_Country"`
Currency string `json:"input_Currency"`
PrimaryPartyCode string `json:"input_PrimaryPartyCode"`
TransactionReference string `json:"input_TransactionReference"`
ThirdPartyConversationID string `json:"input_ThirdPartyConversationID"`
PurchasedItemsDesc string `json:"input_PurchasedItemsDesc"`
}
B2BPaymentResponse struct {
ResponseCode string `json:"output_ResponseCode"`
ResponseDesc string `json:"output_ResponseDesc"`
TransactionID string `json:"output_TransactionID"`
ConversationID string `json:"output_ConversationID"`
ThirdPartyConversationID string `json:"output_ThirdPartyConversationID"`
}
B2CPaymentRequest struct {
Amount string `json:"input_Amount"`
CustomerMSISDN string `json:"input_CustomerMSISDN"`
Country string `json:"input_Country"`
Currency string `json:"input_Currency"`
ServiceProviderCode string `json:"input_ServiceProviderCode"`
TransactionReference string `json:"input_TransactionReference"`
ThirdPartyConversationID string `json:"input_ThirdPartyConversationID"`
PaymentItemsDesc string `json:"input_PaymentItemsDesc"`
}
B2CPaymentResponse struct {
ResponseCode string `json:"output_ResponseCode"`
ResponseDesc string `json:"output_ResponseDesc"`
TransactionID string `json:"output_TransactionID"`
ConversationID string `json:"output_ConversationID"`
ThirdPartyConversationID string `json:"output_ThirdPartyConversationID"`
}
ReversalRequest struct {
ReversalAmount string `json:"input_ReversalAmount,omitempty"`
Country string `json:"input_Country"`
TransactionID string `json:"input_TransactionID"`
ServiceProviderCode string `json:"input_ServiceProviderCode"`
ThirdPartyConversationID string `json:"input_ThirdPartyConversationID"`
}
ReversalResponse struct {
ResponseCode string `json:"output_ResponseCode"`
ResponseDesc string `json:"output_ResponseDesc"`
TransactionID string `json:"output_TransactionID"`
ConversationID string `json:"output_ConversationID"`
ThirdPartyConversationID string `json:"output_ThirdPartyConversationID"`
}
QueryTxStatusRequest struct {
QueryReference string `json:"input_QueryReference"`
Country string `json:"input_Country"`
ServiceProviderCode string `json:"input_ServiceProviderCode"`
ThirdPartyConversationID string `json:"input_ThirdPartyConversationID"`
}
QueryTxStatusResponse struct {
ResponseCode string `json:"output_ResponseCode"`
ResponseDesc string `json:"output_ResponseDesc"`
ResponseTransactionStatus string `json:"output_ResponseTransactionStatus"`
ConversationID string `json:"output_ConversationID"`
ThirdPartyConversationID string `json:"output_ThirdPartyConversationID"`
OriginalTransactionID string `json:"output_OriginalTransactionID"`
}
DirectDBCreateReq struct {
CustomerMSISDN string `json:"input_CustomerMSISDN"`
Country string `json:"input_Country"`
ServiceProviderCode string `json:"input_ServiceProviderCode"`
ThirdPartyReference string `json:"input_ThirdPartyReference"`
ThirdPartyConversationID string `json:"input_ThirdPartyConversationID"`
AgreedTC string `json:"input_AgreedTC"`
FirstPaymentDate string `json:"input_FirstPaymentDate,omitempty"`
Frequency string `json:"input_Frequency,omitempty"`
StartRangeOfDays string `json:"input_StartRangeOfDays,omitempty"`
EndRangeOfDays string `json:"input_EndRangeOfDays,omitempty"`
ExpiryDate string `json:"input_ExpiryDate,omitempty"`
}
DirectDBCreateRes struct {
ResponseCode string `json:"output_ResponseCode"`
ResponseDesc string `json:"output_ResponseDesc"`
TransactionReference string `json:"output_TransactionReference"`
MsisdnToken string `json:"output_MsisdnToken,omitempty"`
ConversationID string `json:"output_ConversationID"`
ThirdPartyConversationID string `json:"output_ThirdPartyConversationID"`
}
DebitDBPaymentReq struct {
MsisdnToken string `json:"input_MsisdnToken,omitempty"`
CustomerMSISDN string `json:"input_CustomerMSISDN,omitempty"`
Country string `json:"input_Country"`
ServiceProviderCode string `json:"input_ServiceProviderCode"`
ThirdPartyReference string `json:"input_ThirdPartyReference"`
ThirdPartyConversationID string `json:"input_ThirdPartyConversationID"`
Amount string `json:"input_Amount"`
Currency string `json:"input_Currency"`
MandateID string `json:"input_MandateID,omitempty"`
}
DebitDBPaymentRes struct {
ResponseCode string `json:"output_ResponseCode"`
ResponseDesc string `json:"output_ResponseDesc"`
TransactionID string `json:"output_TransactionID"`
MsisdnToken string `json:"output_MsisdnToken,omitempty"`
ConversationID string `json:"output_ConversationID"`
ThirdPartyConversationID string `json:"output_ThirdPartyConversationID,omitempty"`
}
QueryBenRequest struct {
CustomerMSISDN string `json:"input_CustomerMSISDN"`
Country string `json:"input_Country"`
ServiceProviderCode string `json:"input_ServiceProviderCode"`
ThirdPartyConversationID string `json:"input_ThirdPartyConversationID"`
KycQueryType string `json:"input_KycQueryType"`
}
QueryBenResponse struct {
ResponseCode string `json:"output_ResponseCode"`
ResponseDesc string `json:"output_ResponseDesc"`
CustomerFirstName string `json:"output_CustomerFirstName"`
CustomerLastName string `json:"output_CustomerLastName"`
ConversationID string `json:"output_ConversationID"`
ThirdPartyConversationID string `json:"output_ThirdPartyConversationID"`
}
QueryDirectDBReq struct {
QueryBalanceAmount bool `json:"input_QueryBalanceAmount"`
BalanceAmount string `json:"input_BalanceAmount,omitempty"`
Country string `json:"input_Country"`
CustomerMSISDN string `json:"input_CustomerMSISDN,omitempty"`
MsisdnToken string `json:"input_MsisdnToken,omitempty"`
ServiceProviderCode string `json:"input_ServiceProviderCode"`
ThirdPartyConversationID string `json:"input_ThirdPartyConversationID"`
ThirdPartyReference string `json:"input_ThirdPartyReference"`
MandateID string `json:"input_MandateID,omitempty"`
Currency string `json:"input_Currency"`
}
QueryDirectDBRes struct {
ResponseCode string `json:"output_ResponseCode"`
ResponseDesc string `json:"output_ResponseDesc"`
TransactionReference string `json:"output_TransactionReference"`
ConversationID string `json:"output_ConversationID"`
ThirdPartyConversationID string `json:"output_ThirdPartyConversationID"`
SufficientBalance bool `json:"output_SufficientBalance"`
MsisdnToken string `json:"output_MsisdnToken,omitempty"`
MandateID string `json:"output_MandateID"`
MandateStatus string `json:"output_MandateStatus"`
AccountStatus string `json:"output_AccountStatus"`
FirstPaymentDate string `json:"output_FirstPaymentDate,omitempty"`
Frequency string `json:"output_Frequency,omitempty"`
PaymentDayFrom string `json:"output_PaymentDayFrom,omitempty"`
PaymentDayTo string `json:"output_PaymentDayTo,omitempty"`
ExpiryDate string `json:"output_ExpiryDate,omitempty"`
}
CancelDirectDBReq struct {
MsisdnToken string `json:"input_MsisdnToken"`
CustomerMSISDN string `json:"input_CustomerMSISDN"`
Country string `json:"input_Country"`
ServiceProviderCode string `json:"input_ServiceProviderCode"`
ThirdPartyReference string `json:"input_ThirdPartyReference"`
ThirdPartyConversationID string `json:"input_ThirdPartyConversationID"`
MandateID string `json:"input_MandateID"`
}
CancelDirectDBRes struct {
ResponseCode string `json:"output_ResponseCode"`
ResponseDesc string `json:"output_ResponseDesc"`
TransactionReference string `json:"output_TransactionReference"`
MsisdnToken string `json:"output_MsisdnToken"`
ConversationID string `json:"output_ConversationID"`
ThirdPartyConversationID string `json:"output_ThirdPartyConversationID"`
}
)