user can buy 1-year coupon

This commit is contained in:
Son 2021-11-22 16:30:27 +01:00
parent 2d9f8e83e6
commit 55ae61527d
2 changed files with 59 additions and 18 deletions

View File

@ -4,7 +4,7 @@ from flask_login import login_required, current_user
from flask_wtf import FlaskForm
from wtforms import StringField, validators
from app.config import ADMIN_EMAIL
from app.config import ADMIN_EMAIL, PADDLE_VENDOR_ID, PADDLE_COUPON_ID
from app.dashboard.base import dashboard_bp
from app.db import Session
from app.email_utils import send_email
@ -55,10 +55,6 @@ def coupon_route():
if coinbase_subscription and coinbase_subscription.is_active():
can_use_coupon = False
if not can_use_coupon:
flash("You already have another subscription.", "warning")
return redirect(url_for("dashboard.index"))
if coupon_form.validate_on_submit():
code = coupon_form.code.data
@ -112,4 +108,10 @@ def coupon_route():
else:
flash(f"Code *{code}* expired or invalid", "warning")
return render_template("dashboard/coupon.html", coupon_form=coupon_form)
return render_template(
"dashboard/coupon.html",
coupon_form=coupon_form,
PADDLE_VENDOR_ID=PADDLE_VENDOR_ID,
PADDLE_COUPON_ID=PADDLE_COUPON_ID,
can_use_coupon=can_use_coupon,
)

View File

@ -2,27 +2,66 @@
{% set active_page = "dashboard" %}
{% block head %}
<script src="https://cdn.paddle.com/paddle/paddle.js"></script>
<script>
if (window.Paddle === undefined) {
console.log("cannot load Paddle from CDN");
document.write('<script src="/static/vendor/paddle.js"><\/script>')
}
</script>
<style type="text/css">
html.mvc__a.mvc__lot.mvc__of.mvc__classes.mvc__to.mvc__increase.mvc__the.mvc__odds.mvc__of.mvc__winning.mvc__specificity, html.mvc__a.mvc__lot.mvc__of.mvc__classes.mvc__to.mvc__increase.mvc__the.mvc__odds.mvc__of.mvc__winning.mvc__specificity > body {
position: static;
}
</style>
{% endblock %}
{% block title %}
Coupon
{% endblock %}
{% block default_content %}
{% if can_use_coupon %}
<div class="card">
<div class="card-body">
<h1 class="h2">Coupon</h1>
<div class="mb-4">
Please enter the coupon here to upgrade your account or extend your current subscription.
</div>
<form method="post">
{{ coupon_form.csrf_token }}
{{ coupon_form.code(class="form-control", placeholder="Licence Code") }}
{{ render_field_errors(coupon_form.code) }}
<button class="btn btn-success mt-2">Apply</button>
</form>
</div>
</div>
{% endif %}
<div class="card">
<div class="card-body">
<h1 class="h2">Coupon</h1>
<div class="mb-4">
Please enter the coupon here to upgrade your account or extend your current subscription.
<h2>1-year coupon</h2>
<div class="mb-3">
You can buy a 1-year coupon that allows anyone to have the SimpleLogin premium for 1 year.
Can be an idea for a gift card :).
After the payment, the coupon will be sent to you by email.
</div>
<form method="post">
{{ coupon_form.csrf_token }}
{{ coupon_form.code(class="form-control", placeholder="Licence Code") }}
{{ render_field_errors(coupon_form.code) }}
<button class="btn btn-success mt-2">Apply</button>
</form>
<a href="#!" class="paddle_button btn btn-primary" data-product="{{ PADDLE_COUPON_ID }}">Buy 1-year SimpleLogin
coupon</a>
</div>
</div>
{% endblock %}
{% block script %}
<script type="text/javascript">
Paddle.Setup({vendor: {{PADDLE_VENDOR_ID}}});
</script>
{% endblock %}