diff options
Diffstat (limited to 'src/frontend/checkout.php')
-rw-r--r-- | src/frontend/checkout.php | 137 |
1 files changed, 52 insertions, 85 deletions
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> |