Skip to content

Commit

Permalink
Create params for cancelation and add support for cancel_at_period_end
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-stripe committed Jun 6, 2018
1 parent 0ce559d commit e2dcfe1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
8 changes: 6 additions & 2 deletions sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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"`
}

Expand Down
4 changes: 2 additions & 2 deletions sub/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion sub/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit e2dcfe1

Please sign in to comment.