Handle subscription case where it's set to trial, but renewal_date is not set. set the renewal_date for LENGTH_OF_FREE_TRIAL days from subscription creation.

This commit is contained in:
sabaimran 2024-10-30 11:05:31 -07:00
parent 889dbd738a
commit 2b2564257e

View file

@ -301,6 +301,11 @@ def subscription_to_state(subscription: Subscription) -> str:
return SubscriptionState.INVALID.value return SubscriptionState.INVALID.value
elif subscription.type == Subscription.Type.TRIAL: elif subscription.type == Subscription.Type.TRIAL:
# Check if the trial has expired # Check if the trial has expired
if not subscription.renewal_date:
# If the renewal date is not set, set it to the current date + trial length and evaluate
subscription.renewal_date = subscription.created_at + timedelta(days=LENGTH_OF_FREE_TRIAL)
subscription.save()
if subscription.renewal_date and datetime.now(tz=timezone.utc) > subscription.renewal_date: if subscription.renewal_date and datetime.now(tz=timezone.utc) > subscription.renewal_date:
return SubscriptionState.EXPIRED.value return SubscriptionState.EXPIRED.value
return SubscriptionState.TRIAL.value return SubscriptionState.TRIAL.value