-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdedicated_virtual_account_client.go
More file actions
executable file
·339 lines (321 loc) · 10.4 KB
/
dedicated_virtual_account_client.go
File metadata and controls
executable file
·339 lines (321 loc) · 10.4 KB
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
package paystack
import (
"context"
"fmt"
"net/http"
"github.com/gray-adeyi/paystack/enum"
)
// 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 {
*restClient
}
// NewDedicatedVirtualAccountClient creates a DedicatedVirtualAccountClient
func NewDedicatedVirtualAccountClient(options ...ClientOptions) *DedicatedVirtualAccountClient {
client := NewClient(options...)
return client.DedicatedVirtualAccounts
}
// Create lets you create a dedicated virtual account for an existing customer
//
// Default response: models.Response[models.DedicatedAccount]
//
// Example:
//
// import (
// "context"
// "fmt"
//
// p "github.com/gray-adeyi/paystack"
// "github.com/gray-adeyi/paystack/models"
// )
//
// func main() {
// client := p.NewClient(p.WithSecretKey("<paystack-secret-key>"))
//
// var response models.Response[models.DedicatedAccount]
// if err := client.DedicatedVirtualAccounts.Create(context.TODO(),"CUS_xr58yrr2ujlft9k", &response); err != nil {
// panic(err)
// }
//
// fmt.Println(response)
//
// // With optional parameters
// // err := client.DedicatedVirtualAccounts.Create(context.TODO(),"CUS_xr58yrr2ujlft9k", &response, p.WithOptionalPayload("preferred_bank","wema-bank"))
// }
//
// For supported optional parameters, see:
// https://paystack.com/docs/api/dedicated-virtual-account/
func (d *DedicatedVirtualAccountClient) Create(ctx context.Context, customerIdOrCode string, response any,
optionalPayloads ...OptionalPayload) error {
payload := map[string]any{
"customer": customerIdOrCode,
}
for _, optionalPayloadParameter := range optionalPayloads {
payload = optionalPayloadParameter(payload)
}
return d.APICall(ctx, http.MethodPost, "/dedicated_account", payload, response)
}
// Assign lets you can create a customer, validate the customer, and assign a DVA to the customer.
//
// Default response: models.Response[struct{}]
//
// Example:
//
// import (
// "context"
// "fmt"
//
// p "github.com/gray-adeyi/paystack"
// "github.com/gray-adeyi/paystack/models"
// )
//
// func main() {
// client := p.NewClient(p.WithSecretKey("<paystack-secret-key>"))
//
// var response models.Response[models.DedicatedAccount]
// if err := client.DedicatedVirtualAccounts.Assign(context.TODO(),"janedoe@test.com","Jane", "Doe","Karen", "+2348100000000", "test-bank", enum.CountryNigeria, &response); err != nil {
// panic(err)
// }
//
// fmt.Println(response)
//
// // With optional parameters
// // err := client.DedicatedVirtualAccounts.Assign(context.TODO(),"janedoe@test.com","Jane", "Doe","Karen", "+2348100000000", "test-bank", enum.CountryNigeria, &response, p.WithOptionalPayload("account_number","5273681014"))
// }
//
// For supported optional parameters, see:
// https://paystack.com/docs/api/dedicated-virtual-account/
func (d *DedicatedVirtualAccountClient) Assign(ctx context.Context, email string, firstName string, lastName string,
phone string, preferredBank string, country enum.Country, response any,
optionalPayloads ...OptionalPayload) error {
payload := map[string]any{
"email": email,
"first_name": firstName,
"last_name": lastName,
"phone": phone,
"preferred_bank": preferredBank,
"country": country,
}
for _, optionalPayloadParameter := range optionalPayloads {
payload = optionalPayloadParameter(payload)
}
return d.APICall(ctx, http.MethodPost, "/dedicated_account/assign", payload, response)
}
// All lets you retrieve dedicated virtual accounts available on your Integration.
//
// Default response: models.Response[[]models.DedicatedAccount]
//
// Example:
//
// import (
// "context"
// "fmt"
//
// p "github.com/gray-adeyi/paystack"
// "github.com/gray-adeyi/paystack/models"
// )
//
// func main() {
// client := p.NewClient(p.WithSecretKey("<paystack-secret-key>"))
//
// var response models.Response[[]models.DedicatedAccount]
// if err := client.DedicatedVirtualAccounts.All(context.TODO(), &response); err != nil {
// panic(err)
// }
//
// fmt.Println(response)
//
// // With query parameters
// // err := client.DedicatedVirtualAccounts.All(context.TODO(), &response,p.WithQuery("active","true"), p.WithQuery("bank_id","035"))
// }
//
// For supported query parameters, see:
// https://paystack.com/docs/api/dedicated-virtual-account/
func (d *DedicatedVirtualAccountClient) All(ctx context.Context, response any, queries ...Query) error {
url := AddQueryParamsToUrl("/dedicated_account", queries...)
return d.APICall(ctx, http.MethodGet, url, nil, response)
}
// FetchOne lets you retrieve details of a dedicated virtual account on your Integration.
//
// Default response: models.Response[models.DedicatedAccount]
//
// Example:
//
// import (
// "context"
// "fmt"
//
// p "github.com/gray-adeyi/paystack"
// "github.com/gray-adeyi/paystack/models"
// )
//
// func main() {
// client := p.NewClient(p.WithSecretKey("<paystack-secret-key>"))
//
// var response models.Response[models.DedicatedAccount]
// if err := client.DedicatedVirtualAccounts.FetchOne(context.TODO(),"<dedicatedAccountId>", &response); err != nil {
// panic(err)
// }
//
// fmt.Println(response)
// }
func (d *DedicatedVirtualAccountClient) FetchOne(ctx context.Context, dedicatedAccountId string, response any) error {
return d.APICall(ctx, http.MethodGet, fmt.Sprintf("/dedicated_account/%s", dedicatedAccountId), nil, response)
}
// Requery lets you requery Dedicated Virtual Account for new Transactions
//
// Default response: models.Response[struct{}]
//
// Example:
//
// import (
// "context"
// "fmt"
//
// p "github.com/gray-adeyi/paystack"
// "github.com/gray-adeyi/paystack/models"
// )
//
// func main() {
// client := p.NewClient(p.WithSecretKey("<paystack-secret-key>"))
//
// var response models.Response[[]models.DedicatedAccount]
// if err := client.DedicatedVirtualAccounts.Requery(context.TODO(),"1234567890","wema-bank", &response); err != nil {
// panic(err)
// }
//
// fmt.Println(response)
//
// // With query parameters
// // err := client.DedicatedVirtualAccounts.Requery(context.TODO(),"1234567890","wema-bank", &response,p.WithQuery("date","2025-06-20"))
// }
//
// For supported query parameters, see:
// https://paystack.com/docs/api/dedicated-virtual-account/
func (d *DedicatedVirtualAccountClient) Requery(ctx context.Context, accountNumber, providerSlug string, response any, queries ...Query) error {
return d.APICall(ctx, http.MethodGet, fmt.Sprintf("/dedicated_account/requery?account_number=%s&prodiver_slug=%s", accountNumber, providerSlug), nil, response)
}
// Deactivate lets you deactivate a dedicated virtual account on your Integration.
//
// Default response: models.Response[models.DedicatedAccount]
//
// Example:
//
// import (
// "context"
// "fmt"
//
// p "github.com/gray-adeyi/paystack"
// "github.com/gray-adeyi/paystack/models"
// )
//
// func main() {
// client := p.NewClient(p.WithSecretKey("<paystack-secret-key>"))
//
// var response models.Response[models.DedicatedAccount]
// if err := client.DedicatedVirtualAccounts.Deactivate(context.TODO(),"<dedicatedAccountId>", &response); err != nil {
// panic(err)
// }
//
// fmt.Println(response)
// }
func (d *DedicatedVirtualAccountClient) Deactivate(ctx context.Context, id string, response any) error {
return d.APICall(ctx, http.MethodDelete, fmt.Sprintf("/dedicated_account/%s", id), nil, response)
}
// Split lets you split a dedicated virtual account transaction with one or more accounts
//
// Default response: models.Response[models.DedicatedAccount]
//
// Example:
//
// import (
// "context"
// "fmt"
//
// p "github.com/gray-adeyi/paystack"
// "github.com/gray-adeyi/paystack/models"
// )
//
// func main() {
// client := p.NewClient(p.WithSecretKey("<paystack-secret-key>"))
//
// var response models.Response[models.DedicatedAccount]
// if err := client.DedicatedVirtualAccounts.Split(context.TODO(),"<customerIdOrCode>",&response); err != nil {
// panic(err)
// }
//
// fmt.Println(response)
//
// // With optional parameters
// // err := client.DedicatedVirtualAccounts.Split(context.TODO(),"<customerIdOrCode>",p.WithOptionalPayload("preferred_bank","wema-bank"))
// }
//
// For supported optional parameters, see:
// https://paystack.com/docs/api/dedicated-virtual-account/
func (d *DedicatedVirtualAccountClient) Split(ctx context.Context, customerIdOrCode string, response any, optionalPayloads ...OptionalPayload) error {
payload := map[string]any{
"customer": customerIdOrCode,
}
for _, optionalPayloadParameter := range optionalPayloads {
payload = optionalPayloadParameter(payload)
}
return d.APICall(ctx, http.MethodPost, "/dedicated_account/split", payload, response)
}
// RemoveSplit lets you remove a split payment for Transactions. If you've previously set up split payment
// for Transactions on a dedicated virtual account
//
// Default response: models.Response[models.DedicatedAccount]
//
// Example:
//
// import (
// "context"
// "fmt"
//
// p "github.com/gray-adeyi/paystack"
// "github.com/gray-adeyi/paystack/models"
// )
//
// func main() {
// client := p.NewClient(p.WithSecretKey("<paystack-secret-key>"))
//
// var response models.Response[models.DedicatedAccount]
// if err := client.DedicatedVirtualAccounts.RemoveSplit(context.TODO(),"<accountNumber>",&response); err != nil {
// panic(err)
// }
//
// fmt.Println(response)
// }
func (d *DedicatedVirtualAccountClient) RemoveSplit(ctx context.Context, accountNumber string, response any) error {
payload := map[string]any{
"account_number": accountNumber,
}
return d.APICall(ctx, http.MethodDelete, "/dedicated_account/split", payload, response)
}
// BankProviders lets you retrieve available bank providers for a dedicated virtual account
//
// Default response: models.Response[[]models.DedicatedAccountProvider]
//
// Example:
//
// import (
// "context"
// "fmt"
//
// p "github.com/gray-adeyi/paystack"
// "github.com/gray-adeyi/paystack/models"
// )
//
// func main() {
// client := p.NewClient(p.WithSecretKey("<paystack-secret-key>"))
//
// var response models.Response[[]models.DedicatedAccountProvider]
// if err := client.DedicatedVirtualAccounts.BankProviders(context.TODO(), &response); err != nil {
// panic(err)
// }
//
// fmt.Println(response)
// }
func (d *DedicatedVirtualAccountClient) BankProviders(ctx context.Context, response any) error {
return d.APICall(ctx, http.MethodPost, "/dedicated_account/available_providers", nil, response)
}