merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit 52d4248097904e30d43036202b5feba167d7cfca
parent a55410cdedb18f2cbd6682865f89d4ccbaf9481c
Author: Florian Dold <florian.dold@gmail.com>
Date:   Mon, 25 Jan 2016 16:11:28 +0100

merge execution page into fulfillment

Diffstat:
Dsrc/frontend/execute.js | 33---------------------------------
Msrc/frontend/fulfillment.php | 3++-
Msrc/frontend_lib/util.php | 14+++++++++-----
3 files changed, 11 insertions(+), 39 deletions(-)

diff --git a/src/frontend/execute.js b/src/frontend/execute.js @@ -1,33 +0,0 @@ -"use strict"; -// JSX literals are compiled to calls to React.createElement calls. -let React = { - createElement: function (tag, props, ...children) { - let e = document.createElement(tag); - for (let k in props) { - e.setAttribute(k, props[k]); - } - for (let child of children) { - if ("string" === typeof child || "number" == typeof child) { - child = document.createTextNode(child); - } - e.appendChild(child); - } - return e; - } -}; -document.addEventListener("DOMContentLoaded", function (e) { - var eve = new CustomEvent('taler-execute-payment', { detail: { H_contract: h_contract } }); - document.dispatchEvent(eve); -}); -function replace(el, r) { - el.parentNode.replaceChild(r, el); -} -document.addEventListener("taler-payment-result", function (e) { - if (!e.detail.success) { - alert("Payment failed\n" + JSON.stringify(e.detail)); - return; - } - console.log("finished payment"); - let msg = React.createElement("div", null, "Payment successful. View your ", React.createElement("a", {"href": e.detail.fulfillmentUrl}, "product"), "."); - replace(document.getElementById("loading"), msg); -}); diff --git a/src/frontend/fulfillment.php b/src/frontend/fulfillment.php @@ -3,6 +3,7 @@ <head> <title>Taler's "Demo" Shop</title> <link rel="stylesheet" type="text/css" href="style.css"> + <script type="application/javascript" src="taler-presence.js"> <script type="application/javascript"> function executePayment(H_contract, pay_url) { var detail = { @@ -81,7 +82,7 @@ if (null === $my_payment) if (true !== get($my_payment["is_payed"], false)) { - $pay_url = url_rel("pay"); + $pay_url = url_rel("pay", true); echo "<p>you have not payed for this contract: " . $hc . "</p>"; echo "<p>Asking the wallet to re-execute it ... </p>"; echo "<script>executePayment('$hc', '$pay_url');</script?"; diff --git a/src/frontend_lib/util.php b/src/frontend_lib/util.php @@ -4,17 +4,21 @@ function get(&$var, $default=null) { return isset($var) ? $var : $default; } -function url_join($base, $path) { - $url = (new http\URL($base)) - ->mod(array ("path" => $path), http\Url::JOIN_PATH|http\URL::SANITIZE_PATH); +function url_join($base, $path, $strip=false) { + $url = new http\URL($base); + if ($strip === true) { + $url = $url->mod(null, http\Url::STRIP_QUERY|http\Url::STRIP_FRAGMENT); + } + $url = $url->mod(array ("path" => $path), http\Url::JOIN_PATH|http\URL::SANITIZE_PATH); return $url->toString(); } // Get a url with a path relative to the // current script's path. -function url_rel($path) { +function url_rel($path, $strip=false) { return url_join( $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], - $path); + $path, + $strip); } ?>