-
Notifications
You must be signed in to change notification settings - Fork 459
/
client.go
45 lines (36 loc) · 1.39 KB
/
client.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
// Package discount provides the discount-related APIs
package discount
import (
"net/http"
stripe "github.com/stripe/stripe-go"
)
// Client is used to invoke discount-related APIs.
type Client struct {
B stripe.Backend
Key string
}
// Del removes a discount from a customer.
func Del(customerID string, params *stripe.DiscountParams) (*stripe.Discount, error) {
return getC().Del(customerID, params)
}
// Del removes a discount from a customer.
func (c Client) Del(customerID string, params *stripe.DiscountParams) (*stripe.Discount, error) {
path := stripe.FormatURLPath("/customers/%s/discount", customerID)
discount := &stripe.Discount{}
err := c.B.Call(http.MethodDelete, path, c.Key, params, discount)
return discount, err
}
// DelSubscription removes a discount from a customer's subscription.
func DelSubscription(subscriptionID string, params *stripe.DiscountParams) (*stripe.Discount, error) {
return getC().DelSub(subscriptionID, params)
}
// DelSub removes a discount from a customer's subscription.
func (c Client) DelSub(subscriptionID string, params *stripe.DiscountParams) (*stripe.Discount, error) {
path := stripe.FormatURLPath("/subscriptions/%s/discount", subscriptionID)
discount := &stripe.Discount{}
err := c.B.Call(http.MethodDelete, path, c.Key, params, discount)
return discount, err
}
func getC() Client {
return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key}
}