gnunet-svn
[Top][All Lists]
Advanced

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

[taler-taler-merchant-demos] 14/18: add logic for repurchase detection,


From: gnunet
Subject: [taler-taler-merchant-demos] 14/18: add logic for repurchase detection, adjusting order_id if provided
Date: Sat, 10 Oct 2020 22:55:48 +0200

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

grothoff pushed a commit to branch master
in repository taler-merchant-demos.

commit 728c4bf11e13dc7a83d88e737b117cbbd4b97cf3
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun Sep 6 22:15:20 2020 +0200

    add logic for repurchase detection, adjusting order_id if provided
---
 talermerchantdemos/blog/blog.py | 46 ++++++++++++++++++++++++++++-------------
 1 file changed, 32 insertions(+), 14 deletions(-)

diff --git a/talermerchantdemos/blog/blog.py b/talermerchantdemos/blog/blog.py
index 37d7c20..af4e95c 100644
--- a/talermerchantdemos/blog/blog.py
+++ b/talermerchantdemos/blog/blog.py
@@ -243,23 +243,41 @@ def article(article_name, lang=None, data=None):
         order_resp = backend_post(BACKEND_URL, "private/orders", 
dict(order=order))
         order_id = order_resp["order_id"]
 
-    # Ask the backend for the status of the payment
-    pay_status = backend_get(
-        BACKEND_URL, f"private/orders/{order_id}", 
params=dict(session_id=session_id)
-    )
+    # We run this code twice, 2nd time in case repurchase detection gave us
+    # a new order_id.
+    for retries in range(0,2):
+        # Ask the backend for the status of the payment
+        pay_status = backend_get(
+            BACKEND_URL, f"private/orders/{order_id}", 
params=dict(session_id=session_id)
+        )
 
-    order_status = pay_status.get("order_status")
+        order_status = pay_status.get("order_status")
 
-    if order_status == "paid":
-        refunded = pay_status["refunded"]
-        if refunded:
-            return flask.render_template(
-                "templates/article_refunded.html",
-                article_name=article_name,
-                order_id=order_id,
-            )
+        if order_status == "paid":
+            refunded = pay_status["refunded"]
+            if refunded:
+                return flask.render_template(
+                    "templates/article_refunded.html",
+                    article_name=article_name,
+                    order_id=order_id,
+                )
+            else:
+                response = render_article(article_name, data, order_id)
+                response.set_cookie("order_id", order_id, 
path=urllib.parse.quote(f"/essay/{article_name}"))
+                response.set_cookie("order_id", order_id, 
path=urllib.parse.quote(f"/{lang}/essay/{article_name}"))
+                return response
         else:
-            return render_article(article_name, data, order_id)
+            if "already_paid_order_id" in pay_status:
+                order_id = pay_status.get("already_paid_order_id")
+                print ("Already paid: " + order_id);
+                # retry (but only once)
+                continue
+            else:
+                print ("Not yet paid paid: " + str(pay_status))
+
+
+        # Give up trying, order is unpaid
+        break
 
     # Redirect the browser to a page where the wallet can
     # run the payment protocol.

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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