forked from stripe/stripe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
68 lines (53 loc) · 1.78 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
64
65
66
67
68
// Package ephemeralkey provides the /ephemeral_keys APIs
package ephemeralkey
import (
"fmt"
"net/http"
stripe "github.com/stripe/stripe-go"
)
// Client is used to invoke /ephemeral_keys APIs.
type Client struct {
B stripe.Backend
Key string
}
// New POSTs new ephemeral keys.
// For more details see https://stripe.com/docs/api#create_ephemeral_key.
func New(params *stripe.EphemeralKeyParams) (*stripe.EphemeralKey, error) {
return getC().New(params)
}
// New POSTs new ephemeral keys.
// For more details see https://stripe.com/docs/api#create_ephemeral_key.
func (c Client) New(params *stripe.EphemeralKeyParams) (*stripe.EphemeralKey, error) {
if params.StripeVersion == "" {
return nil, fmt.Errorf("params.StripeVersion must be specified")
}
body := &stripe.RequestValues{}
if len(params.Customer) > 0 {
body.Add("customer", params.Customer)
}
if len(params.StripeVersion) > 0 {
if params.Headers == nil {
params.Headers = make(http.Header)
}
params.Headers.Add("Stripe-Version", params.StripeVersion)
}
params.AppendTo(body)
ephemeralKey := &stripe.EphemeralKey{}
err := c.B.Call("POST", "ephemeral_keys", c.Key, body, ¶ms.Params, ephemeralKey)
return ephemeralKey, err
}
// Del removes an ephemeral key.
// For more details see https://stripe.com/docs/api#delete_ephemeral_key.
func Del(id string) (*stripe.EphemeralKey, error) {
return getC().Del(id)
}
// Del removes an ephemeral key.
// For more details see https://stripe.com/docs/api#delete_ephemeral_key.
func (c Client) Del(id string) (*stripe.EphemeralKey, error) {
ephemeralKey := &stripe.EphemeralKey{}
err := c.B.Call("DELETE", "/ephemeral_keys/"+id, c.Key, nil, nil, ephemeralKey)
return ephemeralKey, err
}
func getC() Client {
return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key}
}