mirror of
https://github.com/simple-login/app.git
synced 2024-09-28 20:51:29 +02:00
Handle subscription cancel directly
This commit is contained in:
parent
aea717eafc
commit
1acbf173ea
@ -45,11 +45,35 @@
|
|||||||
|
|
||||||
<div>
|
<div>
|
||||||
Don't want to protect your inbox anymore? <br>
|
Don't want to protect your inbox anymore? <br>
|
||||||
<a class="btn btn-warning" href="{{ sub.cancel_url }}"> Cancel subscription 😔 </a>
|
|
||||||
|
<form method="post">
|
||||||
|
<input type="hidden" name="form-name" value="cancel">
|
||||||
|
|
||||||
|
<span class="cancel btn btn-warning">
|
||||||
|
Cancel subscription <i class="fe fe-alert-triangle text-danger"></i>
|
||||||
|
</span>
|
||||||
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block script %}
|
||||||
|
<script>
|
||||||
|
|
||||||
|
$(".cancel").on("click", function (e) {
|
||||||
|
notie.confirm({
|
||||||
|
text: `This operation is irreversible, please confirm`,
|
||||||
|
cancelCallback: () => {
|
||||||
|
// nothing to do
|
||||||
|
},
|
||||||
|
submitCallback: () => {
|
||||||
|
$(this).closest("form").submit();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
@ -1,17 +1,38 @@
|
|||||||
from flask import render_template, flash, redirect, url_for
|
from flask import render_template, flash, redirect, url_for, request
|
||||||
from flask_login import login_required, current_user
|
from flask_login import login_required, current_user
|
||||||
|
|
||||||
from app.dashboard.base import dashboard_bp
|
from app.dashboard.base import dashboard_bp
|
||||||
|
from app.log import LOG
|
||||||
|
from app.models import Subscription
|
||||||
|
from app.extensions import db
|
||||||
|
from app.paddle_utils import cancel_subscription
|
||||||
|
|
||||||
|
|
||||||
@dashboard_bp.route("/billing", methods=["GET", "POST"])
|
@dashboard_bp.route("/billing", methods=["GET", "POST"])
|
||||||
@login_required
|
@login_required
|
||||||
def billing():
|
def billing():
|
||||||
# sanity check: make sure this page is only for user who has paddle subscription
|
# sanity check: make sure this page is only for user who has paddle subscription
|
||||||
sub = current_user.get_subscription()
|
sub: Subscription = current_user.get_subscription()
|
||||||
|
|
||||||
if not sub:
|
if not sub:
|
||||||
flash("You don't have any active subscription", "warning")
|
flash("You don't have any active subscription", "warning")
|
||||||
return redirect(url_for("dashboard.index"))
|
return redirect(url_for("dashboard.index"))
|
||||||
|
|
||||||
|
if request.method == "POST":
|
||||||
|
if request.form.get("form-name") == "cancel":
|
||||||
|
LOG.error(f"User {current_user} cancels their subscription")
|
||||||
|
success = cancel_subscription(sub.subscription_id)
|
||||||
|
|
||||||
|
if success:
|
||||||
|
sub.cancelled = True
|
||||||
|
db.session.commit()
|
||||||
|
flash("Your subscription has been canceled successfully", "success")
|
||||||
|
else:
|
||||||
|
flash(
|
||||||
|
"Something went wrong, sorry for the inconvenience. Please retry. We are already notified and will be on it asap",
|
||||||
|
"error",
|
||||||
|
)
|
||||||
|
|
||||||
|
return redirect(url_for("dashboard.billing"))
|
||||||
|
|
||||||
return render_template("dashboard/billing.html", sub=sub)
|
return render_template("dashboard/billing.html", sub=sub)
|
||||||
|
Loading…
Reference in New Issue
Block a user