-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomer.go
More file actions
69 lines (55 loc) · 1.52 KB
/
customer.go
File metadata and controls
69 lines (55 loc) · 1.52 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
package squarego
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
// CustomerResponse ...
type CustomerResponse struct {
Customer Customer `json:"customer"`
}
// Customer ...
type Customer struct {
ID *string `json:"id"`
CreatedAt *string `json:"created_at"`
UpdatedAt *string `json:"updated_at"`
GivenName *string `json:"given_name"`
FamilyName *string `json:"family_name"`
EmailAddress *string `json:"email_address"`
PhoneNumber *string `json:"phone_number"`
ReferenceID *string `json:"reference_id"`
Note *string `json:"note"`
}
// GetCustomerByID ...
func (svc *service) GetCustomerByID(customerID string) (Customer, error) {
var customerResp CustomerResponse
resp, err := svc.createRequest(http.MethodGet, fmt.Sprintf("customers/%s", customerID), nil)
if err != nil {
return Customer{}, err
}
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return Customer{}, err
}
err = json.Unmarshal(b, &customerResp)
return customerResp.Customer, nil
}
// UpdateCustomerByID ...
func (svc *service) UpdateCustomerByID(customerID string, object Customer) (Customer, error) {
var customerResp CustomerResponse
data, err := json.Marshal(object)
if err != nil {
return object, err
}
resp, err := svc.createRequest(http.MethodPut, fmt.Sprintf("customers/%s", customerID), data)
if err != nil {
return Customer{}, err
}
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return Customer{}, err
}
err = json.Unmarshal(b, &customerResp)
return customerResp.Customer, nil
}