gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-donations] branch master updated: url-based payments


From: gnunet
Subject: [GNUnet-SVN] [taler-donations] branch master updated: url-based payments
Date: Thu, 29 Aug 2019 19:09:39 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository donations.

The following commit(s) were added to refs/heads/master by this push:
     new e7c20a1  url-based payments
e7c20a1 is described below

commit e7c20a11fac21ab485b17feec81d0887be4cf5eb
Author: Florian Dold <address@hidden>
AuthorDate: Thu Aug 29 19:09:02 2019 +0200

    url-based payments
---
 talerdonations/donations/donations.py              | 26 +++++++-
 .../donations/templates/request_payment.html       | 69 ++++++++++++++++++++++
 2 files changed, 94 insertions(+), 1 deletion(-)

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 %}

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]