-
Notifications
You must be signed in to change notification settings - Fork 9
/
promotions.go
36 lines (29 loc) · 1.14 KB
/
promotions.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
package revenuecat
import "time"
// GrantEntitlement grants a user a promotional entitlement.
// https://docs.revenuecat.com/reference#grant-a-promotional-entitlement
func (c *Client) GrantEntitlement(userID string, id string, duration Duration, startTime time.Time) (Subscriber, error) {
var resp struct {
Subscriber Subscriber `json:"subscriber"`
}
req := struct {
Duration Duration `json:"duration"`
StartTime int64 `json:"start_time_ms,omitempty"`
}{
Duration: duration,
}
if !startTime.IsZero() {
req.StartTime = toMilliseconds(startTime)
}
err := c.call("POST", "subscribers/"+userID+"/entitlements/"+id+"/promotional", req, "", &resp)
return resp.Subscriber, err
}
// RevokeEntitlement revokes all promotional entitlements for a given entitlement identifier and app user ID.
// https://docs.revenuecat.com/reference#revoke-promotional-entitlements
func (c *Client) RevokeEntitlement(userID string, id string) (Subscriber, error) {
var resp struct {
Subscriber Subscriber `json:"subscriber"`
}
err := c.call("POST", "subscribers/"+userID+"/entitlements/"+id+"/revoke_promotionals", nil, "", &resp)
return resp.Subscriber, err
}