diff options
author | Marcello Stanisci <marcello.stanisci@inria.fr> | 2015-07-28 17:18:25 +0200 |
---|---|---|
committer | Marcello Stanisci <marcello.stanisci@inria.fr> | 2015-07-28 17:18:25 +0200 |
commit | 9c2a5666f9f3d83aae4ed0c41b53929f64406dcc (patch) | |
tree | 5b998b3fc5d58858614b56d358c8bd8e03fc4aa1 | |
parent | 38050d737309cc226e2668b1dc6e4433a46d522d (diff) | |
download | merchant-9c2a5666f9f3d83aae4ed0c41b53929f64406dcc.tar.gz merchant-9c2a5666f9f3d83aae4ed0c41b53929f64406dcc.zip |
adapting existing merchant routines to the new website
-rw-r--r-- | src/website/new/cert.php | 29 | ||||
-rw-r--r-- | src/website/new/checkout.php | 194 | ||||
-rw-r--r-- | src/website/new/index.html | 3 | ||||
-rw-r--r-- | src/website/new/pay.php | 47 | ||||
-rw-r--r-- | src/website/new/shopping.html | 39 |
5 files changed, 312 insertions, 0 deletions
diff --git a/src/website/new/cert.php b/src/website/new/cert.php new file mode 100644 index 00000000..b0ab445a --- /dev/null +++ b/src/website/new/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/new/checkout.php b/src/website/new/checkout.php new file mode 100644 index 00000000..916858a5 --- /dev/null +++ b/src/website/new/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/new/index.html b/src/website/new/index.html index 2c02f85b..e249635a 100644 --- a/src/website/new/index.html +++ b/src/website/new/index.html | |||
@@ -26,6 +26,9 @@ | |||
26 | <p>The latest version of the Wallet is available at the following link: | 26 | <p>The latest version of the Wallet is available at the following link: |
27 | <a href="http://toy.taler.net/extension">http://toy.taler.net/extension</a> | 27 | <a href="http://toy.taler.net/extension">http://toy.taler.net/extension</a> |
28 | </p> | 28 | </p> |
29 | <p>In case you already have a wallet installed, and some coins in it, please | ||
30 | move in the <a href="shopping.html">shopping area</a> | ||
31 | </p> | ||
29 | </div> | 32 | </div> |
30 | </div> | 33 | </div> |
31 | </div> | 34 | </div> |
diff --git a/src/website/new/pay.php b/src/website/new/pay.php new file mode 100644 index 00000000..7232c2d5 --- /dev/null +++ b/src/website/new/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 | |||
44 | Payment successful, thanks! | ||
45 | |||
46 | </body> | ||
47 | </html> | ||
diff --git a/src/website/new/shopping.html b/src/website/new/shopping.html new file mode 100644 index 00000000..05b32062 --- /dev/null +++ b/src/website/new/shopping.html | |||
@@ -0,0 +1,39 @@ | |||
1 | <html> | ||
2 | <head> | ||
3 | <title>Merchant</title> | ||
4 | <link rel="stylesheet" type="text/css" href="style.css"> | ||
5 | </head> | ||
6 | <body> | ||
7 | |||
8 | <!-- | ||
9 | |||
10 | This file is part of TALER | ||
11 | Copyright (C) 2014, 2015 Christian Grothoff (and other contributing authors) | ||
12 | |||
13 | TALER is free software; you can redistribute it and/or modify it under the | ||
14 | terms of the GNU General Public License as published by the Free Software | ||
15 | Foundation; either version 3, or (at your option) any later version. | ||
16 | |||
17 | TALER is distributed in the hope that it will be useful, but WITHOUT ANY | ||
18 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||
19 | A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
20 | |||
21 | You should have received a copy of the GNU General Public License along with | ||
22 | TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> | ||
23 | |||
24 | --> | ||
25 | |||
26 | <form name="tform" action="checkout.php" method="POST"> | ||
27 | <div id="opt-form" align="left"><br> | ||
28 | <input type="radio" name="group0" value="Milk"> Milk<br> | ||
29 | <input type="radio" name="group0" value="Butter" checked="true"> Butter<br> | ||
30 | <input type="radio" name="group0" value="Cheese"> Cheese<br> | ||
31 | <input type="submit" name="keyName" value="Checkout"> | ||
32 | </div> | ||
33 | </form> | ||
34 | |||
35 | <!--button onclick='sendContract();'>buy</a--> | ||
36 | |||
37 | </body> | ||
38 | |||
39 | </html> | ||