create a constant for paddle grace days
This commit is contained in:
parent
2573c68e82
commit
d2fad44003
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue