From 3492935f95b3b629e5e3aa0db6556c82e79448cf Mon Sep 17 00:00:00 2001 From: Son NK Date: Thu, 5 Mar 2020 09:13:28 +0100 Subject: [PATCH] Canceled user can upgrade again: the payment method is changed immediately though --- .../templates/dashboard/billing.html | 26 +++++++++++---- app/models.py | 32 +++++++++++++++++-- server.py | 4 +-- templates/header.html | 6 +++- 4 files changed, 56 insertions(+), 12 deletions(-) diff --git a/app/dashboard/templates/dashboard/billing.html b/app/dashboard/templates/dashboard/billing.html index 66e42fe8..0dfc3a72 100644 --- a/app/dashboard/templates/dashboard/billing.html +++ b/app/dashboard/templates/dashboard/billing.html @@ -11,19 +11,31 @@

Billing

-

- You are on the {{ sub.plan_name() }} plan. Thank you very much for supporting - SimpleLogin. 🙌 -

- {% if sub.cancelled %}

- Sad to see you go 😢. Your subscription ends on - {{ sub.next_bill_date.year }}-{{ sub.next_bill_date.month}}-{{ sub.next_bill_date.day }} + You are on the {{ sub.plan_name() }} plan.
+ You have canceled your subscription and it will end on {{current_user.next_bill_date()}} ({{ sub.next_bill_date | dt }}).

+
+

+ If you change your mind you can subscribe again to SimpleLogin but please note that this will be a completely + new subscription and + your payment method will be charged immediately. +
+ + We are going to send you an email by the end of the subscription so maybe you can upgrade at that time. +
+ Re-subscribe +

+ {% else %} +

+ You are on the {{ sub.plan_name() }} plan. Thank you very much for supporting + SimpleLogin. 🙌 +

+
Click here to update billing information on Paddle, our payment partner:
Update billing information diff --git a/app/models.py b/app/models.py index 6b884102..8765fdb0 100644 --- a/app/models.py +++ b/app/models.py @@ -195,7 +195,34 @@ class User(db.Model, ModelMixin, UserMixin): return False def should_upgrade(self): - return not self.lifetime_or_active_subscription() + if self.lifetime_or_active_subscription(): + # user who has canceled can also re-subscribe + sub: Subscription = self.get_subscription() + if sub and sub.cancelled: + return True + + return False + + return True + + def next_bill_date(self) -> str: + sub: Subscription = self.get_subscription() + if sub: + return sub.next_bill_date.strftime("%Y-%m-%d") + + LOG.error( + f"next_bill_date() should be called only on user with active subscription. User {self}" + ) + return "" + + def is_cancel(self) -> bool: + """User has canceled their subscription but the subscription is still active, + i.e. next_bill_date > now""" + sub: Subscription = self.get_subscription() + if sub and sub.cancelled: + return True + + return False def is_premium(self) -> bool: """ @@ -273,7 +300,8 @@ class User(db.Model, ModelMixin, UserMixin): # sub is active until the next billing_date + 1 if sub.next_bill_date >= arrow.now().shift(days=-1).date(): return sub - else: # past subscription, user is considered not having a subscription + # past subscription, user is considered not having a subscription = free plan + else: return None else: return sub diff --git a/server.py b/server.py index 0dedcd7b..f57adeb5 100644 --- a/server.py +++ b/server.py @@ -349,7 +349,7 @@ def setup_paddle_callback(app: Flask): sub = Subscription.get_by(user_id=user.id) if not sub: - LOG.d("create a new sub") + LOG.d(f"create a new Subscription for user {user}") Subscription.create( user_id=user.id, cancel_url=request.form.get("cancel_url"), @@ -362,7 +362,7 @@ def setup_paddle_callback(app: Flask): plan=plan, ) else: - LOG.d("update existing sub %s", sub) + LOG.d(f"Update an existing Subscription for user {user}") sub.cancel_url = request.form.get("cancel_url") sub.update_url = request.form.get("update_url") sub.subscription_id = request.form.get("subscription_id") diff --git a/templates/header.html b/templates/header.html index ced588ad..2ca9e8b6 100644 --- a/templates/header.html +++ b/templates/header.html @@ -28,7 +28,11 @@ {% if current_user.in_trial() %} Trial ends {{ current_user.trial_end|dt }} {% elif current_user.lifetime_or_active_subscription() %} - Premium + Premium + {% if current_user.is_cancel() %} + until {{ current_user.next_bill_date() }} + {% endif %} + {% endif %}