merchant-frontend-examples

ZZZ: Inactive/Deprecated
Log | Files | Refs

commit 00e4c27a5f83471d50c290e233a9b7e5925fcf7d
parent 0b5a23780916ae3b0a8003719188737f00262296
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date:   Tue, 21 Feb 2017 11:56:37 +0100

Generating contract Python tutorial

Diffstat:
DPython/Makefile | 5-----
APython/lib/Makefile | 7+++++++
DPython/tutorial/__pycache__/tutorial.cpython-35.pyc | 0
MPython/tutorial/tutorial.py | 38+++++++++++++++++++++-----------------
4 files changed, 28 insertions(+), 22 deletions(-)

diff --git a/Python/Makefile b/Python/Makefile @@ -1,5 +0,0 @@ -all: - pip3 install lib --install-option="--prefix=$(TALER_PREFIX)" - -check: - python3 lib/pytaler/tests.py diff --git a/Python/lib/Makefile b/Python/lib/Makefile @@ -0,0 +1,7 @@ +# TALER_PREFIX must point to 'site-packages' dir. + +all: + pip3 install . --install-option="--prefix=$(TALER_PREFIX)" + +check: + python3 pytaler/tests.py diff --git a/Python/tutorial/__pycache__/tutorial.cpython-35.pyc b/Python/tutorial/__pycache__/tutorial.cpython-35.pyc Binary files differ. diff --git a/Python/tutorial/tutorial.py b/Python/tutorial/tutorial.py @@ -1,6 +1,13 @@ import flask +from urllib.parse import urljoin +from pytaler import amounts + + app = flask.Flask(__name__) +CURRENCY = "KUDOS" +BACKEND_URL = "http://backend.test.taler.net/" + @app.route('/') def index(): return flask.render_template('index.html') @@ -8,7 +15,7 @@ def index(): @app.route('/donate') def donate(): - resp = flask.Response() + resp = flask.Response(status=402) resp.headers['X-Taler-Contract-Url'] = '/generate-contract' return resp @@ -16,34 +23,31 @@ def donate(): @app.route('/generate-contract') def generate_contract(): - # 1. Generate order. - # FIXME: pass to VALUE.FRACTION:CURRENCY notation. - - donation_amount = amounts.amount_get_zero("KUDOS") - order = dict( nonce=flask.request.args.get("nonce"), - amount=ARTICLE_AMOUNT, - max_fee=dict(value=1, fraction=0, currency=CURRENCY), + amount=amounts.string_to_amount("1.0:%s" % CURRENCY), + max_fee=amounts.string_to_amount("1.0:%s" % CURRENCY), products=[ dict( - description="Essay: " + article_name.replace("_", " "), + description="Donation", quantity=1, product_id=0, - price=ARTICLE_AMOUNT, + price=amount, ), ], - fulfillment_url=make_url("/essay/" + quote(article_name)), + fulfillment_url=make_url("/fulfillment/"), merchant=dict( - instance=INSTANCE, address="nowhere", - name="Kudos Inc.", + name="Donation tutorial", jurisdiction="none", ), - extra=dict(article_name=article_name), ) + url = urljoin(BACKEND_URL, 'proposal') - - # 2. POST order to BE. - # 3. Relay proposal to client. + r = requests.post(url, json=dict(order=order)) + if r.status_code != 200: + logger.error("failed to POST to '%s'", url) + return r.status_code, r.text + proposal_resp = r.json() + return flask.jsonify(**proposal_resp)