Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
control: cancel subscription, not the schedule (#250)
Browse files Browse the repository at this point in the history
Canceling subscriptions was not updated when switching to treating
subscriptions as the source of truth vs. schedules.

Fixes #249
  • Loading branch information
bmizerany authored Feb 16, 2023
1 parent 6a79d93 commit ae0362e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cmd/tier/tier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ func TestSubscribe(t *testing.T) {
}
]
}`)
case wants(r, "POST", "/v1/subscription_schedules/sub_sched_123/cancel"):
case wants(r, "DELETE", "/v1/subscriptions/sub_123"):
got.Append(r.URL.Path)
default:
io.WriteString(w, `{}`)
Expand All @@ -531,7 +531,7 @@ func TestSubscribe(t *testing.T) {

tt.Run("subscribe", "--cancel", "org:test")

want := []string{"/v1/subscription_schedules/sub_sched_123/cancel"}
want := []string{"/v1/subscriptions/sub_123"}
diff.Test(t, t.Errorf, got.Load(), want)
}

Expand Down
10 changes: 5 additions & 5 deletions control/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,17 +360,17 @@ func (c *Client) updateSchedule(ctx context.Context, schedID, name string, phase
return c.Stripe.Do(ctx, "POST", "/v1/subscription_schedules/"+schedID, f, nil)
}

func (c *Client) cancelSchedule(ctx context.Context, schedID string) (err error) {
defer errorfmt.Handlef("stripe: cancelSchedule: %q: %w", schedID, &err)
if schedID == "" {
func (c *Client) cancelSubscription(ctx context.Context, subID string) (err error) {
defer errorfmt.Handlef("stripe: cancelSchedule: %q: %w", subID, &err)
if subID == "" {
return errors.New("subscription id required")
}
var f stripe.Form
// Explicit set to the same as Stripe's defaults to avoid any
// surprises.
f.Set("invoice_now", true)
f.Set("prorate", true)
return c.Stripe.Do(ctx, "POST", "/v1/subscription_schedules/"+schedID+"/cancel", f, nil)
return c.Stripe.Do(ctx, "DELETE", "/v1/subscriptions/"+subID, f, nil)
}

func addPhases(ctx context.Context, c *Client, f *stripe.Form, update bool, name string, phases []Phase) error {
Expand Down Expand Up @@ -525,7 +525,7 @@ func (c *Client) schedule(ctx context.Context, org string, phases []Phase) (err
}

if cancelNow {
return c.cancelSchedule(ctx, s.ScheduleID)
return c.cancelSubscription(ctx, s.ID)
}

// TODO(bmizerany): check status?
Expand Down

0 comments on commit ae0362e

Please sign in to comment.