1
|
|
|
package client |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"context" |
5
|
|
|
"encoding/json" |
6
|
|
|
"net/http" |
7
|
|
|
) |
8
|
|
|
|
9
|
|
|
// CustomersService is the API client for the `/v1/stores` endpoint |
10
|
|
|
type CustomersService service |
11
|
|
|
|
12
|
|
|
// Get returns the customer with the given ID. |
13
|
|
|
// https://docs.lemonsqueezy.com/api/customers#retrieve-a-customer |
14
|
|
|
func (service *CustomersService) Get(ctx context.Context, customerID string) (*CustomerApiResponse, *Response, error) { |
15
|
|
|
response, err := service.client.do(ctx, http.MethodGet, "/v1/customers/"+customerID) |
16
|
|
|
if err != nil { |
17
|
|
|
return nil, response, err |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
customer := new(CustomerApiResponse) |
21
|
|
|
if err = json.Unmarshal(*response.Body, customer); err != nil { |
22
|
|
|
return nil, response, err |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
return customer, response, nil |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
// List returns a paginated list of customers. |
29
|
|
|
// https://docs.lemonsqueezy.com/api/customers#list-all-customers |
30
|
|
|
func (service *CustomersService) List(ctx context.Context) (*CustomersApiResponse, *Response, error) { |
31
|
|
|
response, err := service.client.do(ctx, http.MethodGet, "/v1/customers") |
32
|
|
|
if err != nil { |
33
|
|
|
return nil, response, err |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
customers := new(CustomersApiResponse) |
37
|
|
|
if err = json.Unmarshal(*response.Body, customers); err != nil { |
38
|
|
|
return nil, response, err |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return customers, response, nil |
42
|
|
|
} |
43
|
|
|
|