Canceled user can upgrade again: the payment method is changed immediately though

This commit is contained in:
Son NK 2020-03-05 09:13:28 +01:00
parent 83d32244a5
commit 3492935f95
4 changed files with 56 additions and 12 deletions

View File

@ -11,19 +11,31 @@
<div class="bg-white p-6" style="max-width: 60em; margin: auto">
<h1 class="h3 mb-5"> Billing </h1>
<p>
You are on the <b>{{ sub.plan_name() }}</b> plan. Thank you very much for supporting
SimpleLogin. 🙌
</p>
{% if sub.cancelled %}
<p>
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 <b>{{ sub.plan_name() }}</b> plan. <br>
You have canceled your subscription and it will end on {{current_user.next_bill_date()}}
({{ sub.next_bill_date | dt }}).
</p>
<hr>
<p>
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 <b>immediately</b>.
<br>
We are going to send you an email by the end of the subscription so maybe you can upgrade at that time.
<br>
<a href="{{ url_for('dashboard.pricing') }}" class="btn btn-primary mt-2">Re-subscribe</a>
</p>
{% else %}
<p>
You are on the <b>{{ sub.plan_name() }}</b> plan. Thank you very much for supporting
SimpleLogin. 🙌
</p>
<div class="mt-3">
Click here to update billing information on Paddle, our payment partner: <br>
<a class="btn btn-success" href="{{ sub.update_url }}"> Update billing information </a>

View File

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

View File

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

View File

@ -28,7 +28,11 @@
{% if current_user.in_trial() %}
<small class="text-success d-block mt-1">Trial ends {{ current_user.trial_end|dt }}</small>
{% elif current_user.lifetime_or_active_subscription() %}
<small class="text-success d-block mt-1">Premium</small>
<small class="text-success d-block mt-1">Premium
{% if current_user.is_cancel() %}
until {{ current_user.next_bill_date() }}
{% endif %}
</small>
{% endif %}
</span>