From 0f9d1cca169cd0b322d13e57b5a081b0c5adaf21 Mon Sep 17 00:00:00 2001 From: Dimas Ragil T Date: Wed, 16 Dec 2020 16:40:27 +0700 Subject: [PATCH] Add Revise Subscription (#187) * Add function revise subscription * Update README add revise subscription --- README.md | 1 + subscription.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/README.md b/README.md index ebce42b..d817fdc 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ * GET /v1/billing/subscriptions/**ID** * POST /v1/billing/subscriptions/**ID**/activate * POST /v1/billing/subscriptions/**ID**/cancel + * POST /v1/billing/subscriptions/**ID**/revise * POST /v1/billing/subscriptions/**ID**/capture * POST /v1/billing/subscriptions/**ID**/suspend * GET /v1/billing/subscriptions/**ID**/transactions diff --git a/subscription.go b/subscription.go index 711b9ed..77b414d 100644 --- a/subscription.go +++ b/subscription.go @@ -10,6 +10,7 @@ type ( SubscriptionBase struct { PlanID string `json:"plan_id"` StartTime *JSONTime `json:"start_time,omitempty"` + EffectiveTime *JSONTime `json:"effective_time,omitempty"` Quantity string `json:"quantity,omitempty"` ShippingAmount *Money `json:"shipping_amount,omitempty"` Subscriber *Subscriber `json:"subscriber,omitempty"` @@ -186,3 +187,19 @@ func (c *Client) GetSubscriptionTransactions(requestParams SubscriptionTransacti err = c.SendWithAuth(req, response) return response, err } + +// Revise plan or quantity of subscription +// Doc: https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_revise +// Endpoint: POST /v1/billing/subscriptions/{id}/revise +func (c *Client) ReviseSubscription(subscriptionId string, reviseSubscription SubscriptionBase) (*SubscriptionDetailResp, error) { + req, err := c.NewRequest(http.MethodPost, fmt.Sprintf("%s/v1/billing/subscriptions/%s/revise", c.APIBase, subscriptionId), reviseSubscription) + response := &SubscriptionDetailResp{} + if err != nil { + return response, err + } + + req.Header.Add("Content-Type", "application/json") + err = c.SendWithAuth(req, response) + + return response, err +}