forked from stripe/stripe-go
/
client.go
44 lines (35 loc) · 1.04 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
// Package token provides the /tokens APIs
package token
import (
"net/http"
stripe "github.com/stripe/stripe-go"
)
// Client is used to invoke /tokens APIs.
type Client struct {
B stripe.Backend
Key string
}
// New creates a new token.
func New(params *stripe.TokenParams) (*stripe.Token, error) {
return getC().New(params)
}
// New creates a new token.
func (c Client) New(params *stripe.TokenParams) (*stripe.Token, error) {
tok := &stripe.Token{}
err := c.B.Call(http.MethodPost, "/tokens", c.Key, params, tok)
return tok, err
}
// Get returns the details of a token.
func Get(id string, params *stripe.TokenParams) (*stripe.Token, error) {
return getC().Get(id, params)
}
// Get returns the details of a token.
func (c Client) Get(id string, params *stripe.TokenParams) (*stripe.Token, error) {
path := stripe.FormatURLPath("/tokens/%s", id)
token := &stripe.Token{}
err := c.B.Call(http.MethodGet, path, c.Key, params, token)
return token, err
}
func getC() Client {
return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key}
}