generated from NdoleStudio/go-http-client
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathsubscription_invoice_service.go
44 lines (36 loc) · 1.38 KB
/
subscription_invoice_service.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
package lemonsqueezy
import (
"context"
"encoding/json"
"net/http"
)
// SubscriptionInvoicesService is the API client for the `/v1/subscription-invoices` endpoint
type SubscriptionInvoicesService service
// Get returns the subscription invoice with the given ID.
//
// https://docs.lemonsqueezy.com/api/subscription-invoices#retrieve-a-subscription-invoice
func (service *SubscriptionInvoicesService) Get(ctx context.Context, invoiceID string) (*SubscriptionInvoiceApiResponse, *Response, error) {
response, err := service.client.do(ctx, http.MethodGet, "/v1/subscription-invoices/"+invoiceID)
if err != nil {
return nil, response, err
}
invoice := new(SubscriptionInvoiceApiResponse)
if err = json.Unmarshal(*response.Body, invoice); err != nil {
return nil, response, err
}
return invoice, response, nil
}
// List a paginated list of subscription invoices.
//
// https://docs.lemonsqueezy.com/api/subscription-invoices#list-all-subscription-invoices
func (service *SubscriptionInvoicesService) List(ctx context.Context) (*SubscriptionInvoicesApiResponse, *Response, error) {
response, err := service.client.do(ctx, http.MethodGet, "/v1/subscription-invoices")
if err != nil {
return nil, response, err
}
invoices := new(SubscriptionInvoicesApiResponse)
if err = json.Unmarshal(*response.Body, invoices); err != nil {
return nil, response, err
}
return invoices, response, nil
}