-
Notifications
You must be signed in to change notification settings - Fork 5
/
types.go
303 lines (270 loc) · 9.92 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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
package azampay
import (
"net/http"
"sync"
"time"
)
const (
APIBase = "https://sandbox.azampay.co.tz"
AuthenicateUrl = "https://authenticator-sandbox.azampay.co.tz/AppRegistration/GenerateToken"
MnoCheckoutEndPoint = "/azampay/mno/checkout"
BankCheckoutEndPoint = "/azampay/bank/checkout"
PayPartnersEndPoint = "/api/v1/Partner/GetPaymentPartners"
PostCheckOutEndPoint = "/api/v1/Partner/PostCheckout"
NameLookupEndPoint = "/azampay/namelookup"
TransactionalStatusEndpoint = "/azampay/gettransactionstatus"
DisburseEndpoint = "/azampay/createtransfer"
RequestNewTokenBeforeExpiresIn = time.Duration(60) * time.Second
)
type (
TokenData struct {
AccessToken *string `json:"accessToken"`
Expire time.Time `json:"expire"`
}
TokenRequest struct {
AppName string `json:"appName"`
ClientID string `json:"clientId"`
ClientSecret string `json:"clientSecret"`
}
TokenResponse struct {
Data TokenData `json:"data"`
Message string `json:"message"`
Success bool `json:"success"`
StatusCode int `json:"statusCode"`
}
ErrTokenResponse struct {
Data interface{} `json:"data"`
Message string `json:"message"`
Success bool `json:"success"`
StatusCode int `json:"statusCode"`
}
ErrorsMno struct {
Amount []interface{} `json:"amount"`
ExternalID []interface{} `json:"externalId"`
AccountNumber []interface{} `json:"accountNumber"`
Provider []interface{} `json:"provider"`
}
ErrCheckOutResponse struct {
ErrorsMno `json:"errors"`
Type string `json:"type"`
TraceID string `json:"traceId"`
Title string `json:"title"`
Status int `json:"status"`
}
Client struct {
// sync.Mutex
mu sync.Mutex
Client *http.Client
AppName string
ClientID string
ClientSecret string
APIBase string
Token *TokenResponse
TokenKey string
}
MnoPayload struct {
// This is the account number/MSISDN that consumer will provide. The amount will be deducted from this account (required)
AccountNumber string `json:"accountNumber"`
// This is amount that will be charged from the given account (required)
Amount string `json:"amount"`
// This is the transaciton currency. Current support values are only TZS (required)
Currency string `json:"currency"`
// This id belongs to the calling application. Maximum Allowed length for this field is 128 ascii characters (required)
ExternalID string `json:"externalId"`
// Only providers available are Airtel, Tigo, Halopesa and Azampesa (required)
Provider string `json:"provider"`
// This is additional data you can provide (Optional)
AdditionalProperties AdditionalProperties `json:"additionalProperties"`
}
// Data received from the server after a valid transaction
MnoResponse struct {
// Will be true is successful
Success bool `json:"success"`
// Each successful transaction will be given a valid transaction id. Can also be a string or null
TransactionID string `json:"transactionId"`
// This is the status message of checkout request. Can be a string or null
Message string `json:"message"`
}
BankCheckoutPayload struct {
// This is amount that will be charged from the given account (required)
Amount string `json:"amount"`
// Code of currency (required)
CurrencyCode string `json:"currencyCode"`
// This is the account number/MSISDN that consumer will provide. The amount will be deducted from this account (required)
MerchantAccountNumber string `json:"merchantAccountNumber"`
// Mobile number (required)
MerchantMobileNumber string `json:"merchantMobileNumber"`
// The name of the customer (optional)
MerchantName string `json:"merchantName"`
// One time password (required)
OTP string `json:"otp"`
// Bank provider. Currently on CRDB and NMB are supported (required)
Provider string `json:"provider"`
// This id belongs to the calling application. Maximum Allowed length for this field is 128 ascii characters (Optional)
ReferenceID string `json:"referenceId"`
// This is additional data you can provide (Optional)
AdditionalProperties AdditionalProperties `json:"additionalProperties"`
}
AdditionalProperties struct {
Property1 any `json:"property1"`
Property2 any `json:"property2"`
}
ReferenceID struct {
// Reference ID of the transaction
ReferenceID string `json:"ReferenceID"`
}
Properties struct {
// List of properties
Properties ReferenceID `json:"properties"`
}
// Data received from the server after a successful transaction
BankCheckoutResponse struct {
// will return true if successful
Success bool `json:"success"`
// message received from the server. Will be empty for sandbox
Message string `json:"msg"`
// data received from the server
Data Properties `json:"data"`
}
// Payload that will be received from the payment partner payload.
PayPartnersResponse struct {
// ID of ther partner
ID string `json:"id"`
// Logo of the partner
LogoURL string `json:"logoUrl"`
// Name of the partner
PartnerName string `json:"partnerName"`
// Number of the provider
Provider int64 `json:"provider"`
// Name of the vendor
VendorName string `json:"vendorName"`
// ID of the payment vendor
PaymentVendorID string `json:"paymentVendorId"`
// ID of the payment partner
PaymentPartnerID string `json:"paymentPartnerId"`
// The callback url
PaymentAcknowledgementRoute string `json:"paymentAcknowledgementRoute"`
// Currency used
Currency string `json:"currency"`
// Status
Status string `json:"status"`
// Type of the vendor
VendorType string `json:"vendorType"`
}
// Items in the shopping Cart
Item struct {
Name string `json:"name"`
}
// Shopping cart with multiple items
Cart struct {
// Items to be shopped
Items []Item `json:"items"`
}
// Payload to be sent to the post checkout endpoint
PostCheckoutPayload struct {
// This is the amount that will be charged from the given account (required)
Amount string `json:"amount"`
// This is the application name (required)
AppName string `json:"appName"`
// Shopping cat with multiple items (required)
Cart Cart `json:"cart"`
// Unique identifier for the client (required)
ClientID string `json:"clientId"`
// Currency code that will convert amount into specific current (required)
Currency string `json:"currency"`
// 30 character long unique string (required)
ExternalID string `json:"externalId"`
// Language code to translate the application (required)
Language string `json:"language"`
// URL that be redirected to upon transaction failure (required)
RedirectFailURL string `json:"redirectFailURL"`
// URL to be directed to upon successful transaction (required)
RedirectSuccessURL string `json:"redirectSuccessURL"`
// URL which the request is being originated (required)
RequestOrigin string `json:"requestOrigin"`
// UUID to validate vendor (required)
VendorID string `json:"vendorId"`
// Name of the vendor (required)
VendorName string `json:"vendorName"`
}
NameLookupPayload struct {
// Bank account number or mobile money number
BankName string `json:"bankName"`
// Bank name or mobile money name associated with the account
AccountNumber string `json:"accountNumber"`
}
NameLookupResponse struct {
Name string `json:"name"`
Message string `json:"message"`
Success bool `json:"success"`
AccountNumber string `json:"accountNumber"`
BankName string `json:"bankName"`
}
TransactionStatusQueries struct {
// The name of the mobile network operator (MNO) used
// to make the disbursement request
BankName string `json:"bankName"`
// The transaction ID you received when making the
// disbursement request
PgReferenceID string `json:"pgReferenceId"`
}
TransactionStatusResponse struct {
Data string `json:"data"`
Message string `json:"message"`
Success bool `json:"success"`
StatusCode int `json:"statusCode"`
}
// Allows for transfer of money from other countries
// to Tanzania.
DisbursePayload struct {
// Contains information about the source account
Source Source `json:"source"`
// Contains information about the destination account
Destination Destination `json:"destination"`
// Contains information about the transfer
TransferDetails TransferDetails `json:"transferDetails"`
// An external reference ID to track the transaction
ExternalReferenceID string `json:"externalReferenceId"`
// Any Remarks to be included in the transaction
Remarks string `json:"remarks"`
}
Source struct {
// Country code of the source country
CountryCode string `json:"countryCode"`
// Full name of the account holder
FullName string `json:"fullName"`
// The name of the bank where the source account is held.
// Current options are 'tigo', 'airtel', 'azampesa'
BankName string `json:"bankName"`
// The account number of the source account
AccountNumber string `json:"accountNumber"`
// The currency in which the transfer is made
Currency string `json:"currency"`
}
Destination struct {
// Country code of the destination account
CountryCode string `json:"countryCode"`
// The full name of the account holder
FullName string `json:"fullName"`
// The bank where the destination account is held
// Current options are 'tigo', 'airtel', 'azampesa'
BankName string `json:"bankName"`
// The account number of the destination account
AccountNumber string `json:"accountNumber"`
// The currency in which the transfer is made
Currency string `json:"currency"`
}
TransferDetails struct {
// The type of the transfer eg: SWIFT, SEPA etc
Type string `json:"type"`
// The amount to be transfered
Amount int `json:"amount"`
// The date when transfer is made
Date time.Time `json:"date"`
}
DisburseResponse struct {
Success bool `json:"success"`
TransactionID string `json:"transactionId"`
Message string `json:"message"`
}
)