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()
|
Base = declarative_base()
|
||||||
|
|
||||||
|
PADDLE_SUBSCRIPTION_GRACE_DAYS = 14
|
||||||
|
|
||||||
|
|
||||||
class TSVector(sa.types.TypeDecorator):
|
class TSVector(sa.types.TypeDecorator):
|
||||||
impl = TSVECTOR
|
impl = TSVECTOR
|
||||||
|
@ -752,8 +754,11 @@ class User(Base, ModelMixin, UserMixin, PasswordOracle):
|
||||||
|
|
||||||
if sub:
|
if sub:
|
||||||
# grace period is 14 days
|
# grace period is 14 days
|
||||||
# sub is active until the next billing_date + 14
|
# sub is active until the next billing_date + PADDLE_SUBSCRIPTION_GRACE_DAYS
|
||||||
if sub.next_bill_date >= arrow.now().shift(days=-14).date():
|
if (
|
||||||
|
sub.next_bill_date
|
||||||
|
>= arrow.now().shift(days=-PADDLE_SUBSCRIPTION_GRACE_DAYS).date()
|
||||||
|
):
|
||||||
return sub
|
return sub
|
||||||
# past subscription, user is considered not having a subscription = free plan
|
# past subscription, user is considered not having a subscription = free plan
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -16,6 +16,7 @@ from app.models import (
|
||||||
EnumE,
|
EnumE,
|
||||||
Subscription,
|
Subscription,
|
||||||
PlanEnum,
|
PlanEnum,
|
||||||
|
PADDLE_SUBSCRIPTION_GRACE_DAYS,
|
||||||
)
|
)
|
||||||
from tests.utils import login, create_new_user
|
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",
|
update_url="https://checkout.paddle.com/subscription/update?user=1234",
|
||||||
subscription_id=str(random.random()),
|
subscription_id=str(random.random()),
|
||||||
event_time=arrow.now(),
|
event_time=arrow.now(),
|
||||||
next_bill_date=arrow.now()
|
next_bill_date=arrow.now().shift(days=-PADDLE_SUBSCRIPTION_GRACE_DAYS).date(),
|
||||||
.shift(days=-14)
|
|
||||||
.date(), # the grace period is 14 days
|
|
||||||
plan=PlanEnum.monthly,
|
plan=PlanEnum.monthly,
|
||||||
commit=True,
|
commit=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert user.get_subscription() is not None
|
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
|
assert user.get_subscription() is None
|
||||||
|
|
Loading…
Reference in a new issue