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: if the order was not


From: gnunet
Subject: [taler-taler-merchant-demos] branch master updated: if the order was not found, create one
Date: Mon, 10 Jul 2023 16:47:39 +0200

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

sebasjm 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 4a52640  if the order was not found, create one
4a52640 is described below

commit 4a526409d21be191b3e4d3f0500be4ad43ea7d8c
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Mon Jul 10 11:46:47 2023 -0300

    if the order was not found, create one
---
 talermerchantdemos/blog/blog.py           | 19 ++++++++++++++++++-
 talermerchantdemos/httpcommon/__init__.py | 19 +++++++++++--------
 2 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/talermerchantdemos/blog/blog.py b/talermerchantdemos/blog/blog.py
index a0761b4..5784ab1 100644
--- a/talermerchantdemos/blog/blog.py
+++ b/talermerchantdemos/blog/blog.py
@@ -38,6 +38,7 @@ 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_get_with_status,
     backend_post,
     self_localized,
     Deadline,
@@ -406,12 +407,28 @@ def article(article_name, lang=None, data=None):
         order_id = order_resp["order_id"]
 
     # Ask the backend for the status of the payment.
-    pay_status = backend_get(
+    status, pay_status = backend_get_with_status(
         BACKEND_URL,
         f"private/orders/{order_id}",
         params=dict(session_id=session_id),
         auth_token=APIKEY,
     )
+
+    if status == 404:
+        order_resp = post_order(article_name, lang)
+        order_id = order_resp["order_id"]
+        pay_status = backend_get(
+            BACKEND_URL,
+            f"private/orders/{order_id}",
+            params=dict(session_id=session_id),
+            auth_token=APIKEY,
+        )
+    elif status != 200:
+        raise BackendException(
+            message=gettext("Backend returned error status"),
+            backend_status=status,
+            backend_json=pay_status,
+        )
     order_status = pay_status.get("order_status")
 
     if order_status == "claimed":
diff --git a/talermerchantdemos/httpcommon/__init__.py 
b/talermerchantdemos/httpcommon/__init__.py
index 2a6e53d..518eb1b 100644
--- a/talermerchantdemos/httpcommon/__init__.py
+++ b/talermerchantdemos/httpcommon/__init__.py
@@ -69,6 +69,16 @@ def backend_post(backend_url, endpoint, json, 
auth_token=None):
 # @return the JSON response from the backend, or a error response
 #         if something unexpected happens.
 def backend_get(backend_url, endpoint, params, auth_token=None):
+    status, json = backend_get_with_status(backend_url, endpoint, params, 
auth_token)
+    if status != 200:
+        raise BackendException(
+            message=gettext("Backend returned error status"),
+            backend_status=status,
+            backend_json=json,
+        )
+    return json
+
+def backend_get_with_status(backend_url, endpoint, params, auth_token=None):
     headers = dict()
     if auth_token is not None:
         headers["Authorization"] = "Bearer " + auth_token
@@ -84,15 +94,8 @@ def backend_get(backend_url, endpoint, params, 
auth_token=None):
         response_json = resp.json()
     except Exception:
         raise BackendException(message=gettext("Could not parse response from 
backend"))
-    if resp.status_code != 200:
-        raise BackendException(
-            message=gettext("Backend returned error status"),
-            backend_status=resp.status_code,
-            backend_json=response_json,
-        )
     print("Backend responds to {}: {}".format(final_url, str(response_json)))
-    return response_json
-
+    return resp.status_code, response_json
 
 def get_locale():
     parts = request.path.split("/", 2)

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