From 4a56d2eef5307b2d803da81574ae40d1917efc32 Mon Sep 17 00:00:00 2001 From: Son NK Date: Thu, 14 Nov 2019 15:05:20 +0100 Subject: [PATCH] add billing and pricing page --- app/config.py | 7 ++- app/dashboard/__init__.py | 2 +- .../templates/dashboard/billing.html | 46 ++++++++++++++ .../templates/dashboard/pricing.html | 63 +++++++++++++++++++ app/dashboard/views/billing.py | 17 +++++ app/dashboard/views/pricing.py | 34 ++++++++++ templates/header.html | 7 +++ 7 files changed, 174 insertions(+), 2 deletions(-) create mode 100644 app/dashboard/templates/dashboard/billing.html create mode 100644 app/dashboard/templates/dashboard/pricing.html create mode 100644 app/dashboard/views/billing.py create mode 100644 app/dashboard/views/pricing.py diff --git a/app/config.py b/app/config.py index e60ffdd6..e713a8d5 100644 --- a/app/config.py +++ b/app/config.py @@ -65,6 +65,11 @@ STRIPE_API = os.environ["STRIPE_API"] # Stripe public key STRIPE_SECRET_KEY = os.environ["STRIPE_SECRET_KEY"] STRIPE_YEARLY_PLAN = os.environ["STRIPE_YEARLY_PLAN"] +# Paddle TODO: put into config file +PADDLE_VENDOR_ID = int(os.environ["PADDLE_VENDOR_ID"]) +PADDLE_MONTHLY_PRODUCT_ID = int(os.environ["PADDLE_MONTHLY_PRODUCT_ID"]) +PADDLE_YEARLY_PRODUCT_ID = int(os.environ["PADDLE_YEARLY_PRODUCT_ID"]) + # OpenID keys, used to sign id_token OPENID_PRIVATE_KEY_PATH = get_abs_path(os.environ["OPENID_PRIVATE_KEY_PATH"]) OPENID_PUBLIC_KEY_PATH = get_abs_path(os.environ["OPENID_PUBLIC_KEY_PATH"]) @@ -88,4 +93,4 @@ FACEBOOK_CLIENT_SECRET = os.environ["FACEBOOK_CLIENT_SECRET"] AVATAR_URL_EXPIRATION = 3600 * 24 * 7 # 1h*24h/d*7d=1week # session key -HIGHLIGHT_GEN_EMAIL_ID = "highlight_gen_email_id" \ No newline at end of file +HIGHLIGHT_GEN_EMAIL_ID = "highlight_gen_email_id" diff --git a/app/dashboard/__init__.py b/app/dashboard/__init__.py index 9369862c..6aea4049 100644 --- a/app/dashboard/__init__.py +++ b/app/dashboard/__init__.py @@ -1 +1 @@ -from .views import index, pricing, setting, custom_alias +from .views import index, pricing, setting, custom_alias, billing diff --git a/app/dashboard/templates/dashboard/billing.html b/app/dashboard/templates/dashboard/billing.html new file mode 100644 index 00000000..2c4ba5dc --- /dev/null +++ b/app/dashboard/templates/dashboard/billing.html @@ -0,0 +1,46 @@ +{% extends 'default.html' %} + +{% set active_page = "dashboard" %} + +{% block title %} + Billing +{% endblock %} + +{% block head %} +{% endblock %} + +{% block default_content %} +
+
+

Billing

+ +

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

+ + {% if sub.cancelled %} +

+ Sad to see you go 😢. Your subscription ends {{ current_user.get_subscription().next_bill_date | dt }}. +

+ + {% else %} +
+ Click here to update billing information on Paddle, our payment partner:
+ Update billing information +
+ +
+ +
+ Don't want to protect your inbox anymore?
+ Cancel subscription 😔 +
+ {% endif %} + +
+ +
+ + + +{% endblock %} \ No newline at end of file diff --git a/app/dashboard/templates/dashboard/pricing.html b/app/dashboard/templates/dashboard/pricing.html new file mode 100644 index 00000000..c27f0403 --- /dev/null +++ b/app/dashboard/templates/dashboard/pricing.html @@ -0,0 +1,63 @@ +{% extends 'default.html' %} + +{% set active_page = "dashboard" %} + +{% block title %} + Pricing +{% endblock %} + +{% block head %} +{% endblock %} + +{% block default_content %} +
+
+
+
+
Premium
+
    +
  • Unlimited Alias
  • +
  • Custom Alias
  • +
  • Custom email domain
  • +
  • + Support us and our application partners +
  • +
+
+
+
+ +
+
+ 🔐 Secure payments by Paddle +
+ +
+ + + + +
+
+ + + + + +{% endblock %} \ No newline at end of file diff --git a/app/dashboard/views/billing.py b/app/dashboard/views/billing.py new file mode 100644 index 00000000..65ce62cd --- /dev/null +++ b/app/dashboard/views/billing.py @@ -0,0 +1,17 @@ +from flask import render_template, flash, redirect, url_for +from flask_login import login_required, current_user + +from app.dashboard.base import dashboard_bp + + +@dashboard_bp.route("/billing", methods=["GET", "POST"]) +@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() + + return render_template("dashboard/billing.html", sub=sub) diff --git a/app/dashboard/views/pricing.py b/app/dashboard/views/pricing.py new file mode 100644 index 00000000..d29891bc --- /dev/null +++ b/app/dashboard/views/pricing.py @@ -0,0 +1,34 @@ +from flask import render_template, flash, redirect, url_for +from flask_login import login_required, current_user + +from app.config import ( + PADDLE_VENDOR_ID, + PADDLE_MONTHLY_PRODUCT_ID, + PADDLE_YEARLY_PRODUCT_ID, + URL, +) +from app.dashboard.base import dashboard_bp + + +@dashboard_bp.route("/pricing", methods=["GET", "POST"]) +@login_required +def pricing(): + # sanity check: make sure this page is only for free user + if current_user.is_premium(): + flash("You are already a premium user", "warning") + return redirect(url_for("dashboard.index")) + + return render_template( + "dashboard/pricing.html", + PADDLE_VENDOR_ID=PADDLE_VENDOR_ID, + PADDLE_MONTHLY_PRODUCT_ID=PADDLE_MONTHLY_PRODUCT_ID, + PADDLE_YEARLY_PRODUCT_ID=PADDLE_YEARLY_PRODUCT_ID, + success_url=URL + "/dashboard/subscription_success", + ) + + +@dashboard_bp.route("/subscription_success") +@login_required +def subscription_success(): + flash("Thanks so much for supporting SimpleLogin!", "success") + return redirect(url_for("dashboard.index")) diff --git a/templates/header.html b/templates/header.html index eead08cb..473e1753 100644 --- a/templates/header.html +++ b/templates/header.html @@ -43,10 +43,17 @@ {# #} {# Become Partner/Developer#} {# #} + + {% if current_user.is_premium() %} + + Billing + + {% endif %} Sign out +