aboutsummaryrefslogtreecommitdiff
path: root/src/website/new/checkout.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/website/new/checkout.php')
-rw-r--r--src/website/new/checkout.php194
1 files changed, 194 insertions, 0 deletions
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>