diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-08-29 19:09:02 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-08-29 19:09:30 +0200 |
commit | e7c20a11fac21ab485b17feec81d0887be4cf5eb (patch) | |
tree | d4d93e383050d895dca8554347bb1d7da12c744a | |
parent | 9c282aa69a4d25f186e591a075b0f2830b5ec45a (diff) | |
download | donations-e7c20a11fac21ab485b17feec81d0887be4cf5eb.tar.gz donations-e7c20a11fac21ab485b17feec81d0887be4cf5eb.tar.bz2 donations-e7c20a11fac21ab485b17feec81d0887be4cf5eb.zip |
url-based payments
-rw-r--r-- | talerdonations/donations/donations.py | 26 | ||||
-rw-r--r-- | talerdonations/donations/templates/request_payment.html | 69 |
2 files changed, 94 insertions, 1 deletions
diff --git a/talerdonations/donations/donations.py b/talerdonations/donations/donations.py index 220fbb7..06c6617 100644 --- a/talerdonations/donations/donations.py +++ b/talerdonations/donations/donations.py @@ -246,6 +246,16 @@ def donate(): ## +# This endpoint is used by the payment request page +# to check if the payment has been completed via the QR code. +@app.route("/check-status/<order_id>") +def check_status(order_id, session_id): + pay_params = dict( instance=INSTANCE, order_id=order_id) + pay_status = backend_get("check-payment", pay_params) + return flask.jsonify(paid=pay_status["paid"]) + + +## # Serve the fulfillment page. # # @param receiver the donation receiver name, that should @@ -260,7 +270,21 @@ def fulfillment(receiver): pay_status = backend_get("check-payment", pay_params) if pay_status.get("payment_redirect_url"): - return flask.redirect(pay_status["payment_redirect_url"]) + taler_pay_uri = pay_status["taler_pay_uri"] + qrcode_svg = get_qrcode_svg(taler_pay_uri) + check_status_url_enc = urllib.parse.quote( + flask.url_for("check_status", order_id=order_id) + ) + content = flask.render_template( + "templates/request_payment.html", + article_name=article_name, + taler_pay_uri=taler_pay_uri, + qrcode_svg=qrcode_svg, + check_status_url_enc=check_status_url_enc + ) + headers = {"Taler": taler_pay_uri} + resp = flask.Response(content, status=402, headers=headers) + return resp if pay_status.get("paid"): extra = pay_status["contract_terms"]["extra"] diff --git a/talerdonations/donations/templates/request_payment.html b/talerdonations/donations/templates/request_payment.html new file mode 100644 index 0000000..6e050d0 --- /dev/null +++ b/talerdonations/donations/templates/request_payment.html @@ -0,0 +1,69 @@ +{% extends "templates/base.html" %} + + +{% block meta %} +<noscript> + <meta http-equiv="refresh" content="1"> +</noscript> +{% endblock meta %} + + +{% block scripts %} +<script> + let checkUrl = decodeURIComponent("{{ check_status_url_enc }}"); + let delayMs = 500; + function check() { + let req = new XMLHttpRequest(); + req.onreadystatechange = function () { + if (req.readyState === XMLHttpRequest.DONE) { + if (req.status === 200) { + try { + let resp = JSON.parse(req.responseText); + if (resp.paid) { + document.location.reload(true); + } + } catch (e) { + console.error("could not parse response:", e); + } + } + setTimeout(check, delayMs); + } + }; + req.onerror = function () { + setTimeout(check, delayMs); + } + req.open("GET", checkUrl); + req.send(); + } + + setTimeout(check, delayMs); +</script> +{% endblock scripts %} + + +{% block main %} + +<h1>Payment Required</h1> + +<div class="taler-installed-hide"> + <p> + Looks like your browser doesn't support GNU Taler payments. You can try + installing a <a href="https://taler.net/en/wallet.html">wallet browser extension</a>. + </p> +</div> + +<div> + + <p> + You can use this QR code to pay with your mobile wallet: + </p> + + {{ qrcode_svg | safe }} + + <p> + Click <a href="{{ taler_pay_uri }}">this link</a> to open your system's Taler wallet if it exists. + </p> + +</div> + +{% endblock main %} |