-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplans.go
62 lines (54 loc) · 1.34 KB
/
plans.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
package conekta
import (
"encoding/json"
"net/http"
"path"
)
// Defines the public interface required to access available 'plans' methods
type PlansAPI interface {
// Creates a new plan using tokenized data
// https://developers.conekta.com/api?language=bash#create-plan
Create(plan *Plan) error
// Updates plan data
// https://developers.conekta.com/api?language=bash#update-plan
Update(update *PlanUpdate) (*Plan, error)
// Deletes plan data
// https://developers.conekta.com/api?language=bash#delete-plan
Delete(planID string) error
}
type plansClient struct {
c *Client
}
func (pc *plansClient) Create(plan *Plan) error {
b, err := pc.c.request(&requestOptions{
endpoint: baseUrl + "plans",
method: http.MethodPost,
data: plan,
})
if err != nil {
return err
}
json.Unmarshal(b, plan)
return nil
}
func (pc *plansClient) Update(update *PlanUpdate) (*Plan, error) {
b, err := pc.c.request(&requestOptions{
endpoint: baseUrl + path.Join("plans", update.ID),
method: http.MethodPut,
data: update,
})
if err != nil {
return nil, err
}
plan := &Plan{}
json.Unmarshal(b, plan)
return plan, err
}
func (pc *plansClient) Delete(planID string) error {
_, err := pc.c.request(&requestOptions{
endpoint: baseUrl + path.Join("plans", planID),
method: http.MethodDelete,
data: planID,
})
return err
}