Skip to content

Commit 7391163

Browse files
authored
fix: cancel trial in delegated checkout (#863)
1 parent 559f8f6 commit 7391163

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

billing/checkout/service.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,15 @@ func (s *Service) Apply(ctx context.Context, ch Checkout) (*subscription.Subscri
961961
if err != nil {
962962
return nil, nil, fmt.Errorf("failed to create subscription: %w", err)
963963
}
964+
965+
// if set to cancel after trial, schedule a phase to cancel the subscription
966+
if ch.CancelAfterTrial && stripeSubscription.TrialEnd > 0 {
967+
_, err := s.subscriptionService.Cancel(ctx, subs.ID, false)
968+
if err != nil {
969+
return nil, nil, fmt.Errorf("failed to schedule cancel of subscription after trial: %w", err)
970+
}
971+
}
972+
964973
return &subs, nil, nil
965974
} else if ch.ProductID != "" {
966975
chProduct, err := s.productService.GetByID(ctx, ch.ProductID)

0 commit comments

Comments
 (0)