Skip to content

Commit

Permalink
feat: set EndBehavior to cancel in trialing
Browse files Browse the repository at this point in the history
  • Loading branch information
rsbh committed Jan 6, 2025
1 parent e065480 commit 83bd68f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions billing/subscription/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ func (s *Service) getPlanFromSchedule(ctx context.Context, stripeSchedule *strip

// CancelUpcomingPhase cancels the scheduled phase of the subscription
func (s *Service) CancelUpcomingPhase(ctx context.Context, sub Subscription) error {
_, stripeSchedule, err := s.createOrGetSchedule(ctx, sub)
stripeSub, stripeSchedule, err := s.createOrGetSchedule(ctx, sub)
if err != nil {
return err
}
Expand All @@ -988,6 +988,12 @@ func (s *Service) CancelUpcomingPhase(ctx context.Context, sub Subscription) err
var currency = string(stripeSchedule.Phases[0].Currency)
var prorationBehavior = s.config.PlanChangeConfig.ProrationBehavior

var endBehavior = stripe.SubscriptionScheduleEndBehaviorRelease

if stripeSub.Status == stripe.SubscriptionStatusTrialing {
endBehavior = stripe.SubscriptionScheduleEndBehaviorCancel
}

// update the phases
_, err = s.stripeClient.SubscriptionSchedules.Update(stripeSchedule.ID, &stripe.SubscriptionScheduleParams{
Params: stripe.Params{
Expand All @@ -1005,7 +1011,7 @@ func (s *Service) CancelUpcomingPhase(ctx context.Context, sub Subscription) err
},
},
},
EndBehavior: stripe.String("release"),
EndBehavior: stripe.String(string(endBehavior)),
ProrationBehavior: stripe.String(prorationBehavior),
DefaultSettings: &stripe.SubscriptionScheduleDefaultSettingsParams{
CollectionMethod: stripe.String(s.config.PlanChangeConfig.CollectionMethod),
Expand Down

0 comments on commit 83bd68f

Please sign in to comment.