From 731eb60f999d27eb034124de2465c8327f48e753 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Mon, 6 Jan 2025 13:33:27 +0530 Subject: [PATCH] feat: add config to set trial sub end behaviour --- billing/config.go | 2 ++ billing/subscription/service.go | 2 +- config/sample.config.yaml | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/billing/config.go b/billing/config.go index d5962f0cf..edb58dad3 100644 --- a/billing/config.go +++ b/billing/config.go @@ -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 { diff --git a/billing/subscription/service.go b/billing/subscription/service.go index fac8aecc4..22f4a206f 100644 --- a/billing/subscription/service.go +++ b/billing/subscription/service.go @@ -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 } diff --git a/config/sample.config.yaml b/config/sample.config.yaml index 732e4acd5..82f910030 100644 --- a/config/sample.config.yaml +++ b/config/sample.config.yaml @@ -227,3 +227,5 @@ billing: subscription: 1m invoice: 5m checkout: 1m + subscription: + cancel_after_trial: true