send a reminder when a coinbase subscription is ending soon
This commit is contained in:
parent
b00841f679
commit
43a021dd88
39
cron.py
39
cron.py
|
@ -42,6 +42,7 @@ from app.models import (
|
|||
Mailbox,
|
||||
Monitoring,
|
||||
Contact,
|
||||
CoinbaseSubscription,
|
||||
)
|
||||
from server import create_app
|
||||
|
||||
|
@ -114,7 +115,7 @@ def notify_manual_sub_end():
|
|||
LOG.debug("Remind user %s that their manual sub is ending soon", user)
|
||||
send_email(
|
||||
user.email,
|
||||
f"Your trial will end soon {user.name}",
|
||||
f"Your subscription will end soon {user.name}",
|
||||
render(
|
||||
"transactional/manual-subscription-end.txt",
|
||||
name=user.name,
|
||||
|
@ -129,6 +130,42 @@ def notify_manual_sub_end():
|
|||
),
|
||||
)
|
||||
|
||||
extend_subscription_url = URL + "/dashboard/extend_subscription"
|
||||
for coinbase_subscription in CoinbaseSubscription.query.all():
|
||||
need_reminder = False
|
||||
if (
|
||||
arrow.now().shift(days=14)
|
||||
> coinbase_subscription.end_at
|
||||
> arrow.now().shift(days=13)
|
||||
):
|
||||
need_reminder = True
|
||||
elif (
|
||||
arrow.now().shift(days=4)
|
||||
> coinbase_subscription.end_at
|
||||
> arrow.now().shift(days=3)
|
||||
):
|
||||
need_reminder = True
|
||||
|
||||
if need_reminder:
|
||||
user = coinbase_subscription.user
|
||||
LOG.debug(
|
||||
"Remind user %s that their coinbase subscription is ending soon", user
|
||||
)
|
||||
send_email(
|
||||
user.email,
|
||||
f"Your SimpleLogin subscription will end soon",
|
||||
render(
|
||||
"transactional/coinbase/reminder-subscription.txt",
|
||||
coinbase_subscription=coinbase_subscription,
|
||||
extend_subscription_url=extend_subscription_url,
|
||||
),
|
||||
render(
|
||||
"transactional/coinbase/reminder-subscription.html",
|
||||
coinbase_subscription=coinbase_subscription,
|
||||
extend_subscription_url=extend_subscription_url,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def poll_apple_subscription():
|
||||
"""Poll Apple API to update AppleSubscription"""
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
{% call text() %}
|
||||
<h1>
|
||||
Your subscription is ending soon.
|
||||
</h1>
|
||||
{% endcall %}
|
||||
|
||||
{% call text() %}
|
||||
Your subscription ends on
|
||||
<b>{{ coinbase_subscription.end_at.format("YYYY-MM-DD") }}</b>
|
||||
{% endcall %}
|
||||
|
||||
{{ render_button("Extend your subscription", extend_subscription_url) }}
|
||||
|
||||
{{ render_text('Best, <br />SimpleLogin Team.') }}
|
||||
{% endblock %}
|
|
@ -0,0 +1,7 @@
|
|||
Your subscription ends on {{ coinbase_subscription.end_at.format("YYYY-MM-DD") }}
|
||||
|
||||
You can extend your subscription on
|
||||
{{ extend_subscription_url }}
|
||||
|
||||
Best,
|
||||
SimpleLogin team.
|
19
tests/test_cron.py
Normal file
19
tests/test_cron.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
import arrow
|
||||
|
||||
from app.models import User, CoinbaseSubscription
|
||||
from cron import notify_manual_sub_end
|
||||
|
||||
|
||||
def test_notify_manual_sub_end(flask_client):
|
||||
user = User.create(
|
||||
email="a@b.c",
|
||||
password="password",
|
||||
name="Test User",
|
||||
activated=True,
|
||||
)
|
||||
|
||||
cb = CoinbaseSubscription.create(
|
||||
user_id=user.id, end_at=arrow.now().shift(days=13, hours=2), commit=True
|
||||
)
|
||||
|
||||
notify_manual_sub_end()
|
Loading…
Reference in a new issue