1
1
package paypal
2
2
3
3
import (
4
+ "context"
4
5
"errors"
5
6
"fmt"
6
7
"net/http"
43
44
44
45
// CreateBillingPlan creates a billing plan in Paypal
45
46
// Endpoint: POST /v1/payments/billing-plans
46
- func (c * Client ) CreateBillingPlan (plan BillingPlan ) (* CreateBillingResp , error ) {
47
- req , err := c .NewRequest (http .MethodPost , fmt .Sprintf ("%s%s" , c .APIBase , "/v1/payments/billing-plans" ), plan )
47
+ func (c * Client ) CreateBillingPlan (ctx context. Context , plan BillingPlan ) (* CreateBillingResp , error ) {
48
+ req , err := c .NewRequest (ctx , http .MethodPost , fmt .Sprintf ("%s%s" , c .APIBase , "/v1/payments/billing-plans" ), plan )
48
49
response := & CreateBillingResp {}
49
50
if err != nil {
50
51
return response , err
@@ -55,7 +56,7 @@ func (c *Client) CreateBillingPlan(plan BillingPlan) (*CreateBillingResp, error)
55
56
56
57
// UpdateBillingPlan updates values inside a billing plan
57
58
// Endpoint: PATCH /v1/payments/billing-plans
58
- func (c * Client ) UpdateBillingPlan (planId string , pathValues map [string ]map [string ]interface {}) error {
59
+ func (c * Client ) UpdateBillingPlan (ctx context. Context , planId string , pathValues map [string ]map [string ]interface {}) error {
59
60
patchData := []Patch {}
60
61
for path , data := range pathValues {
61
62
patchData = append (patchData , Patch {
@@ -64,8 +65,8 @@ func (c *Client) UpdateBillingPlan(planId string, pathValues map[string]map[stri
64
65
Value : data ,
65
66
})
66
67
}
67
-
68
- req , err := c .NewRequest (http .MethodPatch , fmt .Sprintf ("%s%s%s" , c .APIBase , "/v1/payments/billing-plans/" , planId ), patchData )
68
+
69
+ req , err := c .NewRequest (ctx , http .MethodPatch , fmt .Sprintf ("%s%s%s" , c .APIBase , "/v1/payments/billing-plans/" , planId ), patchData )
69
70
if err != nil {
70
71
return err
71
72
}
@@ -76,21 +77,21 @@ func (c *Client) UpdateBillingPlan(planId string, pathValues map[string]map[stri
76
77
// ActivatePlan activates a billing plan
77
78
// By default, a new plan is not activated
78
79
// Endpoint: PATCH /v1/payments/billing-plans/
79
- func (c * Client ) ActivatePlan (planID string ) error {
80
- return c .UpdateBillingPlan (planID , map [string ]map [string ]interface {}{
80
+ func (c * Client ) ActivatePlan (ctx context. Context , planID string ) error {
81
+ return c .UpdateBillingPlan (ctx , planID , map [string ]map [string ]interface {}{
81
82
"/" : {"state" : BillingPlanStatusActive },
82
83
})
83
84
}
84
85
85
86
// CreateBillingAgreement creates an agreement for specified plan
86
87
// Endpoint: POST /v1/payments/billing-agreements
87
- func (c * Client ) CreateBillingAgreement (a BillingAgreement ) (* CreateAgreementResp , error ) {
88
+ func (c * Client ) CreateBillingAgreement (ctx context. Context , a BillingAgreement ) (* CreateAgreementResp , error ) {
88
89
// PayPal needs only ID, so we will remove all fields except Plan ID
89
90
a .Plan = BillingPlan {
90
91
ID : a .Plan .ID ,
91
92
}
92
93
93
- req , err := c .NewRequest (http .MethodPost , fmt .Sprintf ("%s%s" , c .APIBase , "/v1/payments/billing-agreements" ), a )
94
+ req , err := c .NewRequest (ctx , http .MethodPost , fmt .Sprintf ("%s%s" , c .APIBase , "/v1/payments/billing-agreements" ), a )
94
95
response := & CreateAgreementResp {}
95
96
if err != nil {
96
97
return response , err
@@ -101,8 +102,8 @@ func (c *Client) CreateBillingAgreement(a BillingAgreement) (*CreateAgreementRes
101
102
102
103
// ExecuteApprovedAgreement - Use this call to execute (complete) a PayPal agreement that has been approved by the payer.
103
104
// Endpoint: POST /v1/payments/billing-agreements/token/agreement-execute
104
- func (c * Client ) ExecuteApprovedAgreement (token string ) (* ExecuteAgreementResponse , error ) {
105
- req , err := http .NewRequest ( http .MethodPost , fmt .Sprintf ("%s/v1/payments/billing-agreements/%s/agreement-execute" , c .APIBase , token ), nil )
105
+ func (c * Client ) ExecuteApprovedAgreement (ctx context. Context , token string ) (* ExecuteAgreementResponse , error ) {
106
+ req , err := http .NewRequestWithContext ( ctx , http .MethodPost , fmt .Sprintf ("%s/v1/payments/billing-agreements/%s/agreement-execute" , c .APIBase , token ), nil )
106
107
response := & ExecuteAgreementResponse {}
107
108
108
109
if err != nil {
@@ -125,8 +126,8 @@ func (c *Client) ExecuteApprovedAgreement(token string) (*ExecuteAgreementRespon
125
126
126
127
// ListBillingPlans lists billing-plans
127
128
// Endpoint: GET /v1/payments/billing-plans
128
- func (c * Client ) ListBillingPlans (bplp BillingPlanListParams ) (* BillingPlanListResp , error ) {
129
- req , err := c .NewRequest ("GET" , fmt .Sprintf ("%s%s" , c .APIBase , "/v1/payments/billing-plans" ), nil )
129
+ func (c * Client ) ListBillingPlans (ctx context. Context , bplp BillingPlanListParams ) (* BillingPlanListResp , error ) {
130
+ req , err := c .NewRequest (ctx , "GET" , fmt .Sprintf ("%s%s" , c .APIBase , "/v1/payments/billing-plans" ), nil )
130
131
response := & BillingPlanListResp {}
131
132
if err != nil {
132
133
return response , err
0 commit comments