diff options
author | Marcello Stanisci <marcello.stanisci@inria.fr> | 2015-08-07 19:40:25 +0200 |
---|---|---|
committer | Marcello Stanisci <marcello.stanisci@inria.fr> | 2015-08-07 19:40:25 +0200 |
commit | bfac37697930c75e2cba0180ffcd46345f0eb361 (patch) | |
tree | f1b9da091d7f7534c179ab4168ebd0c4a1a52f93 | |
parent | 65764d7f8a8db817b295165505663350cac20cde (diff) | |
download | merchant-bfac37697930c75e2cba0180ffcd46345f0eb361.tar.gz merchant-bfac37697930c75e2cba0180ffcd46345f0eb361.tar.bz2 merchant-bfac37697930c75e2cba0180ffcd46345f0eb361.zip |
adapting the frontend to the new architecture
-rw-r--r-- | src/backend/taler-merchant-httpd.c | 1 | ||||
-rw-r--r-- | src/frontend/cert.php | 70 | ||||
-rw-r--r-- | src/frontend/checkout.php | 137 | ||||
-rw-r--r-- | src/frontend/shopping.html | 13 |
4 files changed, 123 insertions, 98 deletions
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c index 4dfb71d1..9ac225b5 100644 --- a/src/backend/taler-merchant-httpd.c +++ b/src/backend/taler-merchant-httpd.c @@ -485,6 +485,7 @@ url_handler (void *cls, void **connection_cls) { + printf ("%s\n", url); unsigned int status; unsigned int no_destroy; json_int_t prod_id; diff --git a/src/frontend/cert.php b/src/frontend/cert.php index 3b719b24..a330d76e 100644 --- a/src/frontend/cert.php +++ b/src/frontend/cert.php @@ -18,15 +18,71 @@ */ -// Here goes all the Taler pay logic +/* + + Here goes all the Taler paying logic. The steps are + + 1. recover the session + + 2. generate the JSON to forward to the backend + + 3. route back to the wallet the certificate just gotten + +*/ // recover the session - session_start(); - if(!isset($_SESSION['contract'])){ - http_response_code(404); - echo "Sorry page.."; - } - else echo $_SESSION['contract']; +session_start(); +if(!isset($_SESSION['maydonate'])){ + http_response_code(404); + echo "Please try to donate before getting to this page :)"; +} + +else{ + // fake product id + $p_id = rand(0,1001); + // generate a transaction/certificate id. In production context, it's wishable to + // record this value + $trans_cert_id = rand(0, 1001); + // fake a human readable description of this deal + $desc = "donation aimed to stop the ants' massacre on hicking paths"; + // fake the price's integer (actually, the system is testishly suited for just 10 EUR coins) + $value = 10; + // fake the price's fractional + $fraction = 0; + // hardcode the currency + $currency = "EUR"; + + // pack the JSON + $json = json_encode (array ('desc' => $desc, 'product' => $p_id, 'cid' => $trans_cert_id, + 'price' => array ('value' => $value, + 'fraction' => $fraction, + '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); + + if ($status != 200) + echo "Some error occurred during this operation"; + // send the contract back to the wallet without touching it + else echo $http_obj.getResponseBody (); + + +} + ?> diff --git a/src/frontend/checkout.php b/src/frontend/checkout.php index b2e11ac0..fc11b35a 100644 --- a/src/frontend/checkout.php +++ b/src/frontend/checkout.php @@ -22,46 +22,32 @@ --> -<!-- This page has to: +<!-- This page's main aim is to show to the customer all the accepted payments methods + and actually implementing just Taler; technically the steps are: - 1. make known to the customer this transaction ID - 2. Generate (but still NOT sending) the relevant certificate - - 3. (JavaScript) implement the Pay button for the sole Taler way. - Actually, this button's duty is just to ask for the (already generated) - certificate. - 4. (JavaScript) request the certificate associated with this - ID, through "GET /certal/" - - - --> + 1. retrieve the name of who will receive this donation -<?php - - // ID generation - $transId = rand(1, 15); + 2. show a menu with all the required payments means - // embedding trans ID in a hidden input HTML tag - //echo "<input type=\"hidden\" id=\"taler-trans-id\" value=\"$transId\" />"; + 3. create a session - // JSON certificate generation matching the product being sold - $item = $_POST['group0']; - - $toJSON = array('vendor' => "$item provider", 'item' => $item, 'price'=> rand(5, 66) . ' €', 'payUrl' => "http://" . $_SERVER['SERVER_NAME'] . "/payler/"); + 4. (JavaScript) implement the "checkout" button for the sole Taler way. + Actually, this button's duty is to notice this web portal that the customer + wants to see a certificate, and optionally to pay. + --> - // save certificate (retrievable through file naming convention) to the disk - // file_put_contents(getcwd() . "/cert." . $transId, json_encode($toJSON)); - - // time-expirable (15') tracking cookie definition - // setcookie("talkie", $transId, time()+ 15*60); - - // create session +<?php - session_start(); - $_SESSION['contract'] = json_encode($toJSON); +// ID generation +$transId = rand(1, 15); +// getting the donation receiver's name +$got_donation = $_POST['group0']; +// create session +session_start(); +$_SESSION['maydonate'] = true; @@ -74,101 +60,82 @@ <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="pay(this.form)" value="Ok"> +<input type="button" onclick="ok(this.form)" value="Ok"--> </div> </form> <script type="text/javascript"> - function pay(form){ - for(var cnt=0; cnt < form.group1.length; cnt++){ - var choice = form.group1[cnt]; +function ok(form){ + for(var cnt=0; cnt < form.group1.length; cnt++){ + var choice = form.group1[cnt]; if(choice.checked){ if(choice.value == "Taler"){ var cert = new XMLHttpRequest(); /* request certificate */ - cert.open("GET", "certal/", true); + cert.open("POST", "/cert.php", true); cert.onload = function (e) { if (cert.readyState == 4) { - if (cert.status == 200){ - /* display certificate (i.e. it sends the JSON string + if (cert.status == 200){ + /* display certificate (i.e. it sends the JSON string to the (XUL) extension) */ sendContract(cert.responseText); - } - else alert("Certificate ready state: " + cert.readyState + ", cert status: " + cert.status); } - }; + else alert("Certificate ready state: " + + cert.readyState + ", cert status: " + + cert.status); + } + }; cert.onerror = function (e){ - alert(cert.statusText); - }; + alert(cert.statusText); + }; cert.send(null); - } + } else alert(choice.value + ": NOT available "); } - } - }; + } +}; - /* the following event gets fired whenever a customer has a taler - wallet installed in his browser. In that case, the webmaster can decide - whether or not displaying Taler as a payment option */ +/* the following event gets fired whenever a customer has a taler +wallet installed in his browser. In that case, the webmaster can decide +whether or not displaying Taler as a payment option */ - function hasWallet(aEvent){ - +function hasWallet(aEvent){ + // event awaited by the wallet to change its button's color var eve = new Event('taler-currency'); - document.body.dispatchEvent(eve); - - /* old way of generating events ; left here in case of portability issues*/ - - /*var tevent = document.createEvent("Events"); - tevent.initEvent("taler-currency", true, false); - document.body.dispatchEvent(tevent);*/ + document.body.dispatchEvent(eve); - - /* embedding Taler's availability information inside the form containing - items to be paid */ + // ungrey the Taler payment option from the form var tbutton = document.getElementById("t-button-id"); tbutton.removeAttribute("disabled"); - }; +}; - function sendContract(jsonContract){ +function sendContract(jsonContract){ var cevent = new CustomEvent('taler-contract', { 'detail' : jsonContract }); - document.body.dispatchEvent(cevent); - - - - /* old way of generating events ; left here in case of portability issues*/ - - /*var cevent = document.createEvent("Events"); - cevent.initEvent("taler-contract", true, false); - document.body.dispatchEvent(cevent);*/ - + document.body.dispatchEvent(cevent); +}; - - }; - - function closeEnd(aEvent){ +function closeEnd(aEvent){ var eve = new Event("taler-unload"); - document.body.dispatchEvent(eve); + document.body.dispatchEvent(eve); - }; +}; - document.body.addEventListener("taler-wallet", hasWallet, false); - document.body.addEventListener("taler-shutdown", closeEnd, false); +// to be triggered by the wallet +document.body.addEventListener("taler-wallet", hasWallet, false); +// to be triggered by the wallet +document.body.addEventListener("taler-unload", closeEnd, false); </script> - - - </body> - </html> diff --git a/src/frontend/shopping.html b/src/frontend/shopping.html index 07c8a2e4..8853eef8 100644 --- a/src/frontend/shopping.html +++ b/src/frontend/shopping.html @@ -4,6 +4,7 @@ <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> +<div id='root' class="page-wrapper"> <!-- @@ -23,15 +24,15 @@ --> <h1>Donation Page</h1> -<p>Please choose a project and an amount you which to donate.</p> +<p>Please choose a project and an amount you whish to donate.</p> <form name="tform" action="checkout.php" method="POST"> <div id="opt-form" align="left"><br> -<input type="radio" name="group0" value="Milk"> Taler<br> -<input type="radio" name="group0" value="Butter" checked="true"> Gnunet<br> -<input type="radio" name="group0" value="Cheese"> INRIA<br><br><br> +<input type="radio" name="group0" value="Taler">Taler<br> +<input type="radio" name="group0" value="Gnunet" checked="true">Gnunet<br> +<input type="radio" name="group0" value="INRIA">INRIA<br><br><br> EUR <select id="taler-donation" name="kudos-donation"> - <option value="5">5</option> + <option value="5">10</option> </select> <input type="submit" name="keyName" value="Donate!"><br><br> @@ -39,7 +40,7 @@ EUR <select id="taler-donation" name="kudos-donation"> </form> <!--button onclick='sendContract();'>buy</a--> - +</div> </body> </html> |