forked from BoltApp/braintree-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
address_gateway.go
48 lines (43 loc) · 1.24 KB
/
address_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
package braintree
import (
"context"
)
type AddressGateway struct {
*Braintree
}
// Create creates a new address for the specified customer id.
func (g *AddressGateway) Create(ctx context.Context, customerID string, a *AddressRequest) (*Address, error) {
resp, err := g.execute(ctx, "POST", "customers/"+customerID+"/addresses", &a)
if err != nil {
return nil, err
}
switch resp.StatusCode {
case 201:
return resp.address()
}
return nil, &invalidResponseError{resp}
}
// Delete deletes the address for the specified id and customer id.
func (g *AddressGateway) Delete(ctx context.Context, customerId, addrId string) error {
resp, err := g.execute(ctx, "DELETE", "customers/"+customerId+"/addresses/"+addrId, nil)
if err != nil {
return err
}
switch resp.StatusCode {
case 200:
return nil
}
return &invalidResponseError{resp}
}
// Update updates an address for the address id and customer id.
func (g *AddressGateway) Update(ctx context.Context, customerID, addrID string, a *AddressRequest) (*Address, error) {
resp, err := g.execute(ctx, "PUT", "customers/"+customerID+"/addresses/"+addrID, a)
if err != nil {
return nil, err
}
switch resp.StatusCode {
case 200:
return resp.address()
}
return nil, &invalidResponseError{resp}
}