-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathverification_client.go
More file actions
executable file
·129 lines (122 loc) · 3.95 KB
/
verification_client.go
File metadata and controls
executable file
·129 lines (122 loc) · 3.95 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
package paystack
import (
"context"
"fmt"
"net/http"
"github.com/gray-adeyi/paystack/enum"
)
// VerificationClient interacts with endpoints related to paystack Verification resource
// that allows you to perform KYC processes.
type VerificationClient struct {
*restClient
}
// NewVerificationClient creates a VerificationClient
//
// Example
//
// import p "github.com/gray-adeyi/paystack"
//
// vClient := p.NewVerificationClient(p.WithSecretKey("<paystack-secret-key>"))
func NewVerificationClient(options ...ClientOptions) *VerificationClient {
client := NewClient(options...)
return client.Verification
}
// ResolveAccount lets you confirm an account belongs to the right customer
//
// Default response: models.Response[models.BankAccountInfo]
//
// 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.BankAccountInfo]
// if err := client.Verification.ResolveAccount(context.TODO(), &response,p.WithQuery("account_number","0022728151"),p.WithQuery("bank_code","063")); err != nil {
// panic(err)
// }
//
// fmt.Println(response)
// }
func (v *VerificationClient) ResolveAccount(ctx context.Context, response any, queries ...Query) error {
url := AddQueryParamsToUrl("/bank/resolve", queries...)
return v.APICall(ctx, http.MethodGet, url, nil, response)
}
// ValidateAccount lets you confirm the authenticity of a customer's account number before sending money
//
// Default response: models.Response[models.AccountVerificationInfo]
//
// 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.AccountVerificationInfo]
// if err := client.Verification.ValidateAccount(context.TODO(),"Ann Bron","0123456789",enum.AccountTypePersonal,"632005",enum.CountrySouthAfrica,enum.DocumentIdentityNumber, &response); err != nil {
// panic(err)
// }
//
// fmt.Println(response)
//
// // With optional parameters
// // err := client.Verification.ValidateAccount(context.TODO(),"Ann Bron","0123456789",enum.AccountTypePersonal,"632005",enum.CountrySouthAfrica,enum.DocumentIdentityNumber, &response, p.WithOptionalPayload("document_number","1234567890123"))
// }
//
// For supported optional parameters, see:
// https://paystack.com/docs/api/verification/
func (v *VerificationClient) ValidateAccount(ctx context.Context, accountName string, accountNumber string, accountType enum.AccountType, bankCode string, countryCode enum.Country, documentType enum.Document, response any, optionalPayloads ...OptionalPayload) error {
payload := map[string]any{
"account_name": accountName,
"account_number": accountNumber,
"account_type": accountType,
"bank_code": bankCode,
"country_code": countryCode,
"document_type": documentType,
}
for _, optionalPayloadParameter := range optionalPayloads {
payload = optionalPayloadParameter(payload)
}
return v.APICall(ctx, http.MethodGet, "/bank/validate", payload, response)
}
// ResolveBin lets you retrieve more information about a customer's card
//
// Default response: models.Response[models.CardBin]
//
// 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.CardBin]
// if err := client.Verification.ResolveBin(context.TODO(),"539983", &response); err != nil {
// panic(err)
// }
//
// fmt.Println(response)
// }
func (v *VerificationClient) ResolveBin(ctx context.Context, bin string, response any) error {
return v.APICall(ctx, http.MethodGet, fmt.Sprintf("/decision/bin/%s", bin), nil, response)
}