From febb6d9dc9e1692b686e17215ebef3c5a1a79f68 Mon Sep 17 00:00:00 2001 From: Marcello Stanisci Date: Tue, 21 Nov 2017 17:49:37 +0100 Subject: add /pick endpoint --- talersurvey/survey/survey.py | 22 +++++++++++++++++----- talersurvey/survey/templates/index.html | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/talersurvey/survey/survey.py b/talersurvey/survey/survey.py index 8697ddf..dd68bca 100644 --- a/talersurvey/survey/survey.py +++ b/talersurvey/survey/survey.py @@ -66,12 +66,22 @@ def utility_processor(): return os.environ.get(name, default) return dict(url=url, env=env) -@app.route("/") -def index(): - return flask.render_template("templates/index.html", merchant_currency=CURRENCY) +@app.route("/pick", methods=["POST"]) +def pick(): + body = flask.request.get_json() + # Let the backend complain! + body["tip_id"] = flask.request.args.get("tip_id") + r = requests.post(urljoin(BACKEND_URL, 'tip-pickup'), + json=body) + if 200 != r.status_code: + return backend_error(r) + else: + return flask.jsonify(r.json()) -@app.route("/survey", methods=["GET", "POST"]) +@app.route("/", methods=["GET", "POST"]) def survey(): + if flask.request.method == "GET": + return flask.render_template("templates/index.html", merchant_currency=CURRENCY) success = False amount = Amount(CURRENCY, 1) if flask.request.method == "POST": @@ -85,7 +95,9 @@ def survey(): success = True response = flask.make_response(flask.render_template("templates/index.html", success=success), 402) - response.headers["X-Taler-Tipping-Url"] = "%s/%s?id=%s" % (flask.request.script_root, "pick", r.json().get("tip_id")) + response.headers["X-Taler-Tipping-Url"] = urljoin( + flask.request.base_url, + flask.url_for("pick", tip_id=r.json().get("tip_id"))) response.headers["X-Taler-Tipping-Exchange"] = r.json().get("exchange_uri") response.headers["X-Taler-Tipping-Amount"] = amount.stringify(2) response.headers["X-Taler-Tipping-Deadline"] = r.json().get("expiration") diff --git a/talersurvey/survey/templates/index.html b/talersurvey/survey/templates/index.html index ffb871e..28057c2 100644 --- a/talersurvey/survey/templates/index.html +++ b/talersurvey/survey/templates/index.html @@ -8,7 +8,7 @@

-
+ {% if success %} Congratulations, your reward has been successfully submitted!
-- cgit v1.2.3