-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtransfer.go
233 lines (197 loc) · 8.19 KB
/
transfer.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
package providusbank
import (
"context"
"fmt"
"net/http"
)
type NIPBanksResponse struct {
ResponseCode Code `json:"responseCode"`
ResponseMessage string `json:"responseMessage"`
Banks []struct {
Code string `json:"bankCode"`
Name string `json:"bankName"`
} `json:"banks"`
}
// GetNIPBanks returns the list of institutions currently enrolled on NIP and their respective NIP bank codes.
func (c *transferClient) GetNIPBanks(ctx context.Context) (data NIPBanksResponse, err error) {
req, err := c.newRequest(ctx, http.MethodGet, "/PiPCreateDynamicAccountNumber", nil)
if err != nil {
return data, fmt.Errorf("failed to create request: %w", err)
}
req.DecodeTo(&data)
return data, c.do(ctx, req)
}
type requireAuth interface {
SetAuthCredentials(username, password string)
}
type authPayload struct {
Username string `json:"userName"`
Password string `json:"password"`
}
func (p *authPayload) SetAuthCredentials(username, password string) {
p.Username = username
p.Password = password
}
type getBvnDetailsPayload struct {
authPayload
BVN string `json:"bvn"`
}
type BVNDetailsResponse struct {
ResponseCode Code `json:"responseCode"`
ResponseMessage string `json:"responseMessage"`
FirstName string `json:"firstName"`
MiddleName string `json:"middleName"`
LastName string `json:"surname"`
DOB Time `json:"dateOfBirth"`
}
// GetBVNDetails validates the supplied single BVN and returns the full demography details associated with the BVN.
func (c *transferClient) GetBVNDetails(ctx context.Context, bvn string) (data BVNDetailsResponse, err error) {
req, err := c.newRequest(ctx, http.MethodPost, "/GetBVNDetails", &getBvnDetailsPayload{BVN: bvn})
if err != nil {
return data, fmt.Errorf("failed to create request: %w", err)
}
req.DecodeTo(&data)
return data, c.do(ctx, req)
}
type getTransactionStatusPayload struct {
authPayload
Reference string `json:"transactionReference"`
}
type TransactionStatusResponse struct {
ResponseCode Code `json:"responseCode"`
ResponseMessage string `json:"responseMessage"`
Currency string `json:"currency"`
Amount string `json:"amount"`
CreditAccount string `json:"creditAccount"`
DebitAccount string `json:"debitAccount"`
Reference string `json:"transactionReference"`
Date Time `json:"transactionDateTime"`
}
// GetTransactionStatus validates the supplied single transaction reference and returns the current status of the transaction.
// This status is of Providus-to-Providus transactions.
func (c *transferClient) GetTransactionStatus(ctx context.Context, reference string) (data TransactionStatusResponse, err error) {
req, err := c.newRequest(ctx, http.MethodPost, "/GetProvidusTransactionStatus", &getTransactionStatusPayload{Reference: reference})
if err != nil {
return data, fmt.Errorf("failed to create request: %w", err)
}
req.DecodeTo(&data)
return data, c.do(ctx, req)
}
type NIPTransactionStatusResponse struct {
ResponseCode Code `json:"responseCode"`
ResponseMessage string `json:"responseMessage"`
Currency string `json:"currency"`
Amount string `json:"amount"`
RecipientBankCode string `json:"recipientBankCode"`
RecipientAccountNumber string `json:"recipientAccountNumber"`
Reference string `json:"transactionReference"`
Date Time `json:"transactionDateTime"`
}
// GetNIPTransactionStatus validates the supplied single transaction reference and returns the current status of the transaction.
func (c *transferClient) GetNIPTransactionStatus(ctx context.Context, reference string) (data NIPTransactionStatusResponse, err error) {
req, err := c.newRequest(ctx, http.MethodPost, "/GetNIPTransactionStatus", &getTransactionStatusPayload{Reference: reference})
if err != nil {
return data, fmt.Errorf("failed to create request: %w", err)
}
req.DecodeTo(&data)
return data, c.do(ctx, req)
}
type getAccountPayload struct {
authPayload
AccountNumber string `json:"accountNumber"`
}
type AccountResponse struct {
ResponseCode Code `json:"responseCode"`
ResponseMessage string `json:"responseMessage"`
}
// GetAccount returns the details tied to your account including the balance.
// This account is the one tied to the username making the call.
func (c *transferClient) GetAccount(ctx context.Context, accountNumber string) (data AccountResponse, err error) {
req, err := c.newRequest(ctx, http.MethodPost, "/GetProvidusAccount", &getAccountPayload{AccountNumber: accountNumber})
if err != nil {
return data, fmt.Errorf("failed to create request: %w", err)
}
req.DecodeTo(&data)
return data, c.do(ctx, req)
}
type getNIPAccountPayload struct {
authPayload
AccountNumber string `json:"accountNumber"`
BankCode string `json:"beneficiaryBank"`
}
type NIPAccountResponse struct {
ResponseCode Code `json:"responseCode"`
ResponseMessage string `json:"responseMessage"`
AccountNumber string `json:"accountNumber"`
AccountName string `json:"accountName"`
BankCode string `json:"bankCode"`
BVN string `json:"bvn"`
TransactionReference string `json:"transactionReference"`
}
// GetNIPAccount validates the supplied account number and 3-digit bank code and returns the account details.
// It can also accept the 6-digit NIP bank code in place of the 3-digit.
func (c *transferClient) GetNIPAccount(ctx context.Context, bankCode, accountNumber string) (data NIPAccountResponse, err error) {
req, err := c.newRequest(ctx, http.MethodPost, "/GetNIPAccount", &getNIPAccountPayload{BankCode: bankCode, AccountNumber: accountNumber})
if err != nil {
return data, fmt.Errorf("failed to create request: %w", err)
}
req.DecodeTo(&data)
return data, c.do(ctx, req)
}
type fundTransferPayload struct {
authPayload
FundTransferPayload
}
type FundTransferPayload struct {
CreditAccount string `json:"creditAccount"`
DebitAccount string `json:"debitAccount"`
Currency string `json:"currencyCode"`
Amount float64 `json:"transactionAmount"`
Reference string `json:"transactionReference"`
Narration string `json:"narration"`
}
type FundTransferResponse struct {
ResponseCode Code `json:"responseCode"`
ResponseMessage string `json:"responseMessage"`
Currency string `json:"currency"`
Amount string `json:"amount"`
Reference string `json:"transactionReference"`
}
// FundTransfer used to transfer fund from a specified Providus account number to another ProvidusBank account.
func (c *transferClient) FundTransfer(ctx context.Context, payload FundTransferPayload) (data FundTransferResponse, err error) {
req, err := c.newRequest(ctx, http.MethodPost, "/ProvidusFundTransfer", &fundTransferPayload{FundTransferPayload: payload})
if err != nil {
return data, fmt.Errorf("failed to create request: %w", err)
}
req.DecodeTo(&data)
return data, c.do(ctx, req)
}
type nipFundTransferPayload struct {
authPayload
NIPFundTransferPayload
}
type NIPFundTransferPayload struct {
SourceAccountName string `json:"sourceAccountName"`
BeneficiaryAccountName string `json:"beneficiaryAccountName"`
BeneficiaryAccountNumber string `json:"beneficiaryAccountNumber"`
BeneficiaryBank string `json:"beneficiaryBank"`
Currency string `json:"currencyCode"`
Amount float64 `json:"transactionAmount"`
Reference string `json:"transactionReference"`
Narration string `json:"narration"`
}
type NIPFundTransferResponse struct {
ResponseCode Code `json:"responseCode"`
ResponseMessage string `json:"responseMessage"`
Reference string `json:"transactionReference"`
SessionID string `json:"sessionId"`
}
// NIPFundTransfer used to transfer fund from a specified Providus account number to another account in a different bank.
func (c *transferClient) NIPFundTransfer(ctx context.Context, payload NIPFundTransferPayload) (data NIPFundTransferResponse, err error) {
req, err := c.newRequest(ctx, http.MethodPost, "/NIPFundTransfer", &nipFundTransferPayload{NIPFundTransferPayload: payload})
if err != nil {
return data, fmt.Errorf("failed to create request: %w", err)
}
req.DecodeTo(&data)
return data, c.do(ctx, req)
}