diff options
-rw-r--r-- | src/backend/taler-merchant-httpd_mints.c | 10 | ||||
-rw-r--r-- | src/frontend/checkout.php | 1 | ||||
-rw-r--r-- | src/frontend/execute.js | 32 | ||||
-rw-r--r-- | src/frontend/execute.php | 12 | ||||
-rw-r--r-- | src/frontend/execute.tsx | 40 | ||||
-rw-r--r-- | src/frontend/generate_taler_contract.php | 27 | ||||
-rw-r--r-- | src/frontend/pay.php | 11 | ||||
-rw-r--r-- | src/tsconfig.json | 10 |
8 files changed, 121 insertions, 22 deletions
diff --git a/src/backend/taler-merchant-httpd_mints.c b/src/backend/taler-merchant-httpd_mints.c index e93419cd..5ddaf758 100644 --- a/src/backend/taler-merchant-httpd_mints.c +++ b/src/backend/taler-merchant-httpd_mints.c @@ -230,6 +230,8 @@ context_task (void *cls, struct GNUNET_NETWORK_FDSet *ws; struct GNUNET_TIME_Relative delay; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In mint context polling task\n"); + poller_task = NULL; TALER_MINT_perform (ctx); max_fd = -1; @@ -243,6 +245,9 @@ context_task (void *cls, &except_fd_set, &max_fd, &timeout); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "In mint context polling task, max_fd=%d, timeout=%ld\n", + max_fd, timeout); if (timeout >= 0) delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, @@ -319,6 +324,11 @@ TMH_MINTS_find_mint (const char *chosen_mint, GNUNET_break (0); return NULL; } + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Trying to find chosen mint `%s'\n", + chosen_mint); + /* Check if the mint is known */ for (mint = mint_head; NULL != mint; mint = mint->next) /* test it by checking public key --- FIXME: hostname or public key!? diff --git a/src/frontend/checkout.php b/src/frontend/checkout.php index e4dd8ebd..21d4d8c4 100644 --- a/src/frontend/checkout.php +++ b/src/frontend/checkout.php @@ -55,6 +55,7 @@ // create PHP session and store donation information in session $donation_fraction = (float) ("0." . $donation_fraction); session_start(); + session_unset(); $_SESSION['receiver'] = $donation_receiver; $_SESSION['amount_value'] = (int) $donation_amount; $_SESSION['amount_fraction'] = (int) ($donation_fraction * 1000000); diff --git a/src/frontend/execute.js b/src/frontend/execute.js new file mode 100644 index 00000000..cd7b0b1e --- /dev/null +++ b/src/frontend/execute.js @@ -0,0 +1,32 @@ +"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)); + } + 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/execute.php b/src/frontend/execute.php index 61c8e197..33021fd3 100644 --- a/src/frontend/execute.php +++ b/src/frontend/execute.php @@ -31,18 +31,8 @@ session_start(); echo "var h_contract=\"$_SESSION[H_contract]\";\n"; ?> -document.addEventListener("DOMContentLoaded", function (e) { - var eve = new CustomEvent('taler-execute-payment', {detail: {H_contract: h_contract}}); - document.dispatchEvent(eve); -}); -document.addEventListener("taler-payment-result", function (e) { - if (!e.detail.success) { - alert("Payment failed\n" + JSON.strinfigy(e.detail)); - } - console.log("finished payment"); - document.getElementById("loading").innerHTML = "success!"; -}); </script> + <script type="text/javascript" src="execute.js"></script> </head> <body> diff --git a/src/frontend/execute.tsx b/src/frontend/execute.tsx new file mode 100644 index 00000000..f7e660c9 --- /dev/null +++ b/src/frontend/execute.tsx @@ -0,0 +1,40 @@ +"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; + } +}; + +declare var h_contract: string; + +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: CustomEvent) { + if (!e.detail.success) { + alert("Payment failed\n" + JSON.stringify(e.detail)); + } + console.log("finished payment"); + let msg = + <div>Payment successful. View your <a href={e.detail.fulfillmentUrl}>product</a>.</div>; + replace(document.getElementById("loading"), msg); +}); diff --git a/src/frontend/generate_taler_contract.php b/src/frontend/generate_taler_contract.php index ababa832..14add359 100644 --- a/src/frontend/generate_taler_contract.php +++ b/src/frontend/generate_taler_contract.php @@ -35,10 +35,10 @@ $cli_debug = false; $backend_test = true; -if ($_GET['cli_debug'] == 'yes') +if (isset($_GET['cli_debug']) && $_GET['cli_debug'] == 'yes') $cli_debug = true; -if ($_GET['backend_test'] == 'no') +if (isset($_GET['backend_test']) && $_GET['backend_test'] == 'no') { $cli_debug = true; $backend_test = false; @@ -90,6 +90,9 @@ $teatax = array ('value' => 1, // Take a timestamp $now = new DateTime('now'); +$PAY_URL = "pay.php"; +$EXEC_URL = "execute.php"; + // pack the JSON for the contract // --- FIXME: exact format needs review! $contract = array ('amount' => array ('value' => $amount_value, @@ -110,8 +113,8 @@ $contract = array ('amount' => array ('value' => $amount_value, 'delivery_date' => "Some Date Format", 'delivery_location' => 'LNAME1')), 'timestamp' => "/Date(" . $now->getTimestamp() . ")/", - 'pay_url' => "/taler/pay", - 'exec_url' => "http://example.com/exec-url", + 'pay_url' => $PAY_URL, + 'exec_url' => $EXEC_URL, 'expiry' => "/Date(" . $now->add(new DateInterval('P2W'))->getTimestamp() . ")/", 'refund_deadline' => "/Date(" . $now->add(new DateInterval('P3M'))->getTimestamp() . ")/", 'merchant' => array ('address' => 'LNAME2', @@ -140,19 +143,21 @@ $contract = array ('amount' => array ('value' => $amount_value, 'region' => 'Test Region', 'province' => 'Test Province', 'ZIP code' => 4908))); -$json = json_encode (array ('contract' => $contract), JSON_PRETTY_PRINT); +$json = json_encode (array ('contract' => $contract, 'exec_url' => $EXEC_URL, 'pay_url' => $PAY_URL), JSON_PRETTY_PRINT); if ($cli_debug && !$backend_test) { echo $json . "\n"; exit; } -// Craft the HTTP request, note that the backend -// could be on an entirely different machine if -// desired. -$req = new http\Client\Request ("POST", - "http://" . $_SERVER["SERVER_NAME"] . "/backend/contract", - array ("Content-Type" => "application/json")); + +$url = (new http\URL("http://".$_SERVER["HTTP_HOST"])) + ->mod(array ("path" => "backend/contract"), http\Url::JOIN_PATH); + +$req = new http\Client\Request("POST", + $url, + array ("Content-Type" => "application/json")); + $req->getBody()->append ($json); // Execute the HTTP request diff --git a/src/frontend/pay.php b/src/frontend/pay.php index 7f7a8bc9..11725c63 100644 --- a/src/frontend/pay.php +++ b/src/frontend/pay.php @@ -48,6 +48,17 @@ if (!isset($_SESSION['H_contract'])) return; } +if (isset($_SESSION['payment_ok']) && $_SESSION['payment_ok'] == true) +{ + $_SESSION['payment_ok'] = true; + http_response_code (301); + //$url = (new http\URL("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]")) + $url = (new http\URL("http://$_SERVER[HTTP_HOST]")) + ->mod(array ("path" => "fulfillment.php"), http\Url::JOIN_PATH); + header("Location: $url"); + die(); +} + $post_body = file_get_contents('php://input'); $now = new DateTime('now'); diff --git a/src/tsconfig.json b/src/tsconfig.json new file mode 100644 index 00000000..13a16c56 --- /dev/null +++ b/src/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "target": "es6", + "jsx": "react" + }, + "files": [ + "frontend/execute.tsx" + ] +} + |