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