aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <marcello.stanisci@inria.fr>2015-05-26 17:56:54 +0200
committerMarcello Stanisci <marcello.stanisci@inria.fr>2015-05-26 17:56:54 +0200
commitcfb8b5fc8000a58abfe16879cf3332d2d0aca8b7 (patch)
tree39b82e24db5c68ec4c3dcd28276460fb1e0ae563
parent8bd435d7ee73bd9cfc3265e161d5e847aac1f5ee (diff)
downloadmerchant-cfb8b5fc8000a58abfe16879cf3332d2d0aca8b7.tar.gz
merchant-cfb8b5fc8000a58abfe16879cf3332d2d0aca8b7.zip
minimal merchant website added
-rw-r--r--src/website/README24
-rw-r--r--src/website/cert.php29
-rw-r--r--src/website/checkout.php194
-rw-r--r--src/website/index.html38
-rw-r--r--src/website/pay.php47
5 files changed, 332 insertions, 0 deletions
diff --git a/src/website/README b/src/website/README
new file mode 100644
index 00000000..b36911ad
--- /dev/null
+++ b/src/website/README
@@ -0,0 +1,24 @@
1This directory contains the files needed to implment a simple/debug merchant website.
2
3Only tested on nginx. To run the website, it suffices to have all the files in the same
4directory, to have PHP enabled, and to set the following two redirections:
5
61. your_site/certal/ => your_site/cert.php
72. your_site/payler/ => your_site/pay.php
8
9File |What implements
10--------------------------------
11o index.html | The "negotiation" view, that is the form
12 that allows the user to choose the product to buy.
13
14o checkout.php | The "payment selection" that is the form
15 that allows the user to choose the payment method he wishes to use.
16 It also implements the request of certificate and its showing as a
17 popup window (by JavaScript in it). For debugging purposes, it has a
18 certificate hardcoded in it.
19
20o cert.php | Replies with a JSON certificate that is held in a 'session' variable.
21
22o pay.php | Actual receiving of money, plus it gives back a "fullfillment" page
23 that informs the user of his well ended deal.
24
diff --git a/src/website/cert.php b/src/website/cert.php
new file mode 100644
index 00000000..b0ab445a
--- /dev/null
+++ b/src/website/cert.php
@@ -0,0 +1,29 @@
1<?php
2
3/*
4
5 This file is part of TALER
6 Copyright (C) 2014, 2015 Christian Grothoff (and other contributing authors)
7
8 TALER is free software; you can redistribute it and/or modify it under the
9 terms of the GNU General Public License as published by the Free Software
10 Foundation; either version 3, or (at your option) any later version.
11
12 TALER is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License along with
17 TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
18
19*/
20
21// recover the session
22 session_start();
23 if(!isset($_SESSION['contract'])){
24 http_response_code(404);
25 echo "Sorry page..";
26 }
27 else echo $_SESSION['contract'];
28
29?>
diff --git a/src/website/checkout.php b/src/website/checkout.php
new file mode 100644
index 00000000..916858a5
--- /dev/null
+++ b/src/website/checkout.php
@@ -0,0 +1,194 @@
1<html>
2<head>
3<title>Choose payment method</title>
4</head>
5<body>
6
7<!--
8
9 This file is part of TALER
10 Copyright (C) 2014, 2015 Christian Grothoff (and other contributing authors)
11
12 TALER is free software; you can redistribute it and/or modify it under the
13 terms of the GNU General Public License as published by the Free Software
14 Foundation; either version 3, or (at your option) any later version.
15
16 TALER is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License along with
21 TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
22
23-->
24
25<!-- This page has to:
26
27 1. make known to the customer this transaction ID
28
29 2. Generate the relevant certificate
30
31 3. (JavaScript) implement the Pay button implementing only
32 the Taler payment
33
34 4. (JavaScript) request the certificate associated with this
35 ID, through "GET /certal/"
36
37
38 -->
39
40<?php
41
42 // ID generation
43 $transId = rand(1, 15);
44
45 // embedding trans ID in a hidden input HTML tag
46 //echo "<input type=\"hidden\" id=\"taler-trans-id\" value=\"$transId\" />";
47
48 // JSON certificate generation matching the product being sold
49 $item = $_POST['group0'];
50
51 $toJSON = array('vendor' => "$item provider", 'item' => $item, 'price'=> rand(5, 66) . ' €', 'payUrl' => "http://" . $_SERVER['SERVER_NAME'] . "/payler/");
52
53
54 // save certificate (retrievable through file naming convention) to the disk
55 // file_put_contents(getcwd() . "/cert." . $transId, json_encode($toJSON));
56
57 // time-expirable (15') tracking cookie definition
58 // setcookie("talkie", $transId, time()+ 15*60);
59
60 // create session
61
62 session_start();
63 $_SESSION['contract'] = json_encode($toJSON);
64
65
66
67
68?>
69
70<form name="tform" action="" method="POST">
71<div id="opt-form" align="left"><br>
72<input type="radio" name="group1" value="Lisa">Lisa<br>
73<input type="radio" name="group1" value="You Card" checked>You Card<br>
74<input type="radio" name="group1" value="Card Me">Card Me<br>
75<input id="t-button-id" type="radio" name="group1" value="Taler" disabled="true">Taler<br>
76<input type="button" onclick="pay(this.form)" value="Ok">
77</div>
78</form>
79
80<script type="text/javascript">
81
82
83 function pay(form){
84
85 for(var cnt=0; cnt < form.group1.length; cnt++){
86
87 var choice = form.group1[cnt];
88
89 if(choice.checked){
90
91 if(choice.value == "Taler"){
92
93 var cert = new XMLHttpRequest();
94
95 /* request certificate */
96 cert.open("GET", "certal/", true);
97
98 cert.onload = function (e) {
99
100 if (cert.readyState == 4) {
101
102 if (cert.status == 200){
103
104 /* display certificate (i.e. it sends the JSON string
105 to the (XUL) extension) */
106 sendContract(cert.responseText);
107
108 }
109
110
111
112 else alert("Certificate ready state: " + cert.readyState + ", cert status: " + cert.status);
113
114 }
115 };
116
117 cert.onerror = function (e){
118 console.error(cert.statusText);
119 };
120
121 cert.send(null);
122
123 }
124
125 else alert(choice.value + ": NOT available ");
126
127 }
128 }
129
130
131 };
132
133
134
135
136 /* the following event gets fired whenever a customer has a taler
137 wallet installed in his browser. In that case, the webmaster can decide
138 whether or not displaying Taler as a payment option */
139
140 function hasWallet(aEvent){
141
142 var eve = new Event('taler-currency');
143 document.body.dispatchEvent(eve);
144
145 /* old way of generating events ; left here in case of portability issues*/
146
147 /*var tevent = document.createEvent("Events");
148 tevent.initEvent("taler-currency", true, false);
149 document.body.dispatchEvent(tevent);*/
150
151
152 /* embedding Taler's availability information inside the form containing
153 items to be paid */
154 var tbutton = document.getElementById("t-button-id");
155 tbutton.removeAttribute("disabled");
156 };
157
158
159
160 function sendContract(jsonContract){
161
162 var cevent = new CustomEvent('taler-contract', { 'detail' : jsonContract });
163 document.body.dispatchEvent(cevent);
164
165
166
167 /* old way of generating events ; left here in case of portability issues*/
168
169 /*var cevent = document.createEvent("Events");
170 cevent.initEvent("taler-contract", true, false);
171 document.body.dispatchEvent(cevent);*/
172
173
174
175 };
176
177 function closeEnd(aEvent){
178
179 var eve = new Event("taler-unload");
180 document.body.dispatchEvent(eve);
181
182 };
183
184 document.body.addEventListener("taler-wallet", hasWallet, false);
185 document.body.addEventListener("taler-shutdown", closeEnd, false);
186
187
188</script>
189
190
191
192</body>
193
194</html>
diff --git a/src/website/index.html b/src/website/index.html
new file mode 100644
index 00000000..b5aace31
--- /dev/null
+++ b/src/website/index.html
@@ -0,0 +1,38 @@
1<html>
2<head>
3<title>Merchant</title>
4</head>
5<body>
6
7<!--
8
9 This file is part of TALER
10 Copyright (C) 2014, 2015 Christian Grothoff (and other contributing authors)
11
12 TALER is free software; you can redistribute it and/or modify it under the
13 terms of the GNU General Public License as published by the Free Software
14 Foundation; either version 3, or (at your option) any later version.
15
16 TALER is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License along with
21 TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
22
23-->
24
25<form name="tform" action="checkout.php" method="POST">
26<div id="opt-form" align="left"><br>
27<input type="radio" name="group0" value="Milk"> Milk<br>
28<input type="radio" name="group0" value="Butter" checked="true"> Butter<br>
29<input type="radio" name="group0" value="Cheese"> Cheese<br>
30<input type="submit" name="keyName" value="Checkout">
31</div>
32</form>
33
34<!--button onclick='sendContract();'>buy</a-->
35
36</body>
37
38</html>
diff --git a/src/website/pay.php b/src/website/pay.php
new file mode 100644
index 00000000..7232c2d5
--- /dev/null
+++ b/src/website/pay.php
@@ -0,0 +1,47 @@
1<html>
2<head>
3<title>Fullfillment page</title>
4</head>
5<body>
6
7
8<?php
9
10/*
11
12 This file is part of TALER
13 Copyright (C) 2014, 2015 Christian Grothoff (and other contributing authors)
14
15 TALER is free software; you can redistribute it and/or modify it under the
16 terms of the GNU General Public License as published by the Free Software
17 Foundation; either version 3, or (at your option) any later version.
18
19 TALER is distributed in the hope that it will be useful, but WITHOUT ANY
20 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
21 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License along with
24 TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
25
26*/
27
28
29 /*
30// recover the session
31 session_start();
32 if(!isset($_SESSION['contract'])){
33// http_response_code(404);
34 echo "Sorry..";
35 }
36 else echo "Paid";
37
38 session_destroy();
39
40
41*/
42?>
43
44Payment successful, thanks!
45
46</body>
47</html>