diff --git a/app/dashboard/__init__.py b/app/dashboard/__init__.py
index ec7db995..8363aa5d 100644
--- a/app/dashboard/__init__.py
+++ b/app/dashboard/__init__.py
@@ -25,5 +25,4 @@ from .views import (
contact_detail,
setup_done,
batch_import,
- extend_subscription,
)
diff --git a/app/dashboard/templates/dashboard/pricing.html b/app/dashboard/templates/dashboard/pricing.html
index 21c64045..a8366939 100644
--- a/app/dashboard/templates/dashboard/pricing.html
+++ b/app/dashboard/templates/dashboard/pricing.html
@@ -65,7 +65,7 @@
@@ -100,16 +100,12 @@
Coinbase Commerce
- Only the yearly plan is supported.
+ Only the yearly plan is supported.
-
+
+ $30/year - Crypto
+
{% endif %}
diff --git a/app/dashboard/templates/dashboard/setting.html b/app/dashboard/templates/dashboard/setting.html
index 8d33608f..62850daa 100644
--- a/app/dashboard/templates/dashboard/setting.html
+++ b/app/dashboard/templates/dashboard/setting.html
@@ -53,7 +53,7 @@
({{ coinbase_sub.end_at.format("YYYY-MM-DD") }}).
You can extend your subscription on
-
+
Extend Subscription
diff --git a/app/dashboard/views/extend_subscription.py b/app/dashboard/views/extend_subscription.py
deleted file mode 100644
index e10920aa..00000000
--- a/app/dashboard/views/extend_subscription.py
+++ /dev/null
@@ -1,24 +0,0 @@
-from flask import render_template, flash, redirect, url_for
-from flask_login import login_required, current_user
-
-from app.config import COINBASE_CHECKOUT_ID
-from app.dashboard.base import dashboard_bp
-from app.models import CoinbaseSubscription
-
-
-@dashboard_bp.route("/extend_subscription", methods=["GET", "POST"])
-@login_required
-def extend_subscription_route():
- coinbase_subscription = CoinbaseSubscription.get_by(user_id=current_user.id)
- # this page is only for user who has an active coinbase subscription
- if not coinbase_subscription or not coinbase_subscription.is_active():
- flash("Unknown error, redirect to home page", "error")
- return redirect(url_for("dashboard.index"))
-
- coinbase_url = "https://commerce.coinbase.com/checkout/" + COINBASE_CHECKOUT_ID
-
- return render_template(
- "dashboard/extend_subscription.html",
- coinbase_subscription=coinbase_subscription,
- coinbase_url=coinbase_url,
- )
diff --git a/app/dashboard/views/pricing.py b/app/dashboard/views/pricing.py
index b99353fc..5cc6e98c 100644
--- a/app/dashboard/views/pricing.py
+++ b/app/dashboard/views/pricing.py
@@ -1,3 +1,4 @@
+from coinbase_commerce import Client
from flask import render_template, flash, redirect, url_for
from flask_login import login_required, current_user
@@ -6,9 +7,11 @@ from app.config import (
PADDLE_MONTHLY_PRODUCT_ID,
PADDLE_YEARLY_PRODUCT_ID,
URL,
- COINBASE_CHECKOUT_ID,
+ COINBASE_YEARLY_PRICE,
+ COINBASE_API_KEY,
)
from app.dashboard.base import dashboard_bp
+from app.log import LOG
@dashboard_bp.route("/pricing", methods=["GET", "POST"])
@@ -18,15 +21,12 @@ def pricing():
flash("You are already a premium user", "warning")
return redirect(url_for("dashboard.index"))
- coinbase_url = "https://commerce.coinbase.com/checkout/" + COINBASE_CHECKOUT_ID
-
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",
- coinbase_url=coinbase_url,
)
@@ -35,3 +35,19 @@ def pricing():
def subscription_success():
flash("Thanks so much for supporting SimpleLogin!", "success")
return redirect(url_for("dashboard.index"))
+
+
+@dashboard_bp.route("/coinbase_checkout")
+@login_required
+def coinbase_checkout_route():
+ client = Client(api_key=COINBASE_API_KEY)
+ charge = client.charge.create(
+ name="1 Year Premium Subscription",
+ local_price={"amount": str(COINBASE_YEARLY_PRICE), "currency": "USD"},
+ pricing_type="fixed_price",
+ metadata={"user_id": current_user.id},
+ )
+
+ LOG.d("Create coinbase charge %s", charge)
+
+ return redirect(charge["hosted_url"])
diff --git a/cron.py b/cron.py
index 3f3c045b..d7e99469 100644
--- a/cron.py
+++ b/cron.py
@@ -130,7 +130,7 @@ def notify_manual_sub_end():
),
)
- extend_subscription_url = URL + "/dashboard/extend_subscription"
+ extend_subscription_url = URL + "/dashboard/coinbase_checkout"
for coinbase_subscription in CoinbaseSubscription.query.all():
need_reminder = False
if (