forked from BoltApp/braintree-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
payment_method_gateway.go
73 lines (65 loc) · 2.24 KB
/
payment_method_gateway.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
69
70
71
72
73
package braintree
import (
"context"
"encoding/xml"
)
type PaymentMethodGateway struct {
*Braintree
}
type PaymentMethodRequest struct {
XMLName xml.Name `xml:"payment-method"`
CustomerId string `xml:"customer-id,omitempty"`
Token string `xml:"token,omitempty"`
PaymentMethodNonce string `xml:"payment-method-nonce,omitempty"`
Options *PaymentMethodRequestOptions `xml:"options,omitempty"`
}
type PaymentMethodRequestOptions struct {
MakeDefault bool `xml:"make-default,omitempty"`
FailOnDuplicatePaymentMethod bool `xml:"fail-on-duplicate-payment-method,omitempty"`
VerifyCard *bool `xml:"verify-card,omitempty"`
VerificationMerchantAccountId string `xml:"verification-merchant-account-id,omitempty"`
}
func (g *PaymentMethodGateway) Create(ctx context.Context, paymentMethodRequest *PaymentMethodRequest) (PaymentMethod, error) {
resp, err := g.executeVersion(ctx, "POST", "payment_methods", paymentMethodRequest, apiVersion4)
if err != nil {
return nil, err
}
switch resp.StatusCode {
case 201:
return resp.paymentMethod()
}
return nil, &invalidResponseError{resp}
}
func (g *PaymentMethodGateway) Update(ctx context.Context, token string, paymentMethod *PaymentMethodRequest) (PaymentMethod, error) {
resp, err := g.executeVersion(ctx, "PUT", "payment_methods/any/"+token, paymentMethod, apiVersion4)
if err != nil {
return nil, err
}
switch resp.StatusCode {
case 200:
return resp.paymentMethod()
}
return nil, &invalidResponseError{resp}
}
func (g *PaymentMethodGateway) Find(ctx context.Context, token string) (PaymentMethod, error) {
resp, err := g.executeVersion(ctx, "GET", "payment_methods/any/"+token, nil, apiVersion4)
if err != nil {
return nil, err
}
switch resp.StatusCode {
case 200:
return resp.paymentMethod()
}
return nil, &invalidResponseError{resp}
}
func (g *PaymentMethodGateway) Delete(ctx context.Context, token string) error {
resp, err := g.executeVersion(ctx, "DELETE", "payment_methods/any/"+token, nil, apiVersion4)
if err != nil {
return err
}
switch resp.StatusCode {
case 200:
return nil
}
return &invalidResponseError{resp}
}