Skip to content

Commit

Permalink
feat: add config to set trial sub end behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
rsbh committed Jan 6, 2025
1 parent 83bd68f commit 731eb60
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions billing/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ type PlanChangeConfig struct {
}

type SubscriptionConfig struct {
// CancelAfterTrial will cancel the subscription after trial end and will not generate invoice.
CancelAfterTrial bool `yaml:"cancel_after_trial" mapstructure:"cancel_after_trial" default:"false"`
}

type ProductConfig struct {
Expand Down
2 changes: 1 addition & 1 deletion billing/subscription/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ func (s *Service) CancelUpcomingPhase(ctx context.Context, sub Subscription) err

var endBehavior = stripe.SubscriptionScheduleEndBehaviorRelease

if stripeSub.Status == stripe.SubscriptionStatusTrialing {
if stripeSub.Status == stripe.SubscriptionStatusTrialing && s.config.SubscriptionConfig.CancelAfterTrial {
endBehavior = stripe.SubscriptionScheduleEndBehaviorCancel
}

Expand Down
2 changes: 2 additions & 0 deletions config/sample.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,5 @@ billing:
subscription: 1m
invoice: 5m
checkout: 1m
subscription:
cancel_after_trial: true

0 comments on commit 731eb60

Please sign in to comment.