summaryrefslogtreecommitdiff
path: root/talermerchantdemos/blog/blog.py
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-09-06 22:15:20 +0200
committerChristian Grothoff <christian@grothoff.org>2020-09-06 22:15:20 +0200
commit728c4bf11e13dc7a83d88e737b117cbbd4b97cf3 (patch)
tree0d59c3c88c4d63bc9ba84507a0595a36e1f73313 /talermerchantdemos/blog/blog.py
parent06c708def001b20b6e15d02c5224d835559e4f71 (diff)
downloadtaler-merchant-demos-728c4bf11e13dc7a83d88e737b117cbbd4b97cf3.tar.gz
taler-merchant-demos-728c4bf11e13dc7a83d88e737b117cbbd4b97cf3.tar.bz2
taler-merchant-demos-728c4bf11e13dc7a83d88e737b117cbbd4b97cf3.zip
add logic for repurchase detection, adjusting order_id if provided
Diffstat (limited to 'talermerchantdemos/blog/blog.py')
-rw-r--r--talermerchantdemos/blog/blog.py46
1 files 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.