forked from stripe/stripe-go
/
client.go
55 lines (43 loc) · 1.41 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
// Package token provides the /tokens APIs
package token
import (
stripe "github.com/stripe/stripe-go"
"github.com/stripe/stripe-go/form"
)
// Client is used to invoke /tokens APIs.
type Client struct {
B stripe.Backend
Key string
}
// New POSTs a new card or bank account.
// For more details see https://stripe.com/docs/api#create_card_Token and https://stripe.com/docs/api#create_bank_account_token.
func New(params *stripe.TokenParams) (*stripe.Token, error) {
return getC().New(params)
}
func (c Client) New(params *stripe.TokenParams) (*stripe.Token, error) {
body := &form.Values{}
form.AppendTo(body, params)
tok := &stripe.Token{}
err := c.B.Call("POST", "/tokens", c.Key, body, ¶ms.Params, tok)
return tok, err
}
// Get returns the details of a token.
// For more details see https://stripe.com/docs/api#retrieve_token.
func Get(id string, params *stripe.TokenParams) (*stripe.Token, error) {
return getC().Get(id, params)
}
func (c Client) Get(id string, params *stripe.TokenParams) (*stripe.Token, error) {
var body *form.Values
var commonParams *stripe.Params
if params != nil {
commonParams = ¶ms.Params
body = &form.Values{}
form.AppendTo(body, params)
}
token := &stripe.Token{}
err := c.B.Call("GET", stripe.FormatURLPath("/tokens/%s", id), c.Key, body, commonParams, token)
return token, err
}
func getC() Client {
return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key}
}