exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

donations.py (1633B)


      1 @app.route("/donate")
      2 def donate():
      3     donation_amount = expect_parameter("donation_amount")
      4     donation_donor = expect_parameter("donation_donor")
      5     fulfillment_url = flask.url_for("fulfillment", _external=True)
      6     order = dict(
      7         amount=donation_amount,
      8         extra=dict(donor=donation_donor, amount=donation_amount),
      9         fulfillment_url=fulfillment_url,
     10         summary="Donation to the GNU Taler project",
     11     )
     12     # ask backend to create new order
     13     order_resp = backend_post("order", dict(order=order))
     14     order_id = order_resp["order_id"]
     15     return flask.redirect(flask.url_for("fulfillment", order_id=order_id))
     16 
     17 
     18 @app.route("/receipt")
     19 def fulfillment():
     20     order_id = expect_parameter("order_id")
     21     pay_params = dict(order_id=order_id)
     22 
     23     # ask backend for status of payment
     24     pay_status = backend_get("check-payment", pay_params)
     25 
     26     if pay_status.get("payment_redirect_url"):
     27         return flask.redirect(pay_status["payment_redirect_url"])
     28 
     29     if pay_status.get("paid"):
     30         # The "extra" field in the contract terms can be used
     31         # by the merchant for free-form data, interpreted
     32         # by the merchant (avoids additional database access)
     33         extra = pay_status["contract_terms"]["extra"]
     34         return flask.render_template(
     35             "templates/fulfillment.html",
     36             donation_amount=extra["amount"],
     37             donation_donor=extra["donor"],
     38             order_id=order_id,
     39             currency=CURRENCY)
     40 
     41     # no pay_redirect but article not paid, this should never happen!
     42     err_abort(500, message="Internal error, invariant failed", json=pay_status)