summaryrefslogtreecommitdiff
path: root/talersurvey/survey/survey.py
diff options
context:
space:
mode:
Diffstat (limited to 'talersurvey/survey/survey.py')
-rw-r--r--talersurvey/survey/survey.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/talersurvey/survey/survey.py b/talersurvey/survey/survey.py
index ab02def..9e304ee 100644
--- a/talersurvey/survey/survey.py
+++ b/talersurvey/survey/survey.py
@@ -17,7 +17,11 @@
import flask
import os
import base64
+import requests
+import logging
from talersurvey.talerconfig import TalerConfig
+from urllib.parse import urljoin
+
base_dir = os.path.dirname(os.path.abspath(__file__))
app = flask.Flask(__name__, template_folder=base_dir)
@@ -27,6 +31,18 @@ tc = TalerConfig.from_env()
BACKEND_URL = tc["frontends"]["backend"].value_string(required=True)
CURRENCY = tc["taler"]["currency"].value_string(required=True)
app.config.from_object(__name__)
+logger = logging.getLogger(__name__)
+
+
+def backend_error(requests_response):
+ logger.error("Backend error: status code: "
+ + str(requests_response.status_code))
+ try:
+ return flask.jsonify(requests_response.json()), requests_response.status_code
+ except json.decoder.JSONDecodeError:
+ logger.error("Backend error (NO JSON returned): status code: "
+ + str(requests_response.status_code))
+ return flask.jsonify(dict(error="Backend died, no JSON got from it")), 502
@app.context_processor
def utility_processor():
@@ -52,3 +68,17 @@ def utility_processor():
@app.route("/")
def index():
return flask.render_template("templates/index.html", merchant_currency=CURRENCY)
+
+@app.route("/survey", methods=["GET", "POST"])
+def survey():
+ success = False
+ if flask.request.method == "POST":
+ r = requests.post(urljoin(BACKEND_URL, 'tip-authorize'),
+ json=dict(amount=dict(value=1, fraction=0, currency=CURRENCY),
+ instance="Taler",
+ justification="Payment methods survey"))
+ if 200 != r.status_code:
+ return backend_error(r)
+ else:
+ success = True
+ return flask.render_template("templates/index.html", success=success)