From 67e1812d696a27fec362d0a8b4ff8ffd75576abe Mon Sep 17 00:00:00 2001 From: Jhony Lucas Date: Mon, 15 Jul 2024 16:25:05 -0300 Subject: [PATCH] fix: add trial period for new subscriptions (#632) --- backend/apps/account_payment/graphql.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/apps/account_payment/graphql.py b/backend/apps/account_payment/graphql.py index 2a5fd7ed..7a496e94 100644 --- a/backend/apps/account_payment/graphql.py +++ b/backend/apps/account_payment/graphql.py @@ -192,19 +192,23 @@ class Arguments: def mutate(cls, root, info, price_id): try: admin = info.context.user + internal_subscriptions = admin.internal_subscription.all() for s in [ *admin.subscription_set.all(), - *admin.internal_subscription.all(), + *internal_subscriptions, ]: if s.is_active: return cls(errors=["Conta possui inscrição ativa"]) price = DJStripePrice.objects.get(djstripe_id=price_id) + trial_period_days = 0 if len(internal_subscriptions) > 0 else 7 + subscription: DJStripeSubscription = admin.customer.subscribe( price=price.id, payment_behavior="default_incomplete", payment_settings={"save_default_payment_method": "on_subscription"}, + trial_period_days=trial_period_days, ) Subscription.objects.create(admin=admin, subscription=subscription) return cls(subscription=subscription)