forked from stripe/stripe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
63 lines (49 loc) · 1.75 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Package discount provides the discount-related APIs
package discount
import (
"fmt"
stripe "github.com/stripe/stripe-go"
"github.com/stripe/stripe-go/form"
)
// Client is used to invoke discount-related APIs.
type Client struct {
B stripe.Backend
Key string
}
// Del removes a discount from a customer.
// For more details see https://stripe.com/docs/api#delete_discount.
func Del(customerID string, params *stripe.DiscountParams) (*stripe.Discount, error) {
return getC().Del(customerID, params)
}
func (c Client) Del(customerID string, params *stripe.DiscountParams) (*stripe.Discount, error) {
var body *form.Values
var commonParams *stripe.Params
if params != nil {
body = &form.Values{}
form.AppendTo(body, params)
commonParams = ¶ms.Params
}
discount := &stripe.Discount{}
err := c.B.Call("DELETE", fmt.Sprintf("/customers/%v/discount", customerID), c.Key, body, commonParams, discount)
return discount, err
}
// DelSub removes a discount from a customer's subscription.
// For more details see https://stripe.com/docs/api#delete_subscription_discount.
func DelSubscription(subscriptionID string, params *stripe.DiscountParams) (*stripe.Discount, error) {
return getC().DelSub(subscriptionID, params)
}
func (c Client) DelSub(subscriptionID string, params *stripe.DiscountParams) (*stripe.Discount, error) {
var body *form.Values
var commonParams *stripe.Params
if params != nil {
body = &form.Values{}
form.AppendTo(body, params)
commonParams = ¶ms.Params
}
discount := &stripe.Discount{}
err := c.B.Call("DELETE", fmt.Sprintf("/subscriptions/%v/discount", subscriptionID), c.Key, body, commonParams, discount)
return discount, err
}
func getC() Client {
return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key}
}