forked from stripe/stripe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
64 lines (50 loc) · 1.67 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
// Package threedsecure provides the /3d_secure APIs
package threedsecure
import (
"strconv"
"github.com/stripe/stripe-go"
)
// Client is used to invoke /3d_secure APIs.
type Client struct {
B stripe.Backend
Key string
}
// New POSTs new 3D Secure auths.
// For more details see https://stripe.com/docs/api#create_three_d_secure.
func New(params *stripe.ThreeDSecureParams) (*stripe.ThreeDSecure, error) {
return getC().New(params)
}
func (c Client) New(params *stripe.ThreeDSecureParams) (*stripe.ThreeDSecure, error) {
body := &stripe.RequestValues{}
body.Add("amount", strconv.FormatUint(params.Amount, 10))
body.Add("card", params.Card)
body.Add("currency", string(params.Currency))
body.Add("return_url", params.ReturnURL)
if len(params.Customer) > 0 {
body.Add("customer", params.Customer)
}
params.AppendTo(body)
tds := &stripe.ThreeDSecure{}
err := c.B.Call("POST", "/3d_secure", c.Key, body, ¶ms.Params, tds)
return tds, err
}
// Get returns the details of a 3D Secure auth.
// For more details see https://stripe.com/docs/api#retrieve_three_d_secure.
func Get(id string, params *stripe.ThreeDSecureParams) (*stripe.ThreeDSecure, error) {
return getC().Get(id, params)
}
func (c Client) Get(id string, params *stripe.ThreeDSecureParams) (*stripe.ThreeDSecure, error) {
var body *stripe.RequestValues
var commonParams *stripe.Params
if params != nil {
body = &stripe.RequestValues{}
commonParams = ¶ms.Params
params.AppendTo(body)
}
tds := &stripe.ThreeDSecure{}
err := c.B.Call("GET", "/3d_secure/"+id, c.Key, body, commonParams, tds)
return tds, err
}
func getC() Client {
return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key}
}