-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomer.go
196 lines (155 loc) · 6.92 KB
/
customer.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
package swervpay
import (
"context"
"net/http"
)
// Customer represents a customer in the Swervpay system.
type Customer struct {
Country string `json:"country"` // The country of the customer.
CreatedAt string `json:"created_at"` // The creation date of the customer.
Email string `json:"email"` // The email of the customer.
FirstName string `json:"first_name"` // The first name of the customer.
ID string `json:"id"` // The ID of the customer.
IsBlacklisted bool `json:"is_blacklisted"` // Whether the customer is blacklisted.
LastName string `json:"last_name"` // The last name of the customer.
MiddleName string `json:"middle_name"` // The middle name of the customer.
PhoneNumber string `json:"phone_number"` // The phone number of the customer.
Status string `json:"status"` // The status of the customer.
UpdatedAt string `json:"updated_at"` // The last update date of the customer.
}
// CreateCustomerBody represents the body of a request to create a new customer.
type CreateCustomerBody struct {
Country string `json:"country"` // The country of the new customer.
Email string `json:"email"` // The email of the new customer.
Firstname string `json:"firstname"` // The first name of the new customer.
Lastname string `json:"lastname"` // The last name of the new customer.
Middlename string `json:"middlename"` // The middle name of the new customer.
}
// UpdateustomerBody represents the body of a request to update a customer.
type UpdateustomerBody struct {
Email string `json:"email"` // The new email of the customer.
PhoneNumber string `json:"phone_number"` // The new phone number of the customer.
}
// CustomerKycBody represents the body of a request to update a customer's KYC information.
type CustomerKycBody struct {
Tier string `json:"tier"` // The tier of the KYC information.
Tier1 Tier1KycInput `json:"information"` // The tier 1 KYC information.
Tier2 Tier2KycInput `json:"document"` // The tier 2 KYC information.
}
// Tier1KycInput represents the tier 1 KYC information of a customer.
type Tier1KycInput struct {
Bvn string `json:"bvn"` // The BVN of the customer.
State string `json:"state"` // The state of the customer.
City string `json:"city"` // The city of the customer.
Country string `json:"country"` // The country of the customer.
Address string `json:"address"` // The address of the customer.
PostalCode string `json:"postal_code"` // The postal code of the customer.
PhoneNumber string `json:"phone_number"` // The phone number of the customer.
}
// Tier2KycInput represents the tier 2 KYC information of a customer.
type Tier2KycInput struct {
DocumentType string `json:"document_type"` // The type of the document.
Document string `json:"document"` // The document.
Passport string `json:"passport"` // The passport of the customer.
DocumentNumber string `json:"document_number"` // The document number.
}
// CustomerInt is an interface that defines the methods for interacting with customers in the Swervpay system.
type CustomerInt interface {
Gets(ctx context.Context, query *PageAndLimitQuery) (*[]Customer, error) // Gets a list of customers.
Get(ctx context.Context, id string) (*Customer, error) // Gets a specific customer.
Create(ctx context.Context, body *CreateCustomerBody) (*Customer, error) // Creates a new customer.
Update(ctx context.Context, id string, body *UpdateustomerBody) (*Customer, error) // Updates a specific customer.
Kyc(ctx context.Context, id string, body *CustomerKycBody) (*DefaultResponse, error) // Updates the KYC information of a specific customer.
Blacklist(ctx context.Context, id string) (*DefaultResponse, error) // Blacklists a specific customer.
}
// CustomerIntImpl is an implementation of the CustomerInt interface.
type CustomerIntImpl struct {
client *SwervpayClient // The Swervpay client.
}
// Verify that CustomerIntImpl implements the CustomerInt interface.
var _ CustomerInt = &CustomerIntImpl{}
// Gets retrieves a list of customers.
// https://docs.swervpay.co/api-reference/customers/get-all-customers
func (c CustomerIntImpl) Gets(ctx context.Context, query *PageAndLimitQuery) (*[]Customer, error) {
path := GenerateURLPath("customers", query)
req, err := c.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, err
}
response := new([]Customer)
_, err = c.client.Perform(req, response)
if err != nil {
return nil, err
}
return response, nil
}
// Get retrieves a specific customer.
// https://docs.swervpay.co/api-reference/customers/get
func (c CustomerIntImpl) Get(ctx context.Context, id string) (*Customer, error) {
req, err := c.client.NewRequest(ctx, http.MethodGet, "customers/"+id, nil)
if err != nil {
return nil, err
}
response := new(Customer)
_, err = c.client.Perform(req, response)
if err != nil {
return nil, err
}
return response, nil
}
// Create creates a new customer.
// https://docs.swervpay.co/api-reference/customers/create
func (c CustomerIntImpl) Create(ctx context.Context, body *CreateCustomerBody) (*Customer, error) {
req, err := c.client.NewRequest(ctx, http.MethodPost, "customers", body)
if err != nil {
return nil, err
}
response := new(Customer)
_, err = c.client.Perform(req, response)
if err != nil {
return nil, err
}
return response, nil
}
// Update updates a specific customer.
// https://docs.swervpay.co/api-reference/customers/update
func (c CustomerIntImpl) Update(ctx context.Context, id string, body *UpdateustomerBody) (*Customer, error) {
req, err := c.client.NewRequest(ctx, http.MethodPost, "customers/"+id+"/update", body)
if err != nil {
return nil, err
}
response := new(Customer)
_, err = c.client.Perform(req, response)
if err != nil {
return nil, err
}
return response, nil
}
// Kyc updates the KYC information of a specific customer.
// https://docs.swervpay.co/api-reference/customers/kyc
func (c CustomerIntImpl) Kyc(ctx context.Context, id string, body *CustomerKycBody) (*DefaultResponse, error) {
req, err := c.client.NewRequest(ctx, http.MethodPost, "customers/"+id+"/kyc", body)
if err != nil {
return nil, err
}
response := new(DefaultResponse)
_, err = c.client.Perform(req, response)
if err != nil {
return nil, err
}
return response, nil
}
// Blacklist blacklists a specific customer.
// https://docs.swervpay.co/api-reference/customers/blacklist
func (c CustomerIntImpl) Blacklist(ctx context.Context, id string) (*DefaultResponse, error) {
req, err := c.client.NewRequest(ctx, http.MethodPost, "customers/"+id+"/blacklist", nil)
if err != nil {
return nil, err
}
response := new(DefaultResponse)
_, err = c.client.Perform(req, response)
if err != nil {
return nil, err
}
return response, nil
}