[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-merchant-demos] branch master updated: hide refund (#5865)
From: |
gnunet |
Subject: |
[taler-taler-merchant-demos] branch master updated: hide refund (#5865) |
Date: |
Tue, 08 Sep 2020 17:18:51 +0200 |
This is an automated email from the git hooks/post-receive script.
ms pushed a commit to branch master
in repository taler-merchant-demos.
The following commit(s) were added to refs/heads/master by this push:
new 5766759 hide refund (#5865)
5766759 is described below
commit 57667591de3ce0f8b758dfd85b7475405602ce63
Author: MS <ms@taler.net>
AuthorDate: Tue Sep 8 17:18:45 2020 +0200
hide refund (#5865)
---
talermerchantdemos/blog/blog.py | 43 +++++++++++++++++++---
.../blog/templates/article_frame.html | 3 ++
2 files changed, 40 insertions(+), 6 deletions(-)
diff --git a/talermerchantdemos/blog/blog.py b/talermerchantdemos/blog/blog.py
index e5068ee..a1db789 100644
--- a/talermerchantdemos/blog/blog.py
+++ b/talermerchantdemos/blog/blog.py
@@ -31,6 +31,24 @@ from taler.util.talerconfig import TalerConfig,
ConfigurationError
from ..blog.content import ARTICLES, get_article_file, get_image_file
from talermerchantdemos.httpcommon import backend_get, backend_post,
fallback_404
+class Deadline:
+ def __init__(self, value):
+ self.value = value
+ def isExpired(self):
+ if self.value == "never":
+ return False
+ now = int(round(time.time()) * 1000)
+ return now > self.value
+
+def refundable(pay_status):
+ refunded = pay_status.get("refunded")
+ refund_deadline = pay_status.get("contract_terms",
{}).get("refund_deadline")
+ assert(refunded != None and refund_deadline)
+ rd = Deadline(refund_deadline)
+ if not refunded and not rd.isExpired()
+ return True
+ return False
+
if not sys.version_info.major == 3 and sys.version_info.minor >= 6:
print("Python 3.6 or higher is required.")
print(
@@ -40,7 +58,6 @@ if not sys.version_info.major == 3 and sys.version_info.minor
>= 6:
)
sys.exit(1)
-
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
app = flask.Flask(
__name__, template_folder=BASE_DIR, static_folder=BASE_DIR + "/../static/"
@@ -122,6 +139,11 @@ def confirm_refund(order_id):
400, message="can't refund unpaid article",
)
article_name = pay_status["contract_terms"]["extra"]["article_name"]
+
+ ## FIXME: here goes #refund-checks.
+ """
+ if not refunded and < deadline, allow statement below.
+ """
return flask.render_template(
"templates/confirm_refund.html", article_name=article_name,
order_id=order_id
)
@@ -148,10 +170,15 @@ def refund(order_id):
BACKEND_URL, f"private/orders/{order_id}",
params=dict(session_id=session_id)
)
order_status = pay_status.get("order_status")
+
if order_status != "paid":
err_abort(
402, message="You did not pay for this article (nice try!)",
json=pay_status
)
+ if not refundable(pay_status):
+ err_abort(
+ 403, message="Item not refundable (anymore)", json=pay_status
+ )
refund_spec = dict(reason="Demo reimbursement", refund=ARTICLE_AMOUNT)
resp = backend_post(BACKEND_URL, f"private/orders/{order_id}/refund",
refund_spec)
return flask.redirect(pay_status["order_status_url"])
@@ -170,7 +197,7 @@ def refund(order_id):
# - 404: supplemental @a data not found.
# In the successful case, a response object carrying the
# article in it will be returned.
-def render_article(article_name, data, order_id):
+def render_article(article_name, data, order_id, refundable):
article_info = ARTICLES.get(article_name)
if article_info is None:
m = "Internal error: Files for article ({}) not
found.".format(article_name)
@@ -188,9 +215,9 @@ def render_article(article_name, data, order_id):
article_file=get_article_file(article_info),
article_name=article_name,
order_id=order_id,
+ refundable=refundable
)
-
##
# Trigger a article purchase. The logic follows the main steps:
#
@@ -241,9 +268,8 @@ def article(article_name, data=None):
pay_status = backend_get(
BACKEND_URL, f"private/orders/{order_id}",
params=dict(session_id=session_id)
)
-
+ # not refundable =>! not viewable!
order_status = pay_status.get("order_status")
-
if order_status == "paid":
refunded = pay_status["refunded"]
if refunded:
@@ -252,7 +278,7 @@ def article(article_name, data=None):
article_name=article_name,
order_id=order_id,
)
- return render_article(article_name, data, order_id)
+ return render_article(article_name, data, order_id,
refundable(pay_status))
# Check if the customer came on this page via the
# re-purchase detection mechanism
@@ -273,6 +299,11 @@ def article(article_name, data=None):
)
return response
+@app.errorhandler(500)
+def handler(e):
+ return flask.render_template(
+ "templates/error.html", message="Internal server error")
+
@app.errorhandler(404)
def handler(e):
return flask.render_template(
diff --git a/talermerchantdemos/blog/templates/article_frame.html
b/talermerchantdemos/blog/templates/article_frame.html
index 1efc0d1..a5050d3 100644
--- a/talermerchantdemos/blog/templates/article_frame.html
+++ b/talermerchantdemos/blog/templates/article_frame.html
@@ -2,9 +2,12 @@
{% block main %}
{% include "articles/" + article_file %}
+{% if refundable %}
<hr>
<p>
You don't like this article? <a href="{{ url_for('confirm_refund',
order_id=order_id) }}">Get a refund</a> within
the first hour after buying it.
</p>
+{% endif %}
+
{% endblock main %}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-taler-merchant-demos] branch master updated: hide refund (#5865),
gnunet <=