forked from plutov/paypal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplans.go
119 lines (97 loc) · 3.7 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package paypal
import (
"fmt"
"strconv"
)
// CreatePlan creates plan
// Endpoint: POST /v1/billing/plans
func (c *Client) CreatePlan(plan *CreatePlan) (*Plan, error) {
resp := &Plan{}
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/billing/plans"), plan)
if err != nil {
return nil, err
}
if err = c.SendWithBasicAuth(req, resp); err != nil {
return nil, err
}
return resp, nil
}
// ListAllPlans lists all plans
// Endpoint: GET /v1/billing/plans
func (c *Client) ListAllPlans(params *ListPlansParams) (*ListPlansResponse, error) {
resp := &ListPlansResponse{}
req, err := c.NewRequest("GET", fmt.Sprintf("%s%s", c.APIBase, "/v1/billing/plans"), nil)
if err != nil {
return nil, err
}
q := req.URL.Query()
q.Add("product_id", params.ProductID)
q.Add("page_size", strconv.FormatUint(params.PageSize, 10))
q.Add("page", strconv.FormatUint(params.Page, 10))
q.Add("total_required", strconv.FormatBool(params.TotalRequired))
if err = c.SendWithBasicAuth(req, resp); err != nil {
return nil, err
}
return resp, nil
}
// ShowProduct shows details for a plan by ID
// Endpoint: GET /v1/billing/plans/{plan_id}
func (c *Client) ShowPlan(planID string) (*Plan, error) {
resp := &Plan{}
req, err := c.NewRequest("GET", fmt.Sprintf("%s%s", c.APIBase, "/v1/billing/plans/"+planID), nil)
if err != nil {
return nil, err
}
if err = c.SendWithBasicAuth(req, resp); err != nil {
return nil, err
}
return resp, nil
}
// ActivatePlan updates plan status to active
// Endpoint: POST /v1/billing/plans/{plan_id}/activate
func (c *Client) ActivatePlan(planID string) error {
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/billing/plans/"+planID+"/activate"), nil)
if err != nil {
return err
}
return c.SendWithBasicAuth(req, nil)
}
// DeactivatePlan updates plan status to inactive
// Endpoint: POST /v1/billing/plans/{plan_id}/deactivate
func (c *Client) DeactivatePlan(planID string) error {
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/billing/plans/"+planID+"/deactivate"), nil)
if err != nil {
return err
}
return c.SendWithBasicAuth(req, nil)
}
// UpdatePlan updates plan by ID.
// Updates a plan with the CREATED or ACTIVE status. For an INACTIVE plan, you can make only status updates.
// You can update the following attributes and objects
//--------------------------------------------------------------------------
// | Attribute or Object | Operation |
// -------------------------------------------------------------------------
// | /description | add, replace, remove |
// | /payment_preferences/auto_bill_outstanding | add, replace, remove |
// | /taxes/percentage | add, replace, remove |
// | /payment_preferences/payment_failure_threshold | add, replace, remove |
// | /payment_preferences/setup_fee | add, replace, remove |
// | /payment_preferences/setup_fee_failure_action | add, replace, remove |
// -------------------------------------------------------------------------
// Endpoint: PATCH /v1/billing/plan/{plan_id}
func (c *Client) UpdatePlan(planID string, patchObject []*PatchObject) error {
req, err := c.NewRequest("PATCH", fmt.Sprintf("%s%s", c.APIBase, "/v1/billing/plan/"+planID), patchObject)
if err != nil {
return err
}
return c.SendWithBasicAuth(req, nil)
}
// UpdatePricing updates pricing for a plan
// Endpoint: PATCH /v1/billing/plan/{plan_id}/update-pricing-schemas
func (c *Client) UpdatePricing(planID string,updatePricing UpdatePricingSchemasListRequest) error {
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/billing/plan/"+planID+"/update-pricing-schemas"), updatePricing)
if err != nil {
return err
}
return c.SendWithBasicAuth(req, nil)
}