add CancelAgreement()

This commit is contained in:
imikod 2018-03-26 14:11:31 +03:00
parent e748748f5c
commit 65a74578c8

View File

@ -28,18 +28,6 @@ type (
}
)
// CreateBillingPlan creates a billing plan in Paypal.
// Endpoint: POST /v1/payments/billing-plans
func (c *Client) CreateBillingPlan(plan BillingPlan) (*BillingPlan, error) {
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/billing-plans"), plan)
response := &BillingPlan{}
if err != nil {
return response, err
}
err = c.SendWithAuth(req, response)
return response, err
}
// ActivatePlan activates a billing plan.
// By default, a new plan is not activated.
// Endpoint: PATCH /v1/payments/billing-plans/
@ -54,6 +42,39 @@ func (c *Client) ActivatePlan(planID string) error {
return c.SendWithAuth(req, nil)
}
// CancelAgreement cancels a billing agreement.
// Endpoint: POST /v1/payments/billing-agreements/{agreement_id}/cancel
func (c *Client) CancelAgreement(agreementID string) error {
req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/billing-agreements/"+agreementID+"/cancel"), nil)
if err != nil {
return err
}
req.SetBasicAuth(c.ClientID, c.Secret)
req.Header.Set("Authorization", "Bearer "+c.Token.Token)
err = c.SendWithAuth(req, nil)
// A successful request returns the HTTP 204 No Content status code with no JSON response body.
// This raises error "EOF"
if err.Error() == "EOF" {
return nil
}
return err
}
// CreateBillingPlan creates a billing plan in Paypal.
// Endpoint: POST /v1/payments/billing-plans
func (c *Client) CreateBillingPlan(plan BillingPlan) (*BillingPlan, error) {
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/billing-plans"), plan)
response := &BillingPlan{}
if err != nil {
return response, err
}
err = c.SendWithAuth(req, response)
return response, err
}
// CreateBillingAgreement creates an agreement for specified plan.
// Endpoint: POST /v1/payments/billing-agreements
func (c *Client) CreateBillingAgreement(a BillingAgreement) (*CreateAgreementResp, error) {
@ -130,5 +151,11 @@ func (c *Client) ListBillingPlans(status interface{}, page interface{}) (*ListBi
err = c.SendWithAuth(req, &l)
// A successful request for empty list returns the HTTP 204 No Content status code with no JSON response body.
// This raises error "EOF"
if err.Error() == "EOF" {
return &l, nil
}
return &l, err
}