ActivatePlan definition

This commit is contained in:
envy124 2017-07-22 15:54:57 +03:00
parent e033a62fe2
commit 77c97c8824

View File

@ -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)
}