-
Notifications
You must be signed in to change notification settings - Fork 0
/
customers.go
222 lines (185 loc) · 6.81 KB
/
customers.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
// The Customers API allows you create and manage customers on your integration.
package paystack
import (
"encoding/json"
"fmt"
)
type CreateCustomerBody struct {
// Email: Customer's email address
Email string `json:"email"`
// FirstName: Customer's first name
FirstName string `json:"first_name,omitempty"`
// LastName: Customer's last name
LastName string `json:"last_name,omitempty"`
// Phone: Customer's phone number
Phone string `json:"phone,omitempty"`
// Metadata: A set of key/value pairs that you can attach to the customer.
//It can be used to store additional information in a structured format.
Metadata map[string]any `json:"metadata,omitempty"`
}
type UpdateCustomerBody struct {
// FirstName: Customer's first name
FirstName string `json:"first_name"`
// LastName: Customer's last name
LastName string `json:"last_name"`
// Phone: Customer's phone number
Phone string `json:"phone"`
// Metadata: A set of key/value pairs that you can attach to the customer.
//It can be used to store additional information in a structured format.
Metadata map[string]any `json:"metadata,omitempty"`
}
type ValidateCustomerBody struct {
// FirstName: Customer's first name
FirstName string `json:"first_name"`
// LastName: Customer's last name
LastName string `json:"last_name"`
// Type: Predefined types of identification.
// Only bank_account is supported at the moment
Type string `json:"type"`
// Value: Customer's identification number
Value string `json:"value"`
// Country: 2 letter country code of identification issuer
Country string `json:"country"`
// BVN: Customer's Bank Verification Number
BVN string `json:"bvn"`
// BankCode: You can get the list of Bank Codes by calling
// the List Banks endpoint. (required if type is bank_account)
//
// https://paystack.com/docs/api/#miscellaneous-bank
BankCode string `json:"bank_code"`
// AccountNumber: Customer's bank account number. (required if type is bank_account)
AccountNumber string `json:"account_number"`
// MiddleName: Customer's middle name - Optional
MiddleName string `json:"middle_name,omitempty"`
}
type WhiteListOrBlacklistCustomerBody struct {
// Customer's code, or email address
Customer string `json:"customer"`
// One of the possible risk actions [ default, allow, deny ].
// allow to whitelist. deny to blacklist. Customers start with a default risk action.
RiskAction string `json:"risk_action"`
}
type DeactivateAuthorizationBody struct {
// Authorization code to be deactivated
AuthorizationCode string `json:"authorization_code"`
}
// CreateCustomer create a customer on your integration
//
// **Customer Validation**
//
// The first_name, last_name and phone are optional parameters.
// However, when creating a customer that would be assigned a
// Dedicated Virtual Account and your business catgeory falls
// under Betting, Financial services, and General Service,
// then these parameters become compulsory.
//
// Docs: https://paystack.com/docs/api/#customer-create
//
// client, _ := paystack.NewClient(apiKey)
// auth, err := client.CreateCustomer(body struct{}})
func (c *Config) CreateCustomer(body *CreateCustomerBody) (Response, error) {
path := "/customer"
response, err := c.makeRequest("POST", path, body)
if err != nil {
_ = json.Unmarshal(response, &jsonResponse)
return jsonResponse, err
}
_ = json.Unmarshal(response, &jsonResponse)
return jsonResponse, err
}
// ListCustomers lists customers available on your integration
//
// Docs: https://paystack.com/docs/api/#customer-list
//
// client, _ := paystack.NewClient(apiKey)
// auth, err := client.ListCustomers()
func (c *Config) ListCustomers() (Response, error) {
path := "/customer"
response, err := c.makeRequest("GET", path, nil)
if err != nil {
_ = json.Unmarshal(response, &jsonResponse)
return jsonResponse, err
}
_ = json.Unmarshal(response, &jsonResponse)
return jsonResponse, err
}
// FetchCustomer gets details of a customer on your integration
//
// Docs: https://paystack.com/docs/api/#customer-fetch
//
// client, _ := paystack.NewClient(apiKey)
// auth, err := client.FetchCustomer(emailOrCode string)
func (c *Config) FetchCustomer(emailOrCode string) (Response, error) {
path := fmt.Sprintf("/customer/%s", emailOrCode)
response, err := c.makeRequest("GET", path, nil)
if err != nil {
_ = json.Unmarshal(response, &jsonResponse)
return jsonResponse, err
}
_ = json.Unmarshal(response, &jsonResponse)
return jsonResponse, err
}
// UpdateCustomer updates a customer's detail on your integration
//
// Docs: https://paystack.com/docs/api/#customer-update
//
// client, _ := paystack.NewClient(apiKey)
// auth, err := client.UpdateCustomer(code string, body structs{})
func (c *Config) UpdateCustomer(code string, body *UpdateCustomerBody) (Response, error) {
path := fmt.Sprintf("/customer/%s", code)
response, err := c.makeRequest("PUT", path, body)
if err != nil {
_ = json.Unmarshal(response, &jsonResponse)
return jsonResponse, err
}
_ = json.Unmarshal(response, &jsonResponse)
return jsonResponse, err
}
// ValidateCustomer validates a customer's identity
//
// Docs: https://paystack.com/docs/api/#customer-validate
//
// client, _ := paystack.NewClient(apiKey)
// auth, err := client.ValidateCustomer(code string, body structs{})
func (c *Config) ValidateCustomer(code string, body *ValidateCustomerBody) (Response, error) {
path := fmt.Sprintf("/customer/%s/identification", code)
response, err := c.makeRequest("POST", path, body)
if err != nil {
_ = json.Unmarshal(response, &jsonResponse)
return jsonResponse, err
}
_ = json.Unmarshal(response, &jsonResponse)
return jsonResponse, err
}
// WhiteListOrBlacklistCustomer: Whitelist or blacklist a customer on your integration
//
// Docs: https://paystack.com/docs/api/#customer-whitelist-blacklist
//
// client, _ := paystack.NewClient(apiKey)
// auth, err := client.WhiteListOrBlacklistCustomer(body structs{})
func (c *Config) WhiteListOrBlacklistCustomer(body *WhiteListOrBlacklistCustomerBody) (Response, error) {
path := "/customer/set_risk_action"
response, err := c.makeRequest("POST", path, body)
if err != nil {
_ = json.Unmarshal(response, &jsonResponse)
return jsonResponse, err
}
_ = json.Unmarshal(response, &jsonResponse)
return jsonResponse, err
}
// DeactivateAuthorization: Deactivate an authorization when the card needs to be forgotten
//
// Docs: https://paystack.com/docs/api/#customer-deactivate-authorization
//
// client, _ := paystack.NewClient(apiKey)
// auth, err := client.DeactivateAuthorization(body structs{})
func (c *Config) DeactivateAuthorization(body *DeactivateAuthorizationBody) (Response, error) {
path := "/customer/deactivate_authorization"
response, err := c.makeRequest("POST", path, body)
if err != nil {
_ = json.Unmarshal(response, &jsonResponse)
return jsonResponse, err
}
_ = json.Unmarshal(response, &jsonResponse)
return jsonResponse, err
}