summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--talermerchantdemos/blog/blog.py19
-rw-r--r--talermerchantdemos/httpcommon/__init__.py19
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)