forked from safaricom/mpesa-api-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.go
More file actions
364 lines (339 loc) · 11.6 KB
/
Copy pathmodel.go
File metadata and controls
364 lines (339 loc) · 11.6 KB
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
// Every comment was copied from original documentation from https://developer.safaricom.co.ke/apis-explorer
package mpesa
import (
"encoding/json"
"fmt"
)
//go:generate easyjson
//easyjson:json
type authResponse struct {
// Access token to access other APIs
AccessToken string `json:"access_token"`
// Token expiry time in seconds.
ExpiresIn string `json:"expires_in"`
}
//easyjson:json
type APIError struct {
RequestId *string `json:"requestId"`
ErrorCode *string `json:"errorCode"`
ErrorMessage *string `json:"errorMessage"`
}
func (r APIError) Error() string {
return fmt.Sprintf("%s - %s", sp(r.ErrorCode), sp(r.ErrorMessage))
}
func sp(p *string) string {
if p == nil {
return ""
}
return *p
}
//easyjson:json
type GenericResponse struct {
// A unique numeric code generated by the M-Pesa system of the request.
OriginatorConversationID string `json:",omitempty"`
// A unique numeric code generated by the M-Pesa system of the response to a request.
ConversationID string `json:",omitempty"`
ResponseDescription string `json:",omitempty"`
// A response message from the M-Pesa system accompanying the response to a request.
ResponseCode string `json:",omitempty"`
}
//easyjson:json
type C2B struct {
// Short Code receiving the amount being transacted
ShortCode string
// Unique command for each transaction type. For C2B dafult
// CustomerPayBillOnline
// CustomerBuyGoodsOnline
CommandID string
// The amount being transacted
Amount string
// Phone number (msisdn) initiating the transaction
Msisdn string
// Bill Reference Number (Optional)
BillRefNumber string `json:",omitempty"`
}
//easyjson:json
type C2BResponse GenericResponse
//easyjson:json
type B2C struct {
// The name of the initiator initiating the request
// This is the credential/username used to authenticate the transaction request
InitiatorName string
// Encrypted Credential of user getting transaction amount
// Encrypted password for the initiator to authenticate the transaction request
SecurityCredential string
// Unique command for each transaction type
// SalaryPayment
// BusinessPayment
// PromotionPayment
CommandID string
// The amount been transacted
Amount string
// Organization /MSISDN sending the transaction
// Shortcode (6 digits)
// MSISDN (12 digits)
PartyA string
// MSISDN receiving the transaction (12 digits)
PartyB string
// Comments that are sent along with the transaction.
// Up to 100
Remarks string
// The path that stores information of time out transaction
// https://ip or domain:port/path
QueueTimeOutURL string
// The path that stores information of transactions
// https://ip or domain:port/path
ResultURL string
// Optional Parameter
// Up to 100
Occasion string `json:",omitempty"`
}
//easyjson:json
type B2CResponse GenericResponse
//easyjson:json
type B2CCallback struct {
Result struct {
ResultType int
ResultCode int
ResultDesc string
OriginatorConversationID string
ConversationID string
TransactionID string
ResultParameters struct {
ResultParameter []struct {
Key string
Value json.RawMessage
}
}
ReferenceData json.RawMessage
}
}
//easyjson:json
type TransactionStatus struct {
// Takes only 'TransactionStatusQuery' command id
CommandID string
// Organization/MSISDN receiving the transaction
// -Shortcode (6 digits)
// -MSISDN (12 Digits)
PartyA string
// Type of organization receiving the transaction
IdentifierType string
// Comments that are sent along with the transaction
// Up to 100
Remarks string
// The name of Initiator to initiating the request
// This is the credential/username used to authenticate the transaction request
Initiator string
// Encrypted Credential of user getting transaction amount
// Encrypted password for the initiator to authenticate the transaction request
SecurityCredential string
// The path that stores information of time out transaction
// https://ip or domain:port/path
QueueTimeOutURL string
// The path that stores information of transaction
// https://ip or domain:port/path
ResultURL string
// Unique identifier to identify a transaction on M-Pesa
TransactionID string
Occasion string `json:",omitempty"`
}
//easyjson:json
type TransactionStatusResponse GenericResponse
// https://developer.safaricom.co.ke/lipa-na-m-pesa-online/apis/post/stkpush/v1/processrequest
//easyjson:json
type Payment struct {
// This is organizations shortcode (Paybill or Buygoods - A 5 to 6 digit account number)
// used to identify an organization and receive the transaction.
BusinessShortCode string
// This is the password used for encrypting the request sent: A base64 encoded string.
// (The base64 string is a combination of Shortcode+Passkey+Timestamp)
Password string
// This is the Timestamp of the transaction,
// normally in the format of YEAR+MONTH+DATE+HOUR+MINUTE+SECOND (YYYYMMDDHHMMSS)
// Each part should be at least two digits apart from the year which takes four digits.
Timestamp string
// This is the transaction type that is used to identify the transaction when sending the request to M-Pesa.
// The transaction type for M-Pesa Express is "CustomerPayBillOnline"
TransactionType string
// This is the Amount transacted normally a numeric value. Money that customer pays to the Shorcode.
// Only whole numbers are supported.
Amount string
// The phone number sending money.
// The parameter expected is a Valid Safaricom Mobile Number that is M-Pesa registered in the format 2547XXXXXXXX
PartyA string
// The organization receiving the funds.
// The parameter expected is a 5 to 6 digit as defined on the Shortcode description above.
// This can be the same as BusinessShortCode value above.
PartyB string
// The Mobile Number to receive the STK Pin Prompt. This number can be the same as PartyA value above.
PhoneNumber string
// A CallBack URL is a valid secure URL that is used to receive notifications from M-Pesa API.
// It is the endpoint to which the results will be sent by M-Pesa API.
CallBackURL string
// Account Reference:
// This is an Alpha-Numeric parameter that is defined by your system as an Identifier of the transaction
// for CustomerPayBillOnline transaction type.
// Along with the business name, this value is also displayed to the customer in the STK Pin Prompt message.
// Maximum of 12 characters.
AccountReference string
// This is any additional information/comment that can be sent along with the request from your system.
// Maximum of 13 Characters.
TransactionDesc string
}
//easyjson:json
type PaymentResponse struct {
// This is a global unique Identifier for any submitted payment request.
MerchantRequestID string
// This is a global unique identifier of the processed checkout transaction request.
CheckoutRequestID string
// Response description is an acknowledgement message from the API that gives the status of the request submission,
// usually maps to a specific ResponseCode value.
// It can be a Success submission message or an error description.
ResponseDescription string
// This is a Numeric status code that indicates the status of the transaction submission.
// 0 means successful submission and any other code means an error occurred.
ResponseCode string
// This is a message that your system can display to the Customer as an acknowledgement of the payment request submission.
CustomerMessage string
}
//easyjson:json
type PaymentCallback struct {
Body struct {
STKCallback struct {
// This is a global unique Identifier for any submitted payment request.
// This is the same value returned in the acknowledgement message of the initial request.
MerchantRequestID string
// This is a global unique identifier of the processed checkout transaction request.
// This is the same value returned in the acknowledgement message of the initial request.
CheckoutRequestID string
// This is a numeric status code that indicates the status of the transaction processing.
// 0 means successful processing and any other code means an error occurred or the transaction failed.
ResultCode int
// Result description is a message from the API that gives the status of the request processing,
// usually maps to a specific ResultCode value.
// It can be a Success processing message or an error description message.
ResultDesc string
CallbackMetadata struct {
Item []struct {
Name string
Value json.RawMessage `json:",omitempty"`
}
} `json:",omitempty"`
} `json:"stkCallback"`
}
}
//easyjson:json
type C2BRegisterURL struct {
// The short code of the organization.
ShortCode string
// Default response type for timeout. In case a transaction times out,
// Mpesa will by default Complete or Cancel the transaction.
ResponseType string
// Confirmation URL for the client.
ConfirmationURL string
// Validation URL for the client.
ValidationURL string
}
//easyjson:json
type C2BRegisterURLResponse GenericResponse
//easyjson:json
type Reversal struct {
// Takes only 'TransactionReversal' Command id
CommandID string
// Organization receiving the transaction (shortcode)
ReceiverParty string
// Type of organization receiving the transaction
// Organization Identifier on M-Pesa
ReceiverIdentifierType string
// Comments that are sent along with the transaction.
// Up to 100 characters.
Remarks string
// The name of Initiator to initiating the request
// This is the credential/username used to authenticate the transaction request
Initiator string
// Encrypted Credential of user getting transaction amount
// Encrypted password for the initiator to authenticate the transaction request
SecurityCredential string
// The path that stores information of time out transaction
// https://ip or domain:port/path
QueueTimeOutURL string
// Organization Receiving the funds // WTF??
TransactionID string
// Optional Parameter
// Up to 100 characters
Occasion string
}
//easyjson:json
type ReversalResponse struct {
Result struct {
ResultType int
ResultCode int
ResultDesc string
OriginatorConversationID string
ConversationID string
TransactionID string
ReferenceData json.RawMessage
}
}
//easyjson:json
type C2BValidationResponse struct {
TransactionType string
TransID string
// example: "20170727104247"
TransTime string
// example: "10.00"
TransAmount string
BusinessShortCode string
BillRefNumber string
InvoiceNumber string
OrgAccountBalance string
ThirdPartyTransID string
MSISDN string
FirstName string
MiddleName string
LastName string
}
//easyjson:json
type C2BConformationResponse struct {
TransactionType string
TransID string
// example: "20170727104247"
TransTime string
// example: "10.00"
TransAmount string
BusinessShortCode string
BillRefNumber string
InvoiceNumber string
OrgAccountBalance string
ThirdPartyTransID string
MSISDN string
FirstName string
MiddleName string
LastName string
}
/*
type BalanceInquiry struct {
Initiator string
SecurityCredential string
CommandID string
PartyA string
IdentifierType string
Remarks string
QueueTimeOutURL string
ResultURL string
}
type B2B struct {
Initiator string
SecurityCredential string
CommandID string
SenderIdentifierType string
RecieverIdentifierType string
Amount string
PartyA string
PartyB string
Remarks string
AccountReference string
QueueTimeOutURL string
ResultURL string
}
*/