-
Notifications
You must be signed in to change notification settings - Fork 2
/
mpesa_models.go
284 lines (250 loc) · 7.03 KB
/
mpesa_models.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
package yuri
type AccessTokenResponse struct {
AccessToken string `json:"access_token"`
ExpiresIn string `json:"expires_in"`
}
type StkPushResult struct {
///
CheckoutRequestID string
CustomerMessage string
MerchantRequestID string
ResponseCode string
ResponseDescription string
}
type StkPushResponseBody struct {
Body Body `json:"Body"`
}
type Item struct {
Name string `json:"Name"`
Value interface{} `json:"Value,omitempty"`
}
type CallbackMetadata struct {
Item []Item `json:"Item"`
}
type StkCallback struct {
MerchantRequestID string `json:"MerchantRequestID"`
CheckoutRequestID string `json:"CheckoutRequestID"`
ResultCode int `json:"ResultCode"`
ResultDesc string `json:"ResultDesc"`
CallbackMetadata CallbackMetadata `json:"CallbackMetadata"`
}
type Body struct {
StkCallback StkCallback `json:"stkCallback"`
}
///when querying for success/failure
type StkPushQueryRequestBody struct {
BusinessShortCode string
Password string
Timestamp string
CheckoutRequestID string
}
type StkPushQueryResponseBody struct {
MerchantRequestID string
CheckoutRequestID string
ResponseCode string
ResultDesc string
ResponseDescription string
ResultCode string
}
type StKPushRequestBody struct {
BusinessShortCode string
Password string
Timestamp string
///use only [ CustomerPayBillOnline ]
TransactionType string
Amount string
//sender phone number
PartyA string
///receiver shortcode
PartyB string
////Sending funds
PhoneNumber string
///
CallBackURL string
///use this with paybill
AccountReference string
//
TransactionDesc string
}
// MpesaResponse is returned by every mpesa api
// Here
// i.e that is when we call Mpesa.sendAndProcessMpesaRequest
type MpesaResult struct {
ConversationID string `json:"ConversationID"`
OriginatorCoversationID string `json:"OriginatorCoversationID"`
/// OriginatorConversationID string `json:"OriginatorConversationID"`
ResponseCode string `json:"ResponseCode"`
ResponseDescription string `json:"ResponseDescription"`
///ResponseDescription string `json:"ResponseDescription"`
}
type B2CRequestBody struct {
InitiatorName string
SecurityCredential string
CommandID string
Amount int
PartyA string
PartyB string
Remarks string
QueueTimeOutURL string
ResultURL string
Occassion string
}
type B2BRequestBody struct {
Initiator string
SecurityCredential string
CommandID string
Amount int
PartyA string
SenderIdentifierType string
RecieverIdentifierType string
AccountReference string
PartyB string
Remarks string
QueueTimeOutURL string
ResultURL string
}
type AccountBalanceRequestBody struct {
Initiator string
//see https://developer.safaricom.co.ke/docs#security-credentials
SecurityCredential string
// You don't have to pass
//this we have already set it to AccountBalance
CommandID string
// this is your shortcode i.e Paybill or till number
PartyA string
// use PayBillIdentifier for paybill
// use TillNumberIdentifier for TillNumber
IdentifierType string
Remarks string
// url to receive the results
ResultURL string
QueueTimeOutURL string
}
////Transaction Status
type TransactionStatusRequestBody struct {
Initiator string
SecurityCredential string
ShortCode string
CommandID string
TransactionID string
OriginatorConversationID string
PartyA string
IdentifierType string
Remarks string
ResultURL string
QueueTimeOutURL string
Occasion string
}
/////Register C2B url
type RegisterC2BURLRequestBody struct {
ValidationURL string
ConfirmationURL string
ResponseType string
ShortCode string
}
type C2BSimulationRequestBody struct {
CommandID string
Amount string
///phone number
Msisdn string
///optional
BillRefNumber string
ShortCode string
}
type C2BValidationAndConfirmationResponse struct {
BillRefNumber string
BusinessShortCode string
FirstName string
InvoiceNumber string
LastName string
MSISDN string
MiddleName string
OrgAccountBalance string
ThirdPartyTransID string
TransAmount float64 `json:",string"`
TransID string
TransTime string
TransactionType string
}
/// this is what
// C2BValidatedResponse you send back to mpesa after receiving the validation
//from c2B api
//
// request to Time confirm if it is okay
//
type C2BValidatedResponse struct {
// use 0 for success
// and any other value for error
// this is required
ResultCode int
// this is optional
// value can be “Service processing successful”
ResultDesc string
///The unique identifier of the payment transaction that is generated by the third party
ThirdPartyTransID string
}
// This is response sent when we are checkig the status of a transaction
type MpesaTransactionStatus struct {
//////
Result MpesaTransactionResult
}
type MpesaTransactionResult struct {
Result
ReferenceData BalanceReferenceData
}
// MpesaBalance is what is returned to the resulturl
// you set the result url in your AccountBalanceRequestBody.ResultURL
// you query for your balance using the balance
// api ....
type MpesaBalance struct {
Result BalanceResult `json:"Result"`
}
type BalanceReferenceData struct {
ReferenceItem ReferenceItem `json:"ReferenceItem"`
}
type BalanceResult struct {
Result
ReferenceData BalanceReferenceData `json:"ReferenceData"`
}
//end of balance result
// MpesaB2BResponse is what is returned to the B2BRequestBody.ResultURL
// you set the result url in your AccountBalanceRequestBody.ResultURL
// This is when using the B2B api
type MpesaB2BResponse struct {
Result MpesaB2BResult `json:"Result"`
}
type MpesaB2BResult struct {
Result
ReferenceData B2BReferenceData `json:"ReferenceData"`
}
type B2BReferenceData struct {
ReferenceItem []ReferenceItem `json:"ReferenceItem"`
}
////End of B2B result
type MpesaResponse struct {
Result Result `json:"Result"`
}
type Result struct {
ConversationID string `json:"ConversationID"`
ResultType int `json:"ResultType"`
ResultCode string `json:"ResultCode"`
ResultDesc string `json:"ResultDesc"`
OriginatorConversationID string `json:"OriginatorConversationID"`
TransactionID string `json:"TransactionID"`
ResultParameters ResultParameters `json:"ResultParameters"`
//ReferenceData ReferenceData `json:"ReferenceData"`
}
type ReferenceItem struct {
Key string `json:"Key"`
Value interface{} `json:"Value,omitempty"`
}
type ReferenceData struct {
ReferenceItem []ReferenceItem `json:"ReferenceItem"`
}
type ResultParameter struct {
Key string `json:"Key"`
Value interface{} `json:"Value,omitempty"`
}
type ResultParameters struct {
ResultParameter []ResultParameter `json:"ResultParameter"`
}