forked from stripe/stripe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
53 lines (43 loc) · 1.52 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
// 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 create a new ephemeral key.
func New(params *stripe.EphemeralKeyParams) (*stripe.EphemeralKey, error) {
return getC().New(params)
}
// New create a new ephemeral key.
func (c Client) New(params *stripe.EphemeralKeyParams) (*stripe.EphemeralKey, error) {
if params.StripeVersion == nil || len(stripe.StringValue(params.StripeVersion)) == 0 {
return nil, fmt.Errorf("params.StripeVersion must be specified")
}
if params.Headers == nil {
params.Headers = make(http.Header)
}
params.Headers.Add("Stripe-Version", stripe.StringValue(params.StripeVersion))
ephemeralKey := &stripe.EphemeralKey{}
err := c.B.Call(http.MethodPost, "/v1/ephemeral_keys", c.Key, params, ephemeralKey)
return ephemeralKey, err
}
// Del removes an ephemeral key.
func Del(id string, params *stripe.EphemeralKeyParams) (*stripe.EphemeralKey, error) {
return getC().Del(id, params)
}
// Del removes an ephemeral key.
func (c Client) Del(id string, params *stripe.EphemeralKeyParams) (*stripe.EphemeralKey, error) {
path := stripe.FormatURLPath("/v1/ephemeral_keys/%s", id)
ephemeralKey := &stripe.EphemeralKey{}
err := c.B.Call(http.MethodDelete, path, c.Key, params, ephemeralKey)
return ephemeralKey, err
}
func getC() Client {
return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key}
}