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