2020-12-14 11:34:59 +01:00
|
|
|
from coinbase_commerce import Client
|
2019-11-14 15:05:20 +01:00
|
|
|
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,
|
2020-12-14 11:34:59 +01:00
|
|
|
COINBASE_YEARLY_PRICE,
|
|
|
|
COINBASE_API_KEY,
|
2019-11-14 15:05:20 +01:00
|
|
|
)
|
|
|
|
from app.dashboard.base import dashboard_bp
|
2020-12-14 11:34:59 +01:00
|
|
|
from app.log import LOG
|
2019-11-14 15:05:20 +01:00
|
|
|
|
|
|
|
|
|
|
|
@dashboard_bp.route("/pricing", methods=["GET", "POST"])
|
|
|
|
@login_required
|
|
|
|
def pricing():
|
2020-04-13 20:50:48 +02:00
|
|
|
if not current_user.can_upgrade():
|
2019-11-14 15:05:20 +01:00
|
|
|
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"))
|
2020-12-14 11:34:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
@dashboard_bp.route("/coinbase_checkout")
|
|
|
|
@login_required
|
|
|
|
def coinbase_checkout_route():
|
|
|
|
client = Client(api_key=COINBASE_API_KEY)
|
|
|
|
charge = client.charge.create(
|
2020-12-14 11:52:35 +01:00
|
|
|
name="1 Year SimpleLogin Premium Subscription",
|
2020-12-14 11:34:59 +01:00
|
|
|
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"])
|