diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-07-12 18:19:17 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-07-12 18:19:17 +0200 |
commit | 895e24872de95acf255e0746b42f0661697e7f9a (patch) | |
tree | b2aadbb712549f7aa9caf8679036e9f1535a4f2c /doc/system/snippets | |
parent | 4d298f9bea8a98acc5d4b7d738af02313b203658 (diff) | |
download | exchange-895e24872de95acf255e0746b42f0661697e7f9a.tar.xz |
initial import of thesis-dold
Diffstat (limited to 'doc/system/snippets')
-rw-r--r-- | doc/system/snippets/donations.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/doc/system/snippets/donations.py b/doc/system/snippets/donations.py new file mode 100644 index 000000000..217e4c700 --- /dev/null +++ b/doc/system/snippets/donations.py @@ -0,0 +1,42 @@ +@app.route("/donate") +def donate(): + donation_amount = expect_parameter("donation_amount") + donation_donor = expect_parameter("donation_donor") + fulfillment_url = flask.url_for("fulfillment", _external=True) + order = dict( + amount=donation_amount, + extra=dict(donor=donation_donor, amount=donation_amount), + fulfillment_url=fulfillment_url, + summary="Donation to the GNU Taler project", + ) + # ask backend to create new order + order_resp = backend_post("order", dict(order=order)) + order_id = order_resp["order_id"] + return flask.redirect(flask.url_for("fulfillment", order_id=order_id)) + + +@app.route("/receipt") +def fulfillment(): + order_id = expect_parameter("order_id") + pay_params = dict(order_id=order_id) + + # ask backend for status of payment + pay_status = backend_get("check-payment", pay_params) + + if pay_status.get("payment_redirect_url"): + return flask.redirect(pay_status["payment_redirect_url"]) + + if pay_status.get("paid"): + # The "extra" field in the contract terms can be used + # by the merchant for free-form data, interpreted + # by the merchant (avoids additional database access) + extra = pay_status["contract_terms"]["extra"] + return flask.render_template( + "templates/fulfillment.html", + donation_amount=extra["amount"], + donation_donor=extra["donor"], + order_id=order_id, + currency=CURRENCY) + + # no pay_redirect but article not paid, this should never happen! + err_abort(500, message="Internal error, invariant failed", json=pay_status) |