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