generated from NdoleStudio/go-http-client
-
Notifications
You must be signed in to change notification settings - Fork 16
/
licenses_service.go
76 lines (62 loc) · 2.09 KB
/
licenses_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
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
70
71
72
73
74
75
76
package lemonsqueezy
import (
"context"
"encoding/json"
"net/http"
)
// LicensesService is the API client for the `/v1/licenses` endpoint
type LicensesService service
// Activate a license key.
//
// https://docs.lemonsqueezy.com/help/licensing/license-api
func (service *LicensesService) Activate(ctx context.Context, licenseKey, instanceName string) (*LicenseActivateApiResponse, *Response, error) {
payload := map[string]any{
"license_key": licenseKey,
"instance_name": instanceName,
}
response, err := service.client.do(ctx, http.MethodPost, "/v1/licenses/activate", payload)
if err != nil {
return nil, response, err
}
activation := new(LicenseActivateApiResponse)
if err = json.Unmarshal(*response.Body, activation); err != nil {
return nil, response, err
}
return activation, response, nil
}
// Validate a license key.
//
// https://docs.lemonsqueezy.com/help/licensing/license-api
func (service *LicensesService) Validate(ctx context.Context, licenseKey, instanceID string) (*LicenseValidateApiResponse, *Response, error) {
payload := map[string]any{
"license_key": licenseKey,
"instance_id": instanceID,
}
response, err := service.client.do(ctx, http.MethodPost, "/v1/licenses/validate", payload)
if err != nil {
return nil, response, err
}
validation := new(LicenseValidateApiResponse)
if err = json.Unmarshal(*response.Body, validation); err != nil {
return nil, response, err
}
return validation, response, nil
}
// Deactivate a license key.
//
// https://docs.lemonsqueezy.com/help/licensing/license-api
func (service *LicensesService) Deactivate(ctx context.Context, licenseKey, instanceID string) (*LicenseDeactivateApiResponse, *Response, error) {
payload := map[string]any{
"license_key": licenseKey,
"instance_id": instanceID,
}
response, err := service.client.do(ctx, http.MethodPost, "/v1/licenses/deactivate", payload)
if err != nil {
return nil, response, err
}
deactivation := new(LicenseDeactivateApiResponse)
if err = json.Unmarshal(*response.Body, deactivation); err != nil {
return nil, response, err
}
return deactivation, response, nil
}