diff options
author | Marcello Stanisci <marcello.stanisci@inria.fr> | 2015-08-09 12:38:58 +0200 |
---|---|---|
committer | Marcello Stanisci <marcello.stanisci@inria.fr> | 2015-08-09 12:38:58 +0200 |
commit | 395d3f5e57d2c39cb3bd1a7ee8e768507b5d1e6b (patch) | |
tree | ce4ddc9f369b3287504922d59220f8511b53d9cc | |
parent | bfac37697930c75e2cba0180ffcd46345f0eb361 (diff) | |
download | merchant-395d3f5e57d2c39cb3bd1a7ee8e768507b5d1e6b.tar.gz merchant-395d3f5e57d2c39cb3bd1a7ee8e768507b5d1e6b.tar.bz2 merchant-395d3f5e57d2c39cb3bd1a7ee8e768507b5d1e6b.zip |
adding POST to give the backend the needed JSON
for generating the contract. I.e. adding POST /contract
-rw-r--r-- | src/frontend/README | 21 | ||||
-rw-r--r-- | src/frontend/cert.php | 41 | ||||
-rw-r--r-- | src/frontend/checkout.php | 11 |
3 files changed, 36 insertions, 37 deletions
diff --git a/src/frontend/README b/src/frontend/README index a89b9d36..fe8f44ab 100644 --- a/src/frontend/README +++ b/src/frontend/README @@ -1,24 +1,23 @@ This directory contains the files implementing the frontend of the new merchant architecture. -Only tested on nginx. To run the website, it suffices to have all the files in the same -directory, then having PHP enabled, and setting the following two redirections: - -1. your_site/certal/ => your_site/cert.php -2. your_site/payler/ => your_site/pay.php +Only tested on nginx. To run the website, it suffices to have all the .php and .html files +in the same directory, and having PHP (with the extension 'pecl_http' enabled) enabled. File |What implements -------------------------------- -o index.html | The "negotiation" view, that is the form - that allows the user to choose the product to buy. +o index.html | The homepage. Here it is possible to decide how much donate + to whom you would like. o checkout.php | The "payment selection" that is the form that allows the user to choose the payment method he wishes to use. - It also implements the request of certificate and its showing as a - popup window (by JavaScript in it). For debugging purposes, it has a - certificate hardcoded in it. + It also implements the request of certificate and trigger the certificate + viewer in the extension when it arrives in the customer's machine. + -o cert.php | Replies with a JSON certificate that is held in a 'session' variable. +o cert.php | Replies with a JSON certificate gotten from the backend. o pay.php | Actual receiving of money, plus it gives back a "fullfillment" page that informs the user of his well ended deal. +o toy | the nginx configuration file skeleton for this virtual server. To be tuned + as needed. diff --git a/src/frontend/cert.php b/src/frontend/cert.php index a330d76e..9f0af350 100644 --- a/src/frontend/cert.php +++ b/src/frontend/cert.php @@ -60,27 +60,30 @@ else{ 'currency' => $currency))); // test // echo $json; - // send to backend - /* // _very_ problematic - $http_obj = new HttpRequest; - $http_obj.setMethod (METH_GET); - //$http_obj.setBody ($json); - $http_obj.send (); - $http_obj.setUrl ("http://" . $SERVER["SERVER_NAME"] . "/backend" . "/hello"); - $status = $http_obj.getResponseHeader ('status'); - */ - $client = new http\Client; - $certificate = http_post_data ("http://" . $SERVER["SERVER_NAME"] . "/backend" . "/hello", - null, $response); - $status_code = $response['response_code']; - - set_response_code ($status_code); + + //echo phpinfo (); + + // crafting the request + $req = new http\Client\Request ("POST", + "http://" . $SERVER["SERVER_NAME"] . "/backend" . "/contract", + //"http://localhost:9898/", + array ("Content-Type" => "application/json")); + $req->getBody()->append ($json); - if ($status != 200) - echo "Some error occurred during this operation"; + $client = new http\Client; + $client->enqueue($req)->send (); + $resp = $client->getResponse (); + $status_code = $resp->getResponseCode (); + http_response_code ($status_code); + + + if ($status_code != 200){ + echo "Error while generating the certificate, response code : " . $status_code; + } // send the contract back to the wallet without touching it - else echo $http_obj.getResponseBody (); - + else{ + echo $resp->body->toString (); + } } diff --git a/src/frontend/checkout.php b/src/frontend/checkout.php index fc11b35a..b7b028fb 100644 --- a/src/frontend/checkout.php +++ b/src/frontend/checkout.php @@ -41,8 +41,6 @@ <?php -// ID generation -$transId = rand(1, 15); // getting the donation receiver's name $got_donation = $_POST['group0']; // create session @@ -54,13 +52,14 @@ $_SESSION['maydonate'] = true; ?> -<form name="tform" action="" method="POST"> +<form name="tform" action="cert.php" method="POST"> <div id="opt-form" align="left"><br> <input type="radio" name="group1" value="Lisa">Lisa<br> <input type="radio" name="group1" value="You Card" checked>You Card<br> <input type="radio" name="group1" value="Card Me">Card Me<br> <input id="t-button-id" type="radio" name="group1" value="Taler" disabled="true">Taler<br> -<input type="button" onclick="ok(this.form)" value="Ok"--> +<input type="submit" value="Ok"--> +<!--input type="button" onclick="ok(this.form)" value="Ok"--> </div> </form> @@ -81,9 +80,7 @@ function ok(form){ to the (XUL) extension) */ sendContract(cert.responseText); } - else alert("Certificate ready state: " - + cert.readyState + ", cert status: " - + cert.status); + else alert("No certificate gotten, status " + cert.status); } }; |