merchant-frontend-examples

ZZZ: Inactive/Deprecated
Log | Files | Refs

commit 2030c9eee0970f17798dea700cb21027b3f7a6f3
parent 197504825e3b6da9bec822247a4815eace1bc377
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date:   Mon, 20 Feb 2017 20:02:19 +0100

Going on with Python tutorial..

Diffstat:
MPython/Makefile | 4++--
RPython/pytaler/__init__.py -> Python/lib/pytaler/__init__.py | 0
APython/lib/pytaler/__pycache__/amounts.cpython-35.pyc | 0
RPython/pytaler/amounts.py -> Python/lib/pytaler/amounts.py | 0
APython/lib/pytaler/tests.py | 26++++++++++++++++++++++++++
RPython/setup.py -> Python/lib/setup.py | 0
DPython/tutorial.py | 6------
APython/tutorial/__pycache__/tutorial.cpython-35.pyc | 0
APython/tutorial/templates/index.html | 12++++++++++++
APython/tutorial/tutorial.py | 49+++++++++++++++++++++++++++++++++++++++++++++++++
10 files changed, 89 insertions(+), 8 deletions(-)

diff --git a/Python/Makefile b/Python/Makefile @@ -1,5 +1,5 @@ all: - pip3 install . --install-option="--prefix=$(TALER_PREFIX)" + pip3 install lib --install-option="--prefix=$(TALER_PREFIX)" check: - python3 pytaler/tests.py + python3 lib/pytaler/tests.py diff --git a/Python/pytaler/__init__.py b/Python/lib/pytaler/__init__.py diff --git a/Python/lib/pytaler/__pycache__/amounts.cpython-35.pyc b/Python/lib/pytaler/__pycache__/amounts.cpython-35.pyc Binary files differ. diff --git a/Python/pytaler/amounts.py b/Python/lib/pytaler/amounts.py diff --git a/Python/lib/pytaler/tests.py b/Python/lib/pytaler/tests.py @@ -0,0 +1,26 @@ +import unittest +import amounts +from random import randint + +currency = "KUDOS" + +class AmountsTest(unittest.TestCase): + + def test(self): + a1 = amounts.amount_get_zero(currency) + a2 = amounts.amount_get_zero(currency) + v1 = randint(1, 200) + v2 = randint(1, 200) + f1 = randint(10000000, 100000000) + f2 = randint(10000000, 100000000) + a1['value'] = v1 + a2['value'] = v2 + a1['fraction'] = f1 + a2['fraction'] = f2 + res1 = amounts.amount_sum(a1, a2) + res2 = amounts.amount_sub(res1, a1) + self.assertTrue(amounts.same_amount(res2, a2)) + + +if __name__ == '__main__': + unittest.main() diff --git a/Python/setup.py b/Python/lib/setup.py diff --git a/Python/tutorial.py b/Python/tutorial.py @@ -1,6 +0,0 @@ -from flask import Flask -app = Flask(__name__) - -@app.route('/') -def hello_world(): - return 'Hello, World!' 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/templates/index.html b/Python/tutorial/templates/index.html @@ -0,0 +1,12 @@ +<!DOCTYPE html> +<html lang="en"> + <!-- This file is in the public domain --> + <head> + <title>A donation button</title> + </head> + <body> + <form action='/donate' method='GET'> + <input type='submit' value='Donate!'></input> + </form> + </body> +</html> diff --git a/Python/tutorial/tutorial.py b/Python/tutorial/tutorial.py @@ -0,0 +1,49 @@ +import flask +app = flask.Flask(__name__) + +@app.route('/') +def index(): + return flask.render_template('index.html') + + +@app.route('/donate') +def donate(): + resp = flask.Response() + resp.headers['X-Taler-Contract-Url'] = '/generate-contract' + return resp + + +@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), + products=[ + dict( + description="Essay: " + article_name.replace("_", " "), + quantity=1, + product_id=0, + price=ARTICLE_AMOUNT, + ), + ], + fulfillment_url=make_url("/essay/" + quote(article_name)), + merchant=dict( + instance=INSTANCE, + address="nowhere", + name="Kudos Inc.", + jurisdiction="none", + ), + extra=dict(article_name=article_name), + ) + + + + # 2. POST order to BE. + # 3. Relay proposal to client.