diff --git a/app/models.py b/app/models.py index d8b4b802..d0bb193a 100644 --- a/app/models.py +++ b/app/models.py @@ -57,6 +57,8 @@ from app.utils import ( Base = declarative_base() +PADDLE_SUBSCRIPTION_GRACE_DAYS = 14 + class TSVector(sa.types.TypeDecorator): impl = TSVECTOR @@ -752,8 +754,11 @@ class User(Base, ModelMixin, UserMixin, PasswordOracle): if sub: # grace period is 14 days - # sub is active until the next billing_date + 14 - if sub.next_bill_date >= arrow.now().shift(days=-14).date(): + # sub is active until the next billing_date + PADDLE_SUBSCRIPTION_GRACE_DAYS + if ( + sub.next_bill_date + >= arrow.now().shift(days=-PADDLE_SUBSCRIPTION_GRACE_DAYS).date() + ): return sub # past subscription, user is considered not having a subscription = free plan else: diff --git a/tests/test_models.py b/tests/test_models.py index 208ec518..cc3c6b9f 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -16,6 +16,7 @@ from app.models import ( EnumE, Subscription, PlanEnum, + PADDLE_SUBSCRIPTION_GRACE_DAYS, ) from tests.utils import login, create_new_user @@ -272,14 +273,14 @@ def test_user_get_subscription_grace_period(flask_client): update_url="https://checkout.paddle.com/subscription/update?user=1234", subscription_id=str(random.random()), event_time=arrow.now(), - next_bill_date=arrow.now() - .shift(days=-14) - .date(), # the grace period is 14 days + next_bill_date=arrow.now().shift(days=-PADDLE_SUBSCRIPTION_GRACE_DAYS).date(), plan=PlanEnum.monthly, commit=True, ) assert user.get_subscription() is not None - sub.next_bill_date = arrow.now().shift(days=-15).date() + sub.next_bill_date = ( + arrow.now().shift(days=-(PADDLE_SUBSCRIPTION_GRACE_DAYS + 1)).date() + ) assert user.get_subscription() is None