-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdedicated_virtual_account_client.go
400 lines (383 loc) · 16.1 KB
/
dedicated_virtual_account_client.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
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
package paystack
import (
"fmt"
"net/http"
)
// DedicatedVirtualAccountClient interacts with endpoints related to paystack dedicated virtual account
// resource that enables Nigerian merchants to manage unique payment accounts of their Customers.
type DedicatedVirtualAccountClient struct {
*baseAPIClient
}
// NewDedicatedVirtualAccountClient creates a DedicatedVirtualAccountClient
//
// Example:
//
// import p "github.com/gray-adeyi/paystack"
//
// dvaClient := p.NewDedicatedVirtualAccountClient(p.WithSecretKey("<paystack-secret-key>"))
func NewDedicatedVirtualAccountClient(options ...ClientOptions) *DedicatedVirtualAccountClient {
client := NewAPIClient(options...)
return client.DedicatedVirtualAccounts
}
// Create lets you create a dedicated virtual account for an existing customer
//
// Example:
//
// import (
// "fmt"
// p "github.com/gray-adeyi/paystack"
// "encoding/json"
// )
//
// dvaClient := p.NewDedicatedVirtualAccountClient(p.WithSecretKey("<paystack-secret-key>"))
// // Alternatively, you can access a dedicated virtual account client from an APIClient
// // paystackClient := p.NewAPIClient(p.WithSecretKey("<paystack-secret-key>"))
// // paystackClient.DedicatedVirtualAccounts field is a `DedicatedVirtualAccountClient`
// // Therefore, this is possible
// // resp, err := paystackClient.DedicatedVirtualAccounts.Create("481193")
//
// // you can pass in optional parameters to the `DedicatedVirtualAccounts.Create` with `p.WithOptionalParameter`
// // for example say you want to specify the `preferred_bank`.
// // resp, err := dvaClient.Create("481193", p.WithOptionalParameter("preferred_bank","wema-bank"))
// // the `p.WithOptionalParameter` takes in a key and value parameter, the key should match the optional parameter
// // from paystack documentation see https://paystack.com/docs/api/dedicated-virtual-account/#create
// // Multiple optional parameters can be passed into `Update` each with it's `p.WithOptionalParameter`
//
// resp, err := dvaClient.Create("481193")
//
// if err != nil {
// panic(err)
// }
// // you can have data be a custom structure based on the data your interested in retrieving from
// // from paystack for simplicity, we're using `map[string]interface{}` which is sufficient to
// // to serialize the json data returned by paystack
// data := make(map[string]interface{})
//
// err := json.Unmarshal(resp.Data, &data); if err != nil {
// panic(err)
// }
// fmt.Println(data)
func (d *DedicatedVirtualAccountClient) Create(customerIdOrCode string,
optionalPayloadParameters ...OptionalPayloadParameter) (*Response, error) {
payload := make(map[string]interface{})
payload["customer"] = customerIdOrCode
for _, optionalPayloadParameter := range optionalPayloadParameters {
payload = optionalPayloadParameter(payload)
}
return d.APICall(http.MethodPost, "/dedicated_account", payload)
}
// Assign lets you can create a customer, validate the customer, and assign a DVA to the customer.
//
// Example:
//
// import (
// "fmt"
// p "github.com/gray-adeyi/paystack"
// "encoding/json"
// )
//
// dvaClient := p.NewDedicatedVirtualAccountClient(p.WithSecretKey("<paystack-secret-key>"))
// // Alternatively, you can access a customer client from an APIClient
// // paystackClient := p.NewAPIClient(p.WithSecretKey("<paystack-secret-key>"))
// // paystackClient.DedicatedVirtualAccounts field is a `DedicatedVirtualAccountClient`
// // Therefore, this is possible
// // resp, err := paystackClient.DedicatedVirtualAccounts.Assign("janedoe@test.com","Jane",
// // "Doe","Karen", "+2348100000000", "test-bank", "NG")
//
// // you can pass in optional parameters to the `DedicatedVirtualAccounts.Assign` with `p.WithOptionalParameter`
// // for example say you want to specify the `account_number`.
// // resp, err := dvaClient.Assign("janedoe@test.com","Jane", "Doe","Karen", "+2348100000000", "test-bank", "NG",
// // p.WithOptionalParameter("account_number","5273681014"))
// // the `p.WithOptionalParameter` takes in a key and value parameter, the key should match the optional parameter
// // from paystack documentation see https://paystack.com/docs/api/dedicated-virtual-account/#create
// // Multiple optional parameters can be passed into `Update` each with it's `p.WithOptionalParameter`
//
// resp, err := dvaClient.Assign("janedoe@test.com","Jane", "Doe","Karen", "+2348100000000", "test-bank", "NG")
//
// if err != nil {
// panic(err)
// }
// // you can have data be a custom structure based on the data your interested in retrieving from
// // from paystack for simplicity, we're using `map[string]interface{}` which is sufficient to
// // to serialize the json data returned by paystack
// data := make(map[string]interface{})
//
// err := json.Unmarshal(resp.Data, &data); if err != nil {
// panic(err)
// }
// fmt.Println(data)
func (d *DedicatedVirtualAccountClient) Assign(email string, firstName string, lastName string,
phone string, preferredBank string, country string,
optionalPayloadParameters ...OptionalPayloadParameter) (*Response, error) {
payload := make(map[string]interface{})
payload["email"] = email
payload["first_name"] = firstName
payload["last_name"] = lastName
payload["phone"] = phone
payload["preferred_bank"] = preferredBank
payload["country"] = country
for _, optionalPayloadParameter := range optionalPayloadParameters {
payload = optionalPayloadParameter(payload)
}
return d.APICall(http.MethodPost, "/dedicated_account/assign", payload)
}
// All lets you retrieve dedicated virtual accounts available on your Integration.
//
// Example:
//
// import (
// "fmt"
// p "github.com/gray-adeyi/paystack"
// "encoding/json"
// )
//
// dvaClient := p.NewDedicatedVirtualAccountClient(p.WithSecretKey("<paystack-secret-key>"))
// // Alternatively, you can access a dedicated virtual account client from an APIClient
// // paystackClient := p.NewAPIClient(p.WithSecretKey("<paystack-secret-key>"))
// // paystackClient.DedicatedVirtualAccounts field is a `DedicatedVirtualAccountClient`
// // Therefore, this is possible
// // resp, err := paystackClient.DedicatedVirtualAccounts.All()
//
// // All also accepts queries, so say you want to customize how many Transactions to retrieve
// // and which page to retrieve, you can write it like so.
// // resp, err := dvaClient.All(p.WithQuery("active","true"), p.WithQuery("bank_id","035"))
//
// // see https://paystack.com/docs/api/dedicated-virtual-account/#list for supported query parameters
//
// resp, err := txnClient.All()
// if err != nil {
// panic(err)
// }
// // you can have data be a custom structure based on the data your interested in retrieving from
// // from paystack for simplicity, we're using `map[string]interface{}` which is sufficient to
// // to serialize the json data returned by paystack
// data := make(map[string]interface{})
//
// err := json.Unmarshal(resp.Data, &data); if err != nil {
// panic(err)
// }
// fmt.Println(data)
func (d *DedicatedVirtualAccountClient) All(queries ...Query) (*Response, error) {
url := AddQueryParamsToUrl("/dedicated_account", queries...)
return d.APICall(http.MethodGet, url, nil)
}
// FetchOne lets you retrieve details of a dedicated virtual account on your Integration.
//
// Example:
//
// import (
// "fmt"
// p "github.com/gray-adeyi/paystack"
// "encoding/json"
// )
//
// dvaClient := p.NewDedicatedVirtualAccountClient(p.WithSecretKey("<paystack-secret-key>"))
// // Alternatively, you can access a dedicated virtual account client from an APIClient
// // paystackClient := p.NewAPIClient(p.WithSecretKey("<paystack-secret-key>"))
// // paystackClient.DedicatedVirtualAccounts field is a `DedicatedVirtualAccountClient`
// // Therefore, this is possible
// // resp, err := paystackClient.DedicatedVirtualAccounts.FetchOne("<dedicatedAccountId>")
//
// resp, err := dvaClient.FetchOne("<dedicatedAccountId>")
// if err != nil {
// panic(err)
// }
// // you can have data be a custom structure based on the data your interested in retrieving from
// // from paystack for simplicity, we're using `map[string]interface{}` which is sufficient to
// // to serialize the json data returned by paystack
// data := make(map[string]interface{})
//
// err := json.Unmarshal(resp.Data, &data); if err != nil {
// panic(err)
// }
// fmt.Println(data)
func (d *DedicatedVirtualAccountClient) FetchOne(dedicatedAccountId string) (*Response, error) {
return d.APICall(http.MethodGet, fmt.Sprintf("/dedicated_account/%s", dedicatedAccountId), nil)
}
// Requery lets you requery Dedicated Virtual Account for new Transactions
//
// Example:
//
// import (
// "fmt"
// p "github.com/gray-adeyi/paystack"
// "encoding/json"
// )
//
// dvaClient := p.NewDedicatedVirtualAccountClient(p.WithSecretKey("<paystack-secret-key>"))
// // Alternatively, you can access a dedicated virtual account client from an APIClient
// // paystackClient := p.NewAPIClient(p.WithSecretKey("<paystack-secret-key>"))
// // paystackClient.DedicatedVirtualAccounts field is a `DedicatedVirtualAccountClient`
// // Therefore, this is possible
// // resp, err := paystackClient.DedicatedVirtualAccounts.Requery()
//
// // All also accepts queries, so say you want to customize how many Transactions to retrieve
// // and which page to retrieve, you can write it like so.
// // resp, err := dvaClient.Requery(p.WithQuery("account_number","1234567890"), p.WithQuery("provider_slug","example-provider"))
//
// // see https://paystack.com/docs/api/dedicated-virtual-account/#requery for supported query parameters
//
// resp, err := txnClient.Requery()
// if err != nil {
// panic(err)
// }
// // you can have data be a custom structure based on the data your interested in retrieving from
// // from paystack for simplicity, we're using `map[string]interface{}` which is sufficient to
// // to serialize the json data returned by paystack
// data := make(map[string]interface{})
//
// err := json.Unmarshal(resp.Data, &data); if err != nil {
// panic(err)
// }
// fmt.Println(data)
func (d *DedicatedVirtualAccountClient) Requery(queries ...Query) (*Response, error) {
return d.All(queries...)
}
// Deactivate lets you deactivate a dedicated virtual account on your Integration.
//
// Example:
//
// import (
// "fmt"
// p "github.com/gray-adeyi/paystack"
// "encoding/json"
// )
//
// dvaClient := p.NewDedicatedVirtualAccountClient(p.WithSecretKey("<paystack-secret-key>"))
// // Alternatively, you can access a dedicated virtual account client from an APIClient
// // paystackClient := p.NewAPIClient(p.WithSecretKey("<paystack-secret-key>"))
// // paystackClient.DedicatedVirtualAccounts field is a `DedicatedVirtualAccountClient`
// // Therefore, this is possible
// // resp, err := paystackClient.DedicatedVirtualAccounts.Deactivate("<dedicatedAccountId>")
//
// resp, err := dvaClient.Deactivate("<dedicatedAccountId>")
// if err != nil {
// panic(err)
// }
// // you can have data be a custom structure based on the data your interested in retrieving from
// // from paystack for simplicity, we're using `map[string]interface{}` which is sufficient to
// // to serialize the json data returned by paystack
// data := make(map[string]interface{})
//
// err := json.Unmarshal(resp.Data, &data); if err != nil {
// panic(err)
// }
// fmt.Println(data)
func (d *DedicatedVirtualAccountClient) Deactivate(id string) (*Response, error) {
return d.APICall(http.MethodDelete, fmt.Sprintf("/dedicated_account/%s", id), nil)
}
// Split lets you split a dedicated virtual account transaction with one or more accounts
//
// Example:
//
// import (
// "fmt"
// p "github.com/gray-adeyi/paystack"
// "encoding/json"
// )
//
// dvaClient := p.NewDedicatedVirtualAccountClient(p.WithSecretKey("<paystack-secret-key>"))
// // Alternatively, you can access a customer client from an APIClient
// // paystackClient := p.NewAPIClient(p.WithSecretKey("<paystack-secret-key>"))
// // paystackClient.DedicatedVirtualAccounts field is a `DedicatedVirtualAccountClient`
// // Therefore, this is possible
// // resp, err := paystackClient.DedicatedVirtualAccounts.Split("<customerIdOrCode>")
//
// // you can pass in optional parameters to the `DedicatedVirtualAccounts.Split` with `p.WithOptionalParameter`
// // for example say you want to specify the `preferred_bank`.
// // resp, err := dvaClient.Split("<customerIdOrCode>", p.WithOptionalParameter("preferred_bank","wema-bank"))
// // the `p.WithOptionalParameter` takes in a key and value parameter, the key should match the optional parameter
// // from paystack documentation see https://paystack.com/docs/api/dedicated-virtual-account/#add-split
// // Multiple optional parameters can be passed into `Update` each with it's `p.WithOptionalParameter`
//
// resp, err := dvaClient.Split("<customerIdOrCode>")
//
// if err != nil {
// panic(err)
// }
// // you can have data be a custom structure based on the data your interested in retrieving from
// // from paystack for simplicity, we're using `map[string]interface{}` which is sufficient to
// // to serialize the json data returned by paystack
// data := make(map[string]interface{})
//
// err := json.Unmarshal(resp.Data, &data); if err != nil {
// panic(err)
// }
// fmt.Println(data)
func (d *DedicatedVirtualAccountClient) Split(customerIdOrCode string, optionalPayloadParameters ...OptionalPayloadParameter) (*Response, error) {
payload := make(map[string]interface{})
payload["customer"] = customerIdOrCode
for _, optionalPayloadParameter := range optionalPayloadParameters {
payload = optionalPayloadParameter(payload)
}
return d.APICall(http.MethodPost, "/dedicated_account/split", payload)
}
// RemoveSplit lets you remove a split payment for Transactions. If you've previously set up split payment
// for Transactions on a dedicated virtual account
//
// Example:
//
// import (
// "fmt"
// p "github.com/gray-adeyi/paystack"
// "encoding/json"
// )
//
// dvaClient := p.NewDedicatedVirtualAccountClient(p.WithSecretKey("<paystack-secret-key>"))
// // Alternatively, you can access a dedicated virtual account client from an APIClient
// // paystackClient := p.NewAPIClient(p.WithSecretKey("<paystack-secret-key>"))
// // paystackClient.DedicatedVirtualAccounts field is a `DedicatedVirtualAccountClient`
// // Therefore, this is possible
// // resp, err := paystackClient.DedicatedVirtualAccounts.RemoveSplit("<accountNumber>")
//
// resp, err := dvaClient.RemoveSplit("<accountNumber>")
// if err != nil {
// panic(err)
// }
// // you can have data be a custom structure based on the data your interested in retrieving from
// // from paystack for simplicity, we're using `map[string]interface{}` which is sufficient to
// // to serialize the json data returned by paystack
// data := make(map[string]interface{})
//
// err := json.Unmarshal(resp.Data, &data); if err != nil {
// panic(err)
// }
// fmt.Println(data)
func (d *DedicatedVirtualAccountClient) RemoveSplit(accountNumber string) (*Response, error) {
payload := make(map[string]interface{})
payload["account_number"] = accountNumber
return d.APICall(http.MethodDelete, "/dedicated_account/split", payload)
}
// BankProviders lets you retrieve available bank providers for a dedicated virtual account
//
// Example:
//
// import (
// "fmt"
// p "github.com/gray-adeyi/paystack"
// "encoding/json"
// )
//
// dvaClient := p.NewDedicatedVirtualAccountClient(p.WithSecretKey("<paystack-secret-key>"))
// // Alternatively, you can access a dedicated virtual account client from an APIClient
// // paystackClient := p.NewAPIClient(p.WithSecretKey("<paystack-secret-key>"))
// // paystackClient.DedicatedVirtualAccounts field is a `DedicatedVirtualAccountClient`
// // Therefore, this is possible
// // resp, err := paystackClient.DedicatedVirtualAccounts.BankProviders()
//
// resp, err := dvaClient.BankProviders()
// if err != nil {
// panic(err)
// }
// // you can have data be a custom structure based on the data your interested in retrieving from
// // from paystack for simplicity, we're using `map[string]interface{}` which is sufficient to
// // to serialize the json data returned by paystack
// data := make(map[string]interface{})
//
// err := json.Unmarshal(resp.Data, &data); if err != nil {
// panic(err)
// }
// fmt.Println(data)
func (d *DedicatedVirtualAccountClient) BankProviders() (*Response, error) {
return d.APICall(http.MethodPost, "/dedicated_account/available_providers", nil)
}