From e2dcfe19be7918fbd9c50c2e4a50fdf03f714c65 Mon Sep 17 00:00:00 2001 From: Remi Jannel Date: Sat, 26 May 2018 19:25:59 -0400 Subject: [PATCH] Create params for cancelation and add support for cancel_at_period_end --- sub.go | 8 ++++++-- sub/client.go | 4 ++-- sub/client_test.go | 4 +++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/sub.go b/sub.go index 6ab04185b5..547147e58c 100644 --- a/sub.go +++ b/sub.go @@ -35,6 +35,7 @@ type SubscriptionParams struct { BillingCycleAnchor *int64 `form:"billing_cycle_anchor"` BillingCycleAnchorNow *bool `form:"-"` // See custom AppendTo BillingCycleAnchorUnchanged *bool `form:"-"` // See custom AppendTo + CancelAtPeriodEnd *bool `form:"cancel_at_period_end"` Card *CardParams `form:"card"` Coupon *string `form:"coupon"` Customer *string `form:"customer"` @@ -51,9 +52,12 @@ type SubscriptionParams struct { TrialEndNow *bool `form:"-"` // See custom AppendTo TrialFromPlan *bool `form:"trial_from_plan"` TrialPeriodDays *int64 `form:"trial_period_days"` +} - // Used for Cancel - +// SubscriptionCancelParams is the set of parameters that can be used when canceling a subscription. +// For more details see https://stripe.com/docs/api#cancel_subscription +type SubscriptionCancelParams struct { + Params `form:"*"` AtPeriodEnd *bool `form:"at_period_end"` } diff --git a/sub/client.go b/sub/client.go index 09d6ab3e8a..85af9d97e4 100644 --- a/sub/client.go +++ b/sub/client.go @@ -82,11 +82,11 @@ func (c Client) Update(id string, params *stripe.SubscriptionParams) (*stripe.Su // Cancel removes a subscription. // For more details see https://stripe.com/docs/api#cancel_subscription. -func Cancel(id string, params *stripe.SubscriptionParams) (*stripe.Subscription, error) { +func Cancel(id string, params *stripe.SubscriptionCancelParams) (*stripe.Subscription, error) { return getC().Cancel(id, params) } -func (c Client) Cancel(id string, params *stripe.SubscriptionParams) (*stripe.Subscription, error) { +func (c Client) Cancel(id string, params *stripe.SubscriptionCancelParams) (*stripe.Subscription, error) { var body *form.Values var commonParams *stripe.Params diff --git a/sub/client_test.go b/sub/client_test.go index 567be7cc2a..56de1f1530 100644 --- a/sub/client_test.go +++ b/sub/client_test.go @@ -10,7 +10,9 @@ import ( ) func TestSubscriptionCancel(t *testing.T) { - subscription, err := Cancel("sub_123", nil) + subscription, err := Cancel("sub_123", &stripe.SubscriptionCancelParams{ + AtPeriodEnd: stripe.Bool(true), + }) assert.Nil(t, err) assert.NotNil(t, subscription) }