From d429ea577fc5af028b0d5f3ed309fc96155e8240 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sat, 8 Aug 2020 13:02:11 +0530 Subject: switch to merchant backend based payment flow --- talermerchantdemos/blog/blog.py | 59 +++-------------------------------------- 1 file changed, 4 insertions(+), 55 deletions(-) (limited to 'talermerchantdemos/blog/blog.py') diff --git a/talermerchantdemos/blog/blog.py b/talermerchantdemos/blog/blog.py index 4b1545f..1e25555 100644 --- a/talermerchantdemos/blog/blog.py +++ b/talermerchantdemos/blog/blog.py @@ -1,5 +1,5 @@ ## -# This file is part of GNU TALER. +# This file is part of GNU taler. # Copyright (C) 2014-2017 INRIA # # TALER is free software; you can redistribute it and/or modify it under the @@ -22,8 +22,6 @@ import logging import os import traceback import uuid -import qrcode -import qrcode.image.svg import base64 import flask import lxml.etree @@ -150,26 +148,8 @@ def refund(order_id): order_id=order_id, reason="Demo reimbursement", refund=ARTICLE_AMOUNT ) resp = backend_post(BACKEND_URL, "refund", refund_spec) - try: - # delete from paid article cache - paid_articles_cache.delete(session_id + "-" + article_name) - taler_refund_uri = resp["taler_refund_uri"] - qrcode_svg = get_qrcode_svg(taler_refund_uri) - content = flask.render_template( - "templates/show_refund.html", - article_name=article_name, - taler_refund_uri=taler_refund_uri, - qrcode_svg=qrcode_svg, - ) - headers = {"Taler": taler_refund_uri} - return flask.Response(content, status=402, headers=headers) - except KeyError: - err_abort( - 500, - message="Response from backend incomplete", - json=resp, - stack=traceback.format_exc(), - ) + paid_articles_cache.delete(session_id + "-" + article_name) + return flask.redirect(pay_status["order_status_url"]) ## @@ -206,23 +186,6 @@ def render_article(article_name, data, order_id): ) -def get_qrcode_svg(data): - factory = qrcode.image.svg.SvgImage - img = qrcode.make(data, image_factory=factory) - return lxml.etree.tostring(img.get_image()).decode("utf-8") - - -## -# This endpoint is used by the payment request page -# to check if the payment has been completed via the QR code. -@app.route("/check-status//") -def check_status(order_id, session_id): - pay_status = backend_get( - BACKEND_URL, f"private/orders/{order_id}/", dict(session_id=session_id) - ) - return flask.jsonify(paid=pay_status["paid"]) - - ## # Trigger a article purchase. The logic follows the main steps: # @@ -313,18 +276,4 @@ def article(article_name, data=None): ## # Redirect the browser to a page where the wallet can # run the payment protocol. - 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) - ) - 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, - ) - headers = {"Taler": taler_pay_uri} - resp = flask.Response(content, status=402, headers=headers) - return resp + return flask.redirect(pay_status["order_status_url"]) -- cgit v1.2.3