forked from braintree-go/braintree-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
address_gateway.go
41 lines (36 loc) · 995 Bytes
/
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
package braintree
import (
"context"
"encoding/xml"
)
type AddressGateway struct {
*Braintree
}
// Create creates a new address for the specified customer id.
func (g *AddressGateway) Create(ctx context.Context, a *Address) (*Address, error) {
// Copy address so that field sanitation won't affect original
var cp Address = *a
cp.CustomerId = ""
cp.XMLName = xml.Name{Local: "address"}
resp, err := g.execute(ctx, "POST", "customers/"+a.CustomerId+"/addresses", &cp)
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}
}