forked from braintree-go/braintree-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplan_gateway.go
More file actions
41 lines (37 loc) · 768 Bytes
/
plan_gateway.go
File metadata and controls
41 lines (37 loc) · 768 Bytes
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 PlanGateway struct {
*Braintree
}
// All returns all available plans
func (g *PlanGateway) All(ctx context.Context) ([]*Plan, error) {
resp, err := g.execute(ctx, "GET", "plans", nil)
if err != nil {
return nil, err
}
switch resp.StatusCode {
case 200:
var b Plans
if err := xml.Unmarshal(resp.Body, &b); err != nil {
return nil, err
}
return b.Plan, nil
}
return nil, &invalidResponseError{resp}
}
// Find returns the plan with the specified id, or nil
func (g *PlanGateway) Find(ctx context.Context, id string) (*Plan, error) {
plans, err := g.All(ctx)
if err != nil {
return nil, err
}
for _, p := range plans {
if p.Id == id {
return p, nil
}
}
return nil, nil
}