aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/checkout.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend/checkout.php')
-rw-r--r--src/frontend/checkout.php174
1 files changed, 174 insertions, 0 deletions
diff --git a/src/frontend/checkout.php b/src/frontend/checkout.php
new file mode 100644
index 00000000..b2e11ac0
--- /dev/null
+++ b/src/frontend/checkout.php
@@ -0,0 +1,174 @@
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 (but still NOT sending) the relevant certificate
30
31 3. (JavaScript) implement the Pay button for the sole Taler way.
32 Actually, this button's duty is just to ask for the (already generated)
33 certificate.
34
35 4. (JavaScript) request the certificate associated with this
36 ID, through "GET /certal/"
37
38
39 -->
40
41<?php
42
43 // ID generation
44 $transId = rand(1, 15);
45
46 // embedding trans ID in a hidden input HTML tag
47 //echo "<input type=\"hidden\" id=\"taler-trans-id\" value=\"$transId\" />";
48
49 // JSON certificate generation matching the product being sold
50 $item = $_POST['group0'];
51
52 $toJSON = array('vendor' => "$item provider", 'item' => $item, 'price'=> rand(5, 66) . ' €', 'payUrl' => "http://" . $_SERVER['SERVER_NAME'] . "/payler/");
53
54
55 // save certificate (retrievable through file naming convention) to the disk
56 // file_put_contents(getcwd() . "/cert." . $transId, json_encode($toJSON));
57
58 // time-expirable (15') tracking cookie definition
59 // setcookie("talkie", $transId, time()+ 15*60);
60
61 // create session
62
63 session_start();
64 $_SESSION['contract'] = json_encode($toJSON);
65
66
67
68
69?>
70
71<form name="tform" action="" method="POST">
72<div id="opt-form" align="left"><br>
73<input type="radio" name="group1" value="Lisa">Lisa<br>
74<input type="radio" name="group1" value="You Card" checked>You Card<br>
75<input type="radio" name="group1" value="Card Me">Card Me<br>
76<input id="t-button-id" type="radio" name="group1" value="Taler" disabled="true">Taler<br>
77<input type="button" onclick="pay(this.form)" value="Ok">
78</div>
79</form>
80
81<script type="text/javascript">
82
83 function pay(form){
84 for(var cnt=0; cnt < form.group1.length; cnt++){
85 var choice = form.group1[cnt];
86 if(choice.checked){
87 if(choice.value == "Taler"){
88 var cert = new XMLHttpRequest();
89 /* request certificate */
90 cert.open("GET", "certal/", true);
91 cert.onload = function (e) {
92 if (cert.readyState == 4) {
93 if (cert.status == 200){
94 /* display certificate (i.e. it sends the JSON string
95 to the (XUL) extension) */
96 sendContract(cert.responseText);
97 }
98 else alert("Certificate ready state: " + cert.readyState + ", cert status: " + cert.status);
99 }
100 };
101
102 cert.onerror = function (e){
103 alert(cert.statusText);
104 };
105
106 cert.send(null);
107 }
108 else alert(choice.value + ": NOT available ");
109 }
110 }
111 };
112
113
114
115
116 /* the following event gets fired whenever a customer has a taler
117 wallet installed in his browser. In that case, the webmaster can decide
118 whether or not displaying Taler as a payment option */
119
120 function hasWallet(aEvent){
121
122 var eve = new Event('taler-currency');
123 document.body.dispatchEvent(eve);
124
125 /* old way of generating events ; left here in case of portability issues*/
126
127 /*var tevent = document.createEvent("Events");
128 tevent.initEvent("taler-currency", true, false);
129 document.body.dispatchEvent(tevent);*/
130
131
132 /* embedding Taler's availability information inside the form containing
133 items to be paid */
134 var tbutton = document.getElementById("t-button-id");
135 tbutton.removeAttribute("disabled");
136 };
137
138
139
140 function sendContract(jsonContract){
141
142 var cevent = new CustomEvent('taler-contract', { 'detail' : jsonContract });
143 document.body.dispatchEvent(cevent);
144
145
146
147 /* old way of generating events ; left here in case of portability issues*/
148
149 /*var cevent = document.createEvent("Events");
150 cevent.initEvent("taler-contract", true, false);
151 document.body.dispatchEvent(cevent);*/
152
153
154
155 };
156
157 function closeEnd(aEvent){
158
159 var eve = new Event("taler-unload");
160 document.body.dispatchEvent(eve);
161
162 };
163
164 document.body.addEventListener("taler-wallet", hasWallet, false);
165 document.body.addEventListener("taler-shutdown", closeEnd, false);
166
167
168</script>
169
170
171
172</body>
173
174</html>