forked from braintree-go/braintree-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
credit_card_gateway.go
53 lines (48 loc) · 1.15 KB
/
credit_card_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
package braintree
type CreditCardGateway struct {
*Braintree
}
func (g *CreditCardGateway) Create(card *CreditCard) (*CreditCard, error) {
resp, err := g.execute("POST", "payment_methods", card)
if err != nil {
return nil, err
}
switch resp.StatusCode {
case 201:
return resp.creditCard()
}
return nil, &invalidResponseError{resp}
}
func (g *CreditCardGateway) Update(card *CreditCard) (*CreditCard, error) {
resp, err := g.execute("PUT", "payment_methods/"+card.Token, card)
if err != nil {
return nil, err
}
switch resp.StatusCode {
case 200:
return resp.creditCard()
}
return nil, &invalidResponseError{resp}
}
func (g *CreditCardGateway) Find(token string) (*CreditCard, error) {
resp, err := g.execute("GET", "payment_methods/"+token, nil)
if err != nil {
return nil, err
}
switch resp.StatusCode {
case 200:
return resp.creditCard()
}
return nil, &invalidResponseError{resp}
}
func (g *CreditCardGateway) Delete(card *CreditCard) error {
resp, err := g.execute("DELETE", "payment_methods/"+card.Token, nil)
if err != nil {
return err
}
switch resp.StatusCode {
case 200:
return nil
}
return &invalidResponseError{resp}
}