merchant-frontend-examples

ZZZ: Inactive/Deprecated
Log | Files | Refs

commit 16742e787e4071c1108eb328a5256c2b8d8850c4
parent b28cadd945c1d02f33afdc8feaa03a08565d59b2
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date:   Mon, 27 Mar 2017 02:01:52 +0200

adapting (~60%) php backoffice to latest changes

Diffstat:
Mphp/backend.php | 2--
Mphp/backoffice.html | 15++++-----------
Mphp/generate-order.php | 2+-
Mphp/history.js | 10++++------
Mphp/history.php | 12++----------
Mphp/order.php | 1+
Mphp/track-transaction.php | 16++++------------
Mpython/example/example.py | 1+
8 files changed, 17 insertions(+), 42 deletions(-)

diff --git a/php/backend.php b/php/backend.php @@ -37,6 +37,4 @@ return array("status_code" => curl_getinfo($c, CURLINFO_HTTP_CODE), "body" => $r); } - - ?> diff --git a/php/backoffice.html b/php/backoffice.html @@ -7,7 +7,8 @@ </head> <body> <form action='/track-transaction.php' method='GET'> - <input type='text' name='tid' placeholder='Transaction ID'></input> + <input type='text' name='order_id' placeholder='Order ID'></input> + <input type='text' name='instance' value='tutorial' hidden></input> <input type='submit' value='Track transaction'></input> </form> <form action='/track-transfer.php' method='GET'> @@ -16,23 +17,15 @@ <input type='submit' value='Track transfer'></input> </form> <form id="history_form" action="" method="GET"> - Get transactions up to - <select name="days"> - <option value="1">1</option> - <option value="2">2</option> - <option value="7">7</option> - <option value="0">&infin;</option> - </select> - days back: <input type="button" onclick="submit_history();" value="Get!"> + <a href="#" onclick="submit_history()">Get transactions list</a> <br> <small>Works only if JavaScript enabled</small> </form> <br/> <table id="history" style="visibility: hidden;"> <tr> - <th>Transaction ID</th> + <th>Order ID</th> <th>Date</th> - <th>Contract</th> <th>Amount</th> </tr> </table> diff --git a/php/generate-order.php b/php/generate-order.php @@ -15,7 +15,7 @@ "no nonce given", 400); $order = make_order($_GET["nonce"], - $order_id, + strval($order_id), new DateTime('now')); // Here the frontend POSTs the proposal to the backend $response = post_to_backend("/proposal", $order); diff --git a/php/history.js b/php/history.js @@ -29,7 +29,6 @@ function submit_history(){ /* We don't want to kill the first child */ for (var i = 2; i < table.childNodes.length; i++) table.removeChild(table.childNodes[i]); - var days = document.getElementById("history_form").days.value; var req = new XMLHttpRequest(); var get_column = function(value){ var column = document.createElement("td"); @@ -39,9 +38,10 @@ function submit_history(){ var on_error = function(){ table.innerHTML = "<p>Could not get transactions list from server</p>" }; - req.open("GET", `/history.php?days=${days}`, true); + req.open("GET", "/history.php?instance=tutorial", true); req.onload = function(){ if(req.readyState == 4 && req.status == 200){ + console.log("Got history:", req.responseText); var history = JSON.parse(req.responseText); if(!history) console.log("Got invalid JSON"); @@ -51,12 +51,10 @@ function submit_history(){ for (var i=0; i<history.length; i++){ var entry = history[i]; var tr = document.createElement("tr"); - tr.appendChild(get_column(entry.transaction_id)); + tr.appendChild(get_column(entry.order_id)); var date = get_date(entry.timestamp); tr.appendChild(get_column(date.toLocaleDateString())); - var contract = entry.h_contract.substr(0, 5); - tr.appendChild(get_column(contract + "...")); - tr.appendChild(get_column(parse_amount(entry.total_amount))) + tr.appendChild(get_column(parse_amount(entry.amount))) table.appendChild(tr); } table.style.visibility = ""; diff --git a/php/history.php b/php/history.php @@ -2,22 +2,14 @@ include 'helpers.php'; include 'backend.php'; + include 'error.php'; - if (!isset($_GET['days'])) { - echo "<p>Please give 'days' parameter.</p>"; - return; - } - - $now = new DateTime(); - $now->sub(new DateInterval(sprintf("P%sD", $_GET['days']))); - $response = get_to_backend("/history", - array("date"=>$now->getTimestamp())); + $response = get_to_backend("/history", $_GET); if (200 != $response["status_code"]){ echo build_error($response, "Backend error", $response["status_code"]); return; } - echo $response["body"]; ?> diff --git a/php/order.php b/php/order.php @@ -51,6 +51,7 @@ 'merchant' => array('address' => 'LNAME2', + 'instance' => "tutorial", 'name' => "Charity donation shop", 'jurisdiction' => diff --git a/php/track-transaction.php b/php/track-transaction.php @@ -5,15 +5,8 @@ include 'backend.php'; - if (!isset($_GET['tid'])){ - build_error(array("body" => "No transaction ID given"), - "tid argument missing", - 400); - return; - } + $response = get_to_backend("/track/transaction", $_GET); - $response = get_to_backend("/track/transaction", - array("id" => intval($_GET['tid']))); if (!in_array($response["status_code"], array(200, 202, 424))){ echo build_error($response, "Backend error", @@ -24,11 +17,10 @@ // Report conflict if (424 == $response["status_code"]){ $body = json_decode($response["body"]); - echo sprintf("<p>Coin '%s', related to transaction '%s', - is conflicting: what claimed by the exchange does + echo sprintf("<p>Exchange provided conflicting information about + transaction '%s': what claimed by the exchange does not match what stored in our DB.</p>", - $body->coin_pub, - $_GET['tid']); + $_GET["order_id"]); return; } diff --git a/python/example/example.py b/python/example/example.py @@ -62,6 +62,7 @@ def generate_proposal(): fulfillment_url=make_url("/fulfillment"), pay_url=make_url("/pay"), merchant=dict( + instance="tutorial", address="nowhere", name="Donation tutorial", jurisdiction="none",