commit bbe743a39441907b2f053a97b3e71804c7a4fbd3
parent ac2d14efbba4560bc5f20e532143852e84049970
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date: Mon, 15 Feb 2016 18:29:30 +0100
unification of offering URL for cc and Taler style payments
Diffstat:
7 files changed, 208 insertions(+), 295 deletions(-)
diff --git a/src/backend/merchant.conf b/src/backend/merchant.conf
@@ -11,7 +11,7 @@ HOSTNAME = localhost
KEYFILE = merchant.priv
# What currency does this backend accept?
-CURRENCY = KUDOS
+CURRENCY = EUR
# FIXME: to be revised
TRUSTED_MINTS = taler
diff --git a/src/frontend/index.html b/src/frontend/index.html
@@ -1,132 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
- <title>Toy "Store" - Taler Demo</title>
- <link rel="stylesheet" type="text/css" href="style.css">
- <script src="taler-presence.js" type="text/javascript">
- </script>
-</head>
-
-<body>
- <header>
- <div id="logo">
- <svg height="100" width="100">
- <circle cx="50" cy="50" r="40" stroke="darkcyan" stroke-width="6" fill="white" />
- <text x="19" y="82" font-family="Verdana" font-size="90" fill="darkcyan">S</text>
- </svg>
- </div>
-
- <h1>Toy "Store" - Taler Demo</h1>
- </header>
-
- <aside class="sidebar" id="left">
- </aside>
-
- <section id="main">
- <article>
- <h1>Welcome to the Taler Demo Shop</h1>
-
- <p>This "toy" website provides you with the ability to
- experience using the
- <a href="https://www.taler.net/">GNU Taler</a>
- payment system without using
- valuable currency. Instead, for the demonstrator we
- will be using a "toy" currency, KUDOS. However, please remember that
- Taler is designed to work with ordinary currencies, such
- as Dollars or Euros, not just toy currencies.
- <br>
- This page, <tt>shop.demo.taler.net</tt> models the behavior of a
- typical Web shop supporting Taler. The other pages of the demo,
- <tt>mint.demo.taler.net</tt> and
- <tt>bank.demo.taler.net</tt>, correspond to a Taler mint
- and bank with tight Taler integration respectively.
- </p>
- </article>
-
- <section>
-
- <article>
- <h2>Step 1: Installing the Taler wallet</h2>
- <p class="taler-installed-hide">
- First, you need to <a href="http://demo.taler.net/">install</a>
- the Taler wallet browser extension.
- </p>
- <p class="taler-installed-show">
- Congratulations, you have installed the Taler wallet correctly.
- You can now proceed with the next steps.
- </p>
- </article>
-
- <article class="taler-installed-show">
- <h2>Step 2: Withdraw coins <sup>(occasionally)</sup></h2>
-
- <p>The next step is to withdraw coins, after all you cannot
- pay with an empty wallet. To be allowed to withdraw
- coins from a mint, you first need to transfer currency to the mint
- using the normal banking system, for example by using a
- wire transfer. If the bank offers a tight integration with Taler, it
- may also support this directly over the home banking online interface.
- <br>
- For the demonstration, we have created a "bank" that
- allows you to "wire" funds (in KUDOS) to the mint simply by
- filling in the desired amount into a form. Naturally, when
- using a real bank with real money, you would have to authenticate
- and authorize the transfer.
- <br>
- Note that you would not do this step for each purchase or each shop.
- Payment with Taler is like paying
- with cash: you withdraw currency at the bank (or an ATM) and then
- pay at many merchants without having to authenticate each time.
- <br>
- So, unless you have already done so, please go ahead and withdraw
- KUDOS at the
- <a href="http://bank.demo.taler.net/" target="_blank">Demo bank</a>
- (opens in a new tab).</p>
- </article>
-
- <article class="taler-installed-show">
- <h2>Step 3: Shop! <sup>(as long as you have KUDOS left)</sup></h2>
-
- <p>Now it is time to spend your hard earned KUDOS.
- Note that we cannot really tell if you got any yet,
- as your Taler wallet balance is visible to you, but
- of course is hidden entirely from the shop.</p>
- <p>The form that follows corresponds to the shopping
- cart of a real Web shop; however, we kept it
- very simple for the demonstration.</p>
- <p>So, please choose a project and the amount of KUDOS you
- wish to donate:</p>
-
- <form name="tform" action="checkout.php" method="POST">
- <div class="participation" id="fake-shop">
- <br>
- <input type="radio" name="donation_receiver" value="Taler" checked="true">GNU Taler</input>
- <br>
- <input type="radio" name="donation_receiver" value="Tor">Tor</input>
- <br>
- <input type="radio" name="donation_receiver" value="GNUnet">GNUnet</input>
- <br>
- <select id="taler-donation" name="donation_amount">
- <option value="0.1">0.1 KUDOS</option>
- <option value="1.0">1 KUDOS</option>
- <option value="6.0">5 KUDOS (*)</option>
- <option value="10.0">10 KUDOS</option>
- </select>
- <input type="hidden" name="donation_currency" value="KUDOS"/>
- <input type="submit" name="keyName" value="Donate!"/>
- <br>
- <br>
- </div>
- </form>
- <p>(*) To make it a bit more fun, the 5 KUDOS option
- is deliberately implemented with a fault: the merchant will try to
- make you donate 6 KUDOS instead of the 5 KUDOS you got to see. But do
- not worry, you will be given the opportunity to review the
- final offer from the merchant in a window secured
- by the Taler extension. That way, you can spot the
- error before committing to an incorrect contract.</p>
- </article>
- </section>
- </section>
-</body>
-</html>
diff --git a/src/frontend/index.php b/src/frontend/index.php
@@ -0,0 +1,135 @@
+<!DOCTYPE html>
+<?php
+require_once "../frontend_lib/config.php";
+?>
+<html lang="en">
+<head>
+ <title>Toy "Store" - Taler Demo</title>
+ <link rel="stylesheet" type="text/css" href="style.css">
+ <script src="taler-presence.js" type="text/javascript">
+ </script>
+</head>
+
+<body>
+ <header>
+ <div id="logo">
+ <svg height="100" width="100">
+ <circle cx="50" cy="50" r="40" stroke="darkcyan" stroke-width="6" fill="white" />
+ <text x="19" y="82" font-family="Verdana" font-size="90" fill="darkcyan">S</text>
+ </svg>
+ </div>
+
+ <h1>Toy "Store" - Taler Demo</h1>
+ </header>
+
+ <aside class="sidebar" id="left">
+ </aside>
+
+ <section id="main">
+ <article>
+ <h1>Welcome to the Taler Demo Shop</h1>
+
+ <p>This "toy" website provides you with the ability to
+ experience using the
+ <a href="https://www.taler.net/">GNU Taler</a>
+ payment system without using
+ valuable currency. Instead, for the demonstrator we
+ will be using a "toy" currency, KUDOS. However, please remember that
+ Taler is designed to work with ordinary currencies, such
+ as Dollars or Euros, not just toy currencies.
+ <br>
+ This page, <tt>shop.demo.taler.net</tt> models the behavior of a
+ typical Web shop supporting Taler. The other pages of the demo,
+ <tt>mint.demo.taler.net</tt> and
+ <tt>bank.demo.taler.net</tt>, correspond to a Taler mint
+ and bank with tight Taler integration respectively.
+ </p>
+ </article>
+
+ <section>
+
+ <article>
+ <h2>Step 1: Installing the Taler wallet</h2>
+ <p class="taler-installed-hide">
+ First, you need to <a href="http://demo.taler.net/">install</a>
+ the Taler wallet browser extension.
+ </p>
+ <p class="taler-installed-show">
+ Congratulations, you have installed the Taler wallet correctly.
+ You can now proceed with the next steps.
+ </p>
+ </article>
+
+ <article class="taler-installed-show">
+ <h2>Step 2: Withdraw coins <sup>(occasionally)</sup></h2>
+
+ <p>The next step is to withdraw coins, after all you cannot
+ pay with an empty wallet. To be allowed to withdraw
+ coins from a mint, you first need to transfer currency to the mint
+ using the normal banking system, for example by using a
+ wire transfer. If the bank offers a tight integration with Taler, it
+ may also support this directly over the home banking online interface.
+ <br>
+ For the demonstration, we have created a "bank" that
+ allows you to "wire" funds (in KUDOS) to the mint simply by
+ filling in the desired amount into a form. Naturally, when
+ using a real bank with real money, you would have to authenticate
+ and authorize the transfer.
+ <br>
+ Note that you would not do this step for each purchase or each shop.
+ Payment with Taler is like paying
+ with cash: you withdraw currency at the bank (or an ATM) and then
+ pay at many merchants without having to authenticate each time.
+ <br>
+ So, unless you have already done so, please go ahead and withdraw
+ KUDOS at the
+ <a href="http://bank.demo.taler.net/" target="_blank">Demo bank</a>
+ (opens in a new tab).</p>
+ </article>
+
+ <article class="taler-installed-show">
+ <h2>Step 3: Shop! <sup>(as long as you have KUDOS left)</sup></h2>
+
+ <p>Now it is time to spend your hard earned KUDOS.
+ Note that we cannot really tell if you got any yet,
+ as your Taler wallet balance is visible to you, but
+ of course is hidden entirely from the shop.</p>
+ <p>The form that follows corresponds to the shopping
+ cart of a real Web shop; however, we kept it
+ very simple for the demonstration.</p>
+ <p>So, please choose a project and the amount of KUDOS you
+ wish to donate:</p>
+
+ <form name="tform" action="checkout.php" method="POST">
+ <div class="participation" id="fake-shop">
+ <br>
+ <input type="radio" name="donation_receiver" value="Taler" checked="true">GNU Taler</input>
+ <br>
+ <input type="radio" name="donation_receiver" value="Tor">Tor</input>
+ <br>
+ <input type="radio" name="donation_receiver" value="GNUnet">GNUnet</input>
+ <br>
+ <select id="taler-donation" name="donation_amount">
+ <option value="0.1">0.1 <?php echo $MERCHANT_CURRENCY; ?></option>
+ <option value="1.0">1 <?php echo $MERCHANT_CURRENCY; ?></option>
+ <option value="6.0">5 <?php echo $MERCHANT_CURRENCY; ?> (*)</option>
+ <option value="10.0">10 <?php echo $MERCHANT_CURRENCY; ?></option>
+ </select>
+ <input type="hidden" name="donation_currency" value="KUDOS"/>
+ <input type="submit" name="keyName" value="Donate!"/>
+ <br>
+ <br>
+ </div>
+ </form>
+ <p>(*) To make it a bit more fun, the 5 KUDOS option
+ is deliberately implemented with a fault: the merchant will try to
+ make you donate 6 KUDOS instead of the 5 KUDOS you got to see. But do
+ not worry, you will be given the opportunity to review the
+ final offer from the merchant in a window secured
+ by the Taler extension. That way, you can spot the
+ error before committing to an incorrect contract.</p>
+ </article>
+ </section>
+ </section>
+</body>
+</html>
diff --git a/src/frontend_blog/essay_contract.php b/src/frontend_blog/essay_contract.php
@@ -25,6 +25,7 @@
*/
include("../frontend_lib/merchants.php");
include("../frontend_lib/util.php");
+include("../frontend_lib/config.php");
include("./blog_lib.php");
session_start();
$article = get($_GET['article']);
@@ -41,10 +42,9 @@ $now = new DateTime('now');
$teaser = get_teaser($article);
$amount_value = 0;
$amount_fraction = 50000;
-$currency = "EUR";
$teatax = array ('value' => 1,
'fraction' => 0,
- 'currency' => $currency);
+ 'currency' => $MERCHANT_CURRENCY);
$transaction_id = rand(0, 1001);
// Include all information so we can
// restore the contract without storing it
@@ -53,7 +53,7 @@ $fulfillment_url = url_rel("essay_fulfillment.php")
//file_put_contents("/tmp/debg1", $fulfillment_url);
$contract_json = generate_contract($amount_value,
$amount_fraction,
- $currency,
+ $MERCHANT_CURRENCY,
$transaction_id,
trim($teaser->nodeValue),
$p_id,
diff --git a/src/frontend_blog/essay_offer.php b/src/frontend_blog/essay_offer.php
@@ -1,13 +1,30 @@
<!DOCTYPE html>
<html>
-<head>
-<script type="text/javascript">
+<body onload="signal_taler_wallet_onload()">
+<?php
+ include("../frontend_lib/merchants.php");
+ include("../frontend_lib/util.php");
+ include("./blog_lib.php");
+ session_start();
+ $article = get($_GET['article']);
+ if (null == $article){
+ echo "Please land here just to buy articles";
+ die();
+ }
+ echo "<h3>No Taler installed</h3>";
+ echo "<p>activate it or pay by <a href='/cc_payment.php?article=$article'>credit card</a></p>";
+ echo "<p id=article-name style='display: none;'>$article</input>";
+?>
+</body>
+<script type="text/javascript">
+
function handle_contract(json_contract) {
var cEvent = new CustomEvent('taler-contract',
{detail: json_contract});
document.dispatchEvent(cEvent);
};
+
function get_contract(article) {
var contract_request = new XMLHttpRequest();
@@ -32,22 +49,29 @@
+ contract_request.statusText);
};
contract_request.send();
-}
-</script>
-</head>
-<body>
-<?php
+ }
+
+ function has_taler_wallet_cb(aEvent)
+ {
+ var article = document.getElementById('article-name');
+ get_contract(article.firstChild.nodeValue);
+ };
- include("../frontend_lib/merchants.php");
- include("../frontend_lib/util.php");
- include("./blog_lib.php");
- session_start();
- $article = get($_GET['article']);
- if (null == $article){
- echo "Please land here just to buy articles";
- die();
- }
- echo "<script>get_contract('$article');</script>"
-?>
-</body>
+ function signal_taler_wallet_onload()
+ {
+ var eve = new Event('taler-probe');
+ document.dispatchEvent(eve);
+ };
+
+ 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);
+
+</script>
</html>
diff --git a/src/frontend_blog/index.html b/src/frontend_blog/index.html
@@ -40,7 +40,7 @@
<article class="articles">
<ul style="list-style-type:none">
<li>
- <a href="/cc_payment.php?article=fs-essay" class="read-more" id="fs-essay">
+ <a href="/essay_offer.php?article=fs-essay" class="read-more" id="fs-essay">
<div class="teasers_item">
<h3>What is Free Software</h3>
<p>
@@ -57,144 +57,5 @@
</section>
</section>
</body>
-<script type="text/javascript">
-/* @licstart The following is the entire license notice for the
- JavaScript code in this page.
- Copyright (C) 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 2.1 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 2.1 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.
- */
-
-/* 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)
-{
- var cEvent = new CustomEvent('taler-contract', { detail: json_contract });
-
- document.dispatchEvent(cEvent);
-};
-
-function taler_pay(article)
-{
- var contract_request = new XMLHttpRequest();
-
- /* Note that the URL we give here is specific to the Demo-shop
- and not required by the protocol: each web shop can
- have its own way of generating and transmitting the
- 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", "essay_contract.php?article=" + article, true);
- 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("contract here");
- console.log("response text:", contract_request.responseText);
- 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. */
- alert("Failure to download contract from merchant " +
- "(" + contract_request.status + "):\n" +
- contract_request.responseText);
- }
- }
- };
- 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);
-}
-
-/* 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)
-{
- console.log("has taler wallet");
- // make "read more" trigger Taler payment
- var articles_links = document.getElementsByClassName("read-more");
- for(var i=0; i < articles_links.length; i++)
- //console.log(link);
- articles_links[i].setAttribute("href", "/essay_offer.php?article=" + articles_links[i].id);
-};
-
-/* 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 rm = document.getElementById("read-more");
- rm.setAttribute("href", "cc_payment.html");
-};
-
-
-/* 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>
</html>
diff --git a/src/frontend_lib/config.php b/src/frontend_lib/config.php
@@ -0,0 +1,25 @@
+<?php
+
+$explicit_currency = false;
+//$explicit_currency = "EUR";
+
+$host = $_SERVER["HTTP_HOST"];
+switch ($host) {
+case "blog.demo.taler.net":
+case "show.demo.taler.net":
+ $MERCHANT_CURRENCY = "KUDOS";
+ break;
+case "blog.test.taler.net":
+case "shop.test.taler.net":
+ $MERCHANT_CURRENCY = "PUDOS";
+ break;
+default:
+ if ($explicit_currency != false)
+ $MERCHANT_CURRENCY = $explicit_currency;
+ else {
+ http_response_code (500);
+ echo "<p>Bank configuration error: No currency for domain $host</p>\n";
+ die();
+ }
+}
+?>