gnunet-svn
[Top][All Lists]
Advanced

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

[taler-taler-merchant-demos] branch master updated: formatting, merchant


From: gnunet
Subject: [taler-taler-merchant-demos] branch master updated: formatting, merchant API change
Date: Thu, 30 Jul 2020 14:07:49 +0200

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

dold 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 8574d88  formatting, merchant API change
8574d88 is described below

commit 8574d8848a67680fc65b6e7cc0969cd83e8ba9fc
Author: Florian Dold <florian.dold@gmail.com>
AuthorDate: Thu Jul 30 17:37:27 2020 +0530

    formatting, merchant API change
---
 talermerchantdemos/blog/blog.py | 69 ++++++++++++++++-------------------------
 1 file changed, 26 insertions(+), 43 deletions(-)

diff --git a/talermerchantdemos/blog/blog.py b/talermerchantdemos/blog/blog.py
index cde9006..4b1545f 100644
--- a/talermerchantdemos/blog/blog.py
+++ b/talermerchantdemos/blog/blog.py
@@ -36,7 +36,7 @@ from talermerchantdemos.httpcommon import backend_get, 
backend_post
 
 BASE_DIR = os.path.dirname(os.path.abspath(__file__))
 app = flask.Flask(__name__, template_folder=BASE_DIR)
-app.secret_key = base64.b64encode(os.urandom(64)).decode('utf-8')
+app.secret_key = base64.b64encode(os.urandom(64)).decode("utf-8")
 
 LOGGER = logging.getLogger(__name__)
 TC = TalerConfig.from_env()
@@ -59,6 +59,7 @@ def utility_processor():
     # These helpers will be available in templates
     def env(name, default=None):
         return os.environ.get(name, default)
+
     return dict(env=env)
 
 
@@ -71,6 +72,7 @@ def err_abort(abort_status_code, **params):
     t = flask.render_template("templates/error.html", **params)
     flask.abort(flask.make_response(t, abort_status_code))
 
+
 ##
 # "Fallback" exception handler to capture all the unmanaged errors.
 #
@@ -80,11 +82,10 @@ def err_abort(abort_status_code, **params):
 @app.errorhandler(Exception)
 def internal_error(e):
     return flask.render_template(
-        "templates/error.html",
-        message="Internal error",
-        stack=traceback.format_exc()
+        "templates/error.html", message="Internal error", 
stack=traceback.format_exc()
     )
 
+
 ##
 # Serve the main index page.
 #
@@ -92,9 +93,7 @@ def internal_error(e):
 @app.route("/")
 def index():
     return flask.render_template(
-        "templates/index.html",
-        merchant_currency=CURRENCY,
-        articles=ARTICLES.values()
+        "templates/index.html", merchant_currency=CURRENCY, 
articles=ARTICLES.values()
     )
 
 
@@ -115,14 +114,12 @@ def confirm_refund(order_id):
     pay_status = backend_get(BACKEND_URL, "check-payment", pay_params)
     if not pay_status.get("paid"):
         err_abort(
-            400,
-            message="can't refund unpaid article",
+            400, message="can't refund unpaid article",
         )
     article_name = pay_status["contract_terms"]["extra"]["article_name"]
     return flask.render_template(
-        "templates/confirm_refund.html",
-        article_name=article_name,
-        order_id=order_id)
+        "templates/confirm_refund.html", article_name=article_name, 
order_id=order_id
+    )
 
 
 ##
@@ -140,23 +137,17 @@ def confirm_refund(order_id):
 @app.route("/refund/<order_id>", methods=["POST"])
 def refund(order_id):
     if not order_id:
-        return flask.jsonify(
-            dict(error="Aborting refund: article not payed")
-        ), 401
+        return flask.jsonify(dict(error="Aborting refund: article not 
payed")), 401
     session_id = flask.session.get("session_id", "")
     pay_params = dict(order_id=order_id, session_id=session_id)
     pay_status = backend_get(BACKEND_URL, "check-payment", pay_params)
     if not pay_status.get("paid"):
         err_abort(
-            402,
-            message="You did not pay for this article (nice try!)",
-            json=pay_status
+            402, message="You did not pay for this article (nice try!)", 
json=pay_status
         )
     article_name = pay_status["contract_terms"]["extra"]["article_name"]
     refund_spec = dict(
-        order_id=order_id,
-        reason="Demo reimbursement",
-        refund=ARTICLE_AMOUNT
+        order_id=order_id, reason="Demo reimbursement", refund=ARTICLE_AMOUNT
     )
     resp = backend_post(BACKEND_URL, "refund", refund_spec)
     try:
@@ -177,7 +168,7 @@ def refund(order_id):
             500,
             message="Response from backend incomplete",
             json=resp,
-            stack=traceback.format_exc()
+            stack=traceback.format_exc(),
         )
 
 
@@ -197,9 +188,7 @@ def refund(order_id):
 def render_article(article_name, data, order_id):
     article_info = ARTICLES.get(article_name)
     if article_info is None:
-        m = "Internal error: Files for article ({}) not found.".format(
-            article_name
-        )
+        m = "Internal error: Files for article ({}) not 
found.".format(article_name)
         err_abort(500, message=m)
     if data is not None:
         if data in article_info.extra_files:
@@ -213,7 +202,7 @@ def render_article(article_name, data, order_id):
         "templates/article_frame.html",
         article_file=get_article_file(article_info),
         article_name=article_name,
-        order_id=order_id
+        order_id=order_id,
     )
 
 
@@ -229,9 +218,7 @@ def get_qrcode_svg(data):
 @app.route("/check-status/<order_id>/<session_id>")
 def check_status(order_id, session_id):
     pay_status = backend_get(
-        BACKEND_URL,
-        f"private/orders/{order_id}/",
-        dict(session_id=session_id)
+        BACKEND_URL, f"private/orders/{order_id}/", dict(session_id=session_id)
     )
     return flask.jsonify(paid=pay_status["paid"])
 
@@ -280,25 +267,23 @@ def article(article_name, data=None):
             fulfillment_url=flask.request.base_url,
             summary="Essay: " + article_name.replace("_", " "),
             # 10 minutes time for a refund
-            refund_deadline=dict(t_ms=1000*int(time.time() + 10 * 30)),
-            wire_transfer_deadline=dict(t_ms=1000*int(time.time() + 15 * 30)),
+            refund_deadline=dict(t_ms=1000 * int(time.time() + 10 * 30)),
+            wire_transfer_deadline=dict(t_ms=1000 * int(time.time() + 15 * 
30)),
         )
         order_resp = backend_post(BACKEND_URL, "private/orders", 
dict(order=order))
         order_id = order_resp["order_id"]
         return flask.redirect(
-            flask.url_for(
-                "article", article_name=article_name, order_id=order_id
-            )
+            flask.url_for("article", article_name=article_name, 
order_id=order_id)
         )
 
     # Prepare data for the upcoming payment check.
     pay_status = backend_get(
-        BACKEND_URL,
-        f"private/orders/{order_id}",
-        params=dict(session_id=session_id)
+        BACKEND_URL, f"private/orders/{order_id}", 
params=dict(session_id=session_id)
     )
 
-    if pay_status.get("paid"):
+    order_status = pay_status.get("order_status")
+
+    if order_status == "paid":
         # Checks to do:
         #
         # - check that the paid article is actually the one
@@ -321,7 +306,7 @@ def article(article_name, data=None):
             flask.url_for(
                 "article",
                 article_name=article_name,
-                order_id=pay_status.get("already_paid_order_id")
+                order_id=pay_status.get("already_paid_order_id"),
             )
         )
 
@@ -331,16 +316,14 @@ def article(article_name, data=None):
     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, session_id=session_id
-        )
+        flask.url_for("check_status", order_id=order_id, session_id=session_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
+        check_status_url_enc=check_status_url_enc,
     )
     headers = {"Taler": taler_pay_uri}
     resp = flask.Response(content, status=402, headers=headers)

-- 
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]