-
Notifications
You must be signed in to change notification settings - Fork 0
/
disbursements.go
266 lines (220 loc) · 8.36 KB
/
disbursements.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
package gomonnify
import (
"fmt"
"github.com/jcobhams/gomonnify/params"
"net/http"
"strings"
)
// SingleTransfer sends money to a single recipient.
// Docs: https://docs.teamapt.com/display/MON/Initiate+Transfer
func (d *disbursements) SingleTransfer(params params.SingleTransferParam) (*SingleTransferResponse, error) {
url := fmt.Sprintf("%v/v1/disbursements/single", d.APIBaseUrl)
rawResponse, statusCode, err := d.postRequest(url, requestAuthTypeBasic, params)
if err != nil {
return nil, err
}
result := SingleTransferResponse{}
err = d.unmarshallJson(strings.NewReader(rawResponse), &result)
if err != nil {
return nil, err
}
if statusCode != http.StatusOK {
return nil, failedRequestMessage(statusCode, result.ResponseCode, result.ResponseMessage)
}
return &result, nil
}
// BulkTransfer sends money to a list of recipients.
// Docs: https://docs.teamapt.com/display/MON/Initiate+Transfer
func (d *disbursements) BulkTransfer(params params.BulkTransferParam) (*BulkTransferResponse, error) {
url := fmt.Sprintf("%v/v1/disbursements/batch", d.APIBaseUrl)
rawResponse, statusCode, err := d.postRequest(url, requestAuthTypeBasic, params)
if err != nil {
return nil, err
}
result := BulkTransferResponse{}
err = d.unmarshallJson(strings.NewReader(rawResponse), &result)
if err != nil {
return nil, err
}
if statusCode != http.StatusOK {
return nil, failedRequestMessage(statusCode, result.ResponseCode, result.ResponseMessage)
}
return &result, nil
}
// AuthorizeSingleTransfer validates the OTP for the transaction
// Docs: https://docs.teamapt.com/pages/viewpage.action?pageId=4587995
func (d *disbursements) AuthorizeSingleTransfer(reference, authorizationCode string) (*SingleTransferResponse, error) {
url := fmt.Sprintf("%v/v1/disbursements/single/validate-otp", d.APIBaseUrl)
param := struct {
Reference string `json:"reference"`
AuthorizationCode string `json:"authorizationCode"`
}{
Reference: reference,
AuthorizationCode: authorizationCode,
}
rawResponse, statusCode, err := d.postRequest(url, requestAuthTypeBasic, param)
if err != nil {
return nil, err
}
result := SingleTransferResponse{}
err = d.unmarshallJson(strings.NewReader(rawResponse), &result)
if err != nil {
return nil, err
}
if statusCode != http.StatusOK {
return nil, failedRequestMessage(statusCode, result.ResponseCode, result.ResponseMessage)
}
return &result, nil
}
// AuthorizeBulkTransfer validates the OTP for the transaction
// Docs: https://docs.teamapt.com/pages/viewpage.action?pageId=4587995
func (d *disbursements) AuthorizeBulkTransfer(reference, authorizationCode string) (*BulkTransferResponse, error) {
url := fmt.Sprintf("%v/v1/disbursements/batch/validate-otp", d.APIBaseUrl)
param := struct {
Reference string `json:"reference"`
AuthorizationCode string `json:"authorizationCode"`
}{
Reference: reference,
AuthorizationCode: authorizationCode,
}
rawResponse, statusCode, err := d.postRequest(url, requestAuthTypeBasic, param)
if err != nil {
return nil, err
}
result := BulkTransferResponse{}
err = d.unmarshallJson(strings.NewReader(rawResponse), &result)
if err != nil {
return nil, err
}
if statusCode != http.StatusOK {
return nil, failedRequestMessage(statusCode, result.ResponseCode, result.ResponseMessage)
}
return &result, nil
}
// SingleTransferDetails gets a single transfer detail
// Docs: https://docs.teamapt.com/display/MON/Get+Transfer+Details
func (d *disbursements) SingleTransferDetails(reference string) (*SingleTransferDetailsResponse, error) {
url := fmt.Sprintf("%v/v1/disbursements/single/summary?reference=%v", d.APIBaseUrl, reference)
rawResponse, statusCode, err := d.getRequest(url, requestAuthTypeBasic)
if err != nil {
return nil, err
}
result := SingleTransferDetailsResponse{}
err = d.unmarshallJson(strings.NewReader(rawResponse), &result)
if err != nil {
return nil, err
}
if statusCode != http.StatusOK {
return nil, failedRequestMessage(statusCode, result.ResponseCode, result.ResponseMessage)
}
return &result, nil
}
// BulkTransferDetails gets a bulk transfer detail
// Docs: https://docs.teamapt.com/display/MON/Get+Transfer+Details
func (d *disbursements) BulkTransferDetails(batchReference string) (*BulkTransferDetailsResponse, error) {
url := fmt.Sprintf("%v/v1/disbursements/batch/summary?reference=%v", d.APIBaseUrl, batchReference)
rawResponse, statusCode, err := d.getRequest(url, requestAuthTypeBasic)
if err != nil {
return nil, err
}
result := BulkTransferDetailsResponse{}
err = d.unmarshallJson(strings.NewReader(rawResponse), &result)
if err != nil {
return nil, err
}
if statusCode != http.StatusOK {
return nil, failedRequestMessage(statusCode, result.ResponseCode, result.ResponseMessage)
}
return &result, nil
}
// BulkTransferTransactions returns a list of transactions in a bulk transfer batch
// Docs: https://docs.teamapt.com/display/MON/Get+Bulk+Transfer+Transactions
func (d *disbursements) BulkTransferTransactions(batchReference string, pageNo, pageSize int) (*TransferTransactionsResponse, error) {
url := fmt.Sprintf("%v/v1/disbursements/bulk/%v/transactions?pageNo=%v&pageSize=%v", d.APIBaseUrl, batchReference, pageNo, pageSize)
rawResponse, statusCode, err := d.getRequest(url, requestAuthTypeBasic)
if err != nil {
return nil, err
}
result := TransferTransactionsResponse{}
err = d.unmarshallJson(strings.NewReader(rawResponse), &result)
if err != nil {
return nil, err
}
if statusCode != http.StatusOK {
return nil, failedRequestMessage(statusCode, result.ResponseCode, result.ResponseMessage)
}
return &result, nil
}
func (d *disbursements) SingleTransferTransactions(pageNo, pageSize int) (*TransferTransactionsResponse, error) {
url := fmt.Sprintf("%v/v1/disbursements/single/transactions?pageNo=%v&pageSize=%v", d.APIBaseUrl, pageNo, pageSize)
rawResponse, statusCode, err := d.getRequest(url, requestAuthTypeBasic)
if err != nil {
return nil, err
}
result := TransferTransactionsResponse{}
err = d.unmarshallJson(strings.NewReader(rawResponse), &result)
if err != nil {
return nil, err
}
if statusCode != http.StatusOK {
return nil, failedRequestMessage(statusCode, result.ResponseCode, result.ResponseMessage)
}
return &result, nil
}
// ValidateAccountNumber This allows you check if an account number is a valid NUBAN, get the account name if valid.
// Docs: https://docs.teamapt.com/display/MON/Validate+Bank+Account
func (d *disbursements) ValidateAccountNumber(accountNumber, bankCode string) (*ValidAccountNumberResponse, error) {
url := fmt.Sprintf("%v/v1/disbursements/account/validate?accountNumber=%v&bankCode=%v", d.APIBaseUrl, accountNumber, bankCode)
rawResponse, statusCode, err := d.getRequest(url, requestAuthTypeBasic)
if err != nil {
return nil, err
}
result := ValidAccountNumberResponse{}
err = d.unmarshallJson(strings.NewReader(rawResponse), &result)
if err != nil {
return nil, err
}
if statusCode != http.StatusOK {
return nil, failedRequestMessage(statusCode, result.ResponseCode, result.ResponseMessage)
}
return &result, nil
}
// WalletBalance returns the available balance in the monnify wallet
// Docs: https://docs.teamapt.com/display/MON/Get+Wallet+Balance
func (d *disbursements) WalletBalance(walletId string) (*WalletBalanceResponse, error) {
url := fmt.Sprintf("%v/v1/disbursements/wallet-balance?walletId=%v", d.APIBaseUrl, walletId)
rawResponse, statusCode, err := d.getRequest(url, requestAuthTypeBasic)
if err != nil {
return nil, err
}
result := WalletBalanceResponse{}
err = d.unmarshallJson(strings.NewReader(rawResponse), &result)
if err != nil {
return nil, err
}
if statusCode != http.StatusOK {
return nil, failedRequestMessage(statusCode, result.ResponseCode, result.ResponseMessage)
}
return &result, nil
}
func (d *disbursements) ResendOTP(reference string) (*ResendOTPResponse, error) {
param := struct {
Reference string `json:"reference"`
}{
Reference: reference,
}
url := fmt.Sprintf("%v/v1/disbursements/single/resend-otp", d.APIBaseUrl)
rawResponse, statusCode, err := d.postRequest(url, requestAuthTypeBasic, param)
if err != nil {
return nil, err
}
result := ResendOTPResponse{}
err = d.unmarshallJson(strings.NewReader(rawResponse), &result)
if err != nil {
return nil, err
}
if statusCode != http.StatusOK {
return nil, failedRequestMessage(statusCode, result.ResponseCode, result.ResponseMessage)
}
return &result, nil
}