summaryrefslogtreecommitdiff
path: root/src/frontend/checkout.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend/checkout.php')
-rw-r--r--src/frontend/checkout.php169
1 files changed, 44 insertions, 125 deletions
diff --git a/src/frontend/checkout.php b/src/frontend/checkout.php
index ec9245f8..83e5ac16 100644
--- a/src/frontend/checkout.php
+++ b/src/frontend/checkout.php
@@ -3,34 +3,35 @@
<head>
<title>Toy Store - Payment method - Taler Demo</title>
<link rel="stylesheet" type="text/css" href="style.css">
- <script>
- /*
- @licstart The following is the entire license notice for the
- JavaScript code in this page.
-
- Copyright (C) 2014,2015 GNUnet e.V.
-
- The JavaScript code in this page is free software: you can
- redistribute it and/or modify it under the terms of the GNU
- Lesser General Public License (GNU LGPL) as published by the
- Free Software
- Foundation, either version 3 of the License, or (at your option)
- any later version. The code is distributed WITHOUT ANY WARRANTY;
- without even the implied warranty of MERCHANTABILITY or FITNESS
- FOR A PARTICULAR PURPOSE. See the GNU LGPL for more details.
-
- As additional permission under GNU LGPL version 3 section 7, you
- may distribute non-source (e.g., minimized or compacted) forms of
- that code without the copy of the GNU LGPL normally required by
- section 4, provided you include this license notice and a URL
- through which recipients can access the Corresponding Source.
-
- @licend The above is the entire license notice
- for the JavaScript code in this page.
- */
- </script>
+ <script>
+ /*
+ @licstart The following is the entire license notice for the
+ JavaScript code in this page.
+
+ Copyright (C) 2014,2015 GNUnet e.V.
+
+ The JavaScript code in this page is free software: you can
+ redistribute it and/or modify it under the terms of the GNU
+ Lesser General Public License (GNU LGPL) as published by the
+ Free Software
+ Foundation, either version 3 of the License, or (at your option)
+ any later version. The code is distributed WITHOUT ANY WARRANTY;
+ without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU LGPL for more details.
+
+ As additional permission under GNU LGPL version 3 section 7, you
+ may distribute non-source (e.g., minimized or compacted) forms of
+ that code without the copy of the GNU LGPL normally required by
+ section 4, provided you include this license notice and a URL
+ through which recipients can access the Corresponding Source.
+
+ @licend The above is the entire license notice
+ for the JavaScript code in this page.
+ */
+ </script>
+ <script type="application/javascript" src="taler-presence.js"></script>
</head>
-<body onload="signal_taler_wallet_onload()">
+<body>
<!--
This main goal of this page is to show to the customer all the accepted
payments methods and actually implementing just Taler; technically
@@ -115,7 +116,7 @@
<input type="radio" name="payment_system" value="cardme">Card Me</input>
<br/>
<input type="radio" name="payment_system" value="taler"
- id="taler-radio-button-id" disabled="true">Taler</input>
+ id="taler-radio-button-id" class="taler-installed-enable">Taler</input>
<br/>
<input type="button" onclick="pay(this.form)" value="Ok"></input>
</div>
@@ -129,18 +130,15 @@
/* This function is called from "taler_pay" after
we downloaded the JSON contract from the merchant.
We now need to pass it to the extension. */
-function handle_contract(json_contract)
-{
+function handle_contract(json_contract) {
var cEvent = new CustomEvent('taler-contract', { detail: json_contract });
-
document.dispatchEvent(cEvent);
};
/* Trigger Taler contract generation on the server, and pass the
contract to the extension once we got it. */
-function taler_pay(form)
-{
+function taler_pay(form) {
var contract_request = new XMLHttpRequest();
/* Note that the URL we give here is specific to the Demo-shop
@@ -149,19 +147,14 @@ function taler_pay(form)
contract, there just must be a way to get the contract
and to pass it to the wallet when the user selects 'Pay'. */
contract_request.open("GET", "generate_taler_contract.php", true);
- contract_request.onload = function (e)
- {
- if (contract_request.readyState == 4)
- {
- if (contract_request.status == 200)
- {
+ contract_request.onload = function (e) {
+ if (contract_request.readyState == 4) {
+ if (contract_request.status == 200) {
/* display contract_requestificate (i.e. it sends the JSON string
to the extension) alert (contract_request.responseText); */
console.log("response text:", contract_request.responseText);
- //handle_contract(contract_request.responseText);
- }
- else
- {
+ handle_contract(contract_request.responseText);
+ } else {
/* There was an error obtaining the contract from the merchant,
obviously this should not happen. To keep it simple, we just
alert the user to the error. */
@@ -171,14 +164,13 @@ function taler_pay(form)
}
}
};
- contract_request.onerror = function (e)
- {
+ contract_request.onerror = function (e) {
/* There was an error obtaining the contract from the merchant,
obviously this should not happen. To keep it simple, we just
alert the user to the error. */
alert("Failure requesting the contract:\n" + contract_request.statusText);
};
- contract_request.send(null);
+ contract_request.send();
}
@@ -186,89 +178,16 @@ function taler_pay(form)
'Ok' button. We are now supposed to trigger the
"corret" payment system logic. For this demo, we
only handle "taler". */
-function pay(form)
-{
- for (var cnt=0; cnt < form.payment_system.length; cnt++)
- {
- var choice = form.payment_system[cnt];
- if (choice.checked)
- {
- if (choice.value == "taler")
- {
+function pay(form) {
+ var choice = form.elements["payment_system"].value;
+ if (choice == "taler") {
taler_pay(form);
- }
- else
- {
- alert(choice.value + ": NOT available in this demo!");
- }
- }
+ }
+ else {
+ alert("You selected '" +choice.value + "', but we do not support this payment system in the demo".);
}
};
-
-/* 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 to display/enable Taler as a payment option in the dialog. */
-function has_taler_wallet_cb(aEvent)
-{
- // enable the Taler payment option from the form
- var tbutton = document.getElementById("taler-radio-button-id");
- tbutton.removeAttribute("disabled");
- tbutton.setAttribute("checked", "true");
-};
-
-
-/* Function called when the Taler extension was unloaded;
- here we disable the Taler option and check "Lisa", as
- some "valid" option should always be selected. */
-function taler_wallet_unload_cb(aEvent)
-{
- var tbutton = document.getElementById("taler-radio-button-id");
- tbutton.setAttribute("disabled", "true");
- var lbutton = document.getElementById("lisa-radio-button-id");
- lbutton.setAttribute("checked", "true");
-};
-
-
-/* The merchant signals its taler-friendlyness to the wallet,
- thereby causing the wallet to make itself more visible in the menu.
- This function should be called both when the page is loaded
- (i.e. via body's onload) and when we receive a "taler-load" signal
- (as the extension may be loaded/enabled after the page was loaded) */
-function signal_taler_wallet_onload()
-{
- var eve = new Event('taler-probe');
- document.dispatchEvent(eve);
-};
-
-
-// function included to be run to test the page despite a
-// wallet not being present in the browser. Enables the
-// Taler option. NOT needed in real deployments.
-function test_without_wallet(){
- var tbutton = document.getElementById("taler-radio-button-id");
- tbutton.removeAttribute("disabled");
-};
-
-
-// /////////////// Main logic run first ////////////////////////
-
-// Register event to be triggered by the wallet as a response to our
-// first event
-document.addEventListener("taler-wallet-present",
- has_taler_wallet_cb,
- false);
-
-// Register event to be triggered by the wallet when it gets enabled while
-// the user is on the payment page
-document.addEventListener("taler-load",
- signal_taler_wallet_onload,
- false);
-
-// Register event to be triggered by the wallet when it is unloaded
-document.addEventListener("taler-unload",
- taler_wallet_unload_cb,
- false);
</script>
</body>
</html>