get_subscription should only return *active* subscription.
This commit is contained in:
parent
86e5a44b89
commit
026fe4addd
|
@ -8,10 +8,10 @@ from app.dashboard.base import dashboard_bp
|
|||
@login_required
|
||||
def billing():
|
||||
# sanity check: make sure this page is only for user who has paddle subscription
|
||||
if not current_user.is_premium():
|
||||
flash("This page is for paid customer only", "warning")
|
||||
return redirect(url_for("dashboard.index"))
|
||||
|
||||
sub = current_user.get_subscription()
|
||||
|
||||
if not sub:
|
||||
flash("You don't have any active subscription", "warning")
|
||||
return redirect(url_for("dashboard.index"))
|
||||
|
||||
return render_template("dashboard/billing.html", sub=sub)
|
||||
|
|
|
@ -145,11 +145,6 @@ class User(db.Model, ModelMixin, UserMixin):
|
|||
"""user is premium if they have a active subscription"""
|
||||
sub: Subscription = self.get_subscription()
|
||||
if sub:
|
||||
if sub.cancelled:
|
||||
# user is premium until the next billing_date + 1
|
||||
return sub.next_bill_date >= arrow.now().shift(days=-1).date()
|
||||
|
||||
# subscription active, ie not cancelled
|
||||
return True
|
||||
|
||||
return False
|
||||
|
@ -217,8 +212,19 @@ class User(db.Model, ModelMixin, UserMixin):
|
|||
return "Free Plan"
|
||||
|
||||
def get_subscription(self):
|
||||
"""return *active* subscription
|
||||
TODO: support user unsubscribe and re-subscribe
|
||||
"""
|
||||
sub = Subscription.get_by(user_id=self.id)
|
||||
if sub and sub.cancelled:
|
||||
# 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
|
||||
return None
|
||||
else:
|
||||
return sub
|
||||
|
||||
|
||||
def verified_custom_domains(self):
|
||||
return CustomDomain.query.filter_by(user_id=self.id, verified=True).all()
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
</a>
|
||||
|
||||
<div class="dropdown-menu dropdown-menu-right dropdown-menu-arrow">
|
||||
{% if current_user.is_premium() %}
|
||||
{% if current_user.get_subscription() %}
|
||||
<a class="dropdown-item" href="{{ url_for('dashboard.billing') }}">
|
||||
<i class="dropdown-icon fe fe-dollar-sign"></i> Billing
|
||||
</a>
|
||||
|
|
Loading…
Reference in a new issue