summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--talermerchantdemos/blog/blog.py59
1 files changed, 27 insertions, 32 deletions
diff --git a/talermerchantdemos/blog/blog.py b/talermerchantdemos/blog/blog.py
index af4e95c..1268d6b 100644
--- a/talermerchantdemos/blog/blog.py
+++ b/talermerchantdemos/blog/blog.py
@@ -226,6 +226,7 @@ def article(article_name, lang=None, data=None):
if not session_id:
session_id = flask.session["session_id"] = str(uuid.uuid4())
+ order_id = None
##
# First-timer; generate order first.
if not order_id:
@@ -243,41 +244,35 @@ 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"]
- # 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)
- )
+ # 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,
- )
- 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
+ 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:
- 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
+ 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:
+ # Check if the customer came on this page via the
+ # re-purchase detection mechanism
+ ai = pay_status.get("already_paid_order_id")
+ au = pay_status.get("already_paid_fulfillment_url")
+ if ai is not None and au is not None:
+ response = flask.redirect(au)
+ response.set_cookie("order_id", ai, path=urllib.parse.quote(f"/essay/{article_name}"))
+ return response
# Redirect the browser to a page where the wallet can
# run the payment protocol.