From 77c97c88240a055650576466bcb2d6681a97ada2 Mon Sep 17 00:00:00 2001 From: envy124 Date: Sat, 22 Jul 2017 15:54:57 +0300 Subject: [PATCH] ActivatePlan definition --- billing.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/billing.go b/billing.go index 3442f3d..4798f9d 100644 --- a/billing.go +++ b/billing.go @@ -1,7 +1,9 @@ package paypalsdk import ( + "bytes" "fmt" + "net/http" "time" ) @@ -35,3 +37,17 @@ func (c *Client) CreateBillingPlan(plan BillingPlan) (*CreateBillingResp, error) return response, nil } + +// Activates a billing plan +// By default, a new plan is not activated +// Endpoint: PATCH /v1/payments/billing-plans/ +func (c *Client) ActivatePlan(planID string) error { + buf := bytes.NewBuffer([]byte("[{\"op\":\"replace\",\"path\":\"/\",\"value\":{\"state\":\"ACTIVE\"}}]")) + req, err := http.NewRequest("PATCH", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/billing-plans/"+planID), buf) + if err != nil { + return err + } + req.SetBasicAuth(c.ClientID, c.Secret) + req.Header.Set("Authorization", "Bearer "+c.Token.Token) + return c.SendWithAuth(req, nil) +}