send a reminder when a coinbase subscription is ending soon

This commit is contained in:
Son NK 2020-12-13 19:18:58 +01:00
parent b00841f679
commit 43a021dd88
4 changed files with 82 additions and 1 deletions

39
cron.py
View file

@ -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"""

View file

@ -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 %}

View file

@ -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
View 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()