-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
441 lines (433 loc) · 21.7 KB
/
index.html
File metadata and controls
441 lines (433 loc) · 21.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
<!DOCTYPE html>
<html lang="en">
<head>
<title>w0bm stickers</title>
<link rel="stylesheet" href="style.css"/>
<link rel="icon" href="//w0bm.com/favicon.png"/>
<script src="https://www.google.com/recaptcha/api.js"></script>
<script src="https://www.paypalobjects.com/api/checkout.js" data-version-4></script>
<script src="form-submit.js"></script>
<script src="country-select.js"></script>
<script src="flash.js"></script>
<script src="order_overview.js"></script>
<script>
class Overlay {
constructor() {
this.main = document.querySelector("div#overlay");
this.veil = document.querySelector("div#overlay_veil");
this.spinner = document.querySelector("div#overlay_spinner");
this.payment = document.querySelector("div#payment");
this.order_status = document.querySelector("div#order_status");
this.allow_hide = false;
this.veil.addEventListener("click", () => {
if(this.allow_hide) {
this.main.hidden = true;
this.allow_hide = false;
}
});
}
set_allow_hide(b) {
this.allow_hide = b;
}
show_spinner() {
this.payment.hidden = true;
this.order_status.hidden = true;
this.main.hidden = false;
this.spinner.hidden = false;
}
show_payment() {
this.spinner.hidden = true;
this.order_status.hidden = true;
this.main.hidden = false;
this.payment.hidden = false;
}
show_order_status() {
this.spinner.hidden = true;
this.payment.hidden = true;
this.main.hidden = false;
this.order_status.hidden = false;
}
hide() {
this.main.hidden = true;
this.allow_hide = false;
}
}
let flash, order_id, overlay;
document.addEventListener("DOMContentLoaded", () => {
flash = window.init_flash();
overlay = new Overlay();
});
const add_payment_result = (cl, warn) => {
const prev_result = document.querySelector("p#payment_result");
let el = document.createElement("p");
el.id = "payment_result";
el.classList.add(cl);
el.textContent =
cl === "error"
? "Payment cancelled!"
: "Payment executed successfully!";
if(warn)
el.innerHTML
= el.innerHTML
+ `<br/><span class="payment_warn">${warn}</span>`;
if(prev_result)
prev_result.remove();
if(cl === "success")
document.querySelector("div#paypal_payment").hidden = true;
overlay.payment.appendChild(el);
};
const toggle_order_submit = val => document.querySelector('form[action="add_order.php"] button[type="submit"]').disabled = val;
const toggle_status_submit = val => document.querySelector('form[action="order_status.php"] button[type="submit"]').disabled = val;
function enable_order_submit() {
toggle_order_submit(false);
}
function disable_order_submit() {
toggle_order_submit(true);
}
function enable_status_submit() {
toggle_status_submit(false);
}
function disable_status_submit() {
toggle_status_submit(true);
}
paypal.Button.render({
payment: () => new paypal.Promise((resolve, reject) => {
let data = new FormData();
data.set("order_id", order_id);
fetch("create_payment.php", {
method: "POST",
body: data
}).then(async res => {
const json = await res.json();
if(res.ok && res.status === 200)
resolve(json.data.payment_id);
else
reject(json);
}).catch(reject);
}),
onAuthorize: data => {
overlay.show_spinner();
let formdata = new FormData();
formdata.set("order_id", order_id);
formdata.set("payer_id", data.payerID);
formdata.set("payment_id", data.paymentID);
fetch("execute_payment.php", {
method: "POST",
body: formdata
}).then(async res => {
overlay.show_payment();
const json = await res.json();
if(res.ok) {
flash({
type: "success",
msg: "Payment executed successfully!"
});
add_payment_result(
"success",
(json.error && json.error.msg === "payment_insertion_failed")
? "Unfortunately we were not able to store your payment on our side.<br/>Please notify an administrator and sorry for the inconvenience."
: null
);
overlay.set_allow_hide(true);
}
else {
flash({
type: "error",
msg: "Payment execution failed!"
});
add_payment_result("error");
}
}).catch(err => {
overlay.show_payment();
flash({
type: "error",
msg: "Payment execution failed!"
});
add_payment_result("error");
});
},
onCancel: data => {
flash({
type: "error",
msg: "The payment has been cancelled!"
});
add_payment_result("error");
},
style: {
size: "medium",
color: "blue",
shape: "rect"
}
}, "div#paypal_payment");
function order_submit(form) {
document.querySelector("div#overlay").hidden = false;
overlay.show_spinner();
}
function order_data(res, json, form) {
overlay.show_payment();
if(res.status === 400 && json.error.msg === "invalid_field_value") {
flash({
type: "error",
msg: `Invalid value for ${json.error.subject}`
});
overlay.hide();
}
else if(res.status === 403 && json.error.msg === "captcha_verification_failed") {
flash({
type: "error",
msg: "Couldn't verify captcha! Resetting..."
});
overlay.hide();
grecaptcha.reset();
disable_order_submit();
}
else if(res.status === 403 && json.error.msg === "ordering_disabled") {
flash({
type: "error",
msg: "Ordering is not possible anymore!"
});
overlay.hide();
}
else if(res.status === 500 && json.error.msg === "captcha_verification_failed") {
flash({
type: "error",
msg: "Couldn't verify captcha! This is an internal error, please notify an administrator!"
});
overlay.hide();
}
else if(res.ok && json.success) {
flash({
type: "success",
msg: "Your data has been saved."
});
grecaptcha.reset();
disable_order_submit();
document.querySelector("span#order_id").textContent = order_id = json.data.order_id;
overlay.show_payment();
}
else {
flash({
type: "error",
msg: "Oops, something internal broke. Please notify an administrator: https:\/\/w0bm.com/contact\n"
+ `${res.status} ${res.statusText}\n${JSON.stringify(json)}`
});
overlay.hide();
}
}
function form_error(error, form) {
overlay.hide();
flash({
type: "error",
msg: "submit error: " + JSON.stringify(error)
});
console.error(error);
}
function status_submit(form) {
overlay.show_spinner();
}
function status_data(res, json, form) {
if(res.status === 400 && json.error.msg === "invalid_field_value") {
flash({
type: "error",
msg: "Invalid value for " + json.error.subject
});
overlay.hide();
}
else if(res.status === 403 && json.error.msg === "captcha_verification_failed") {
flash({
type: "error",
msg: "Captcha verification failed!"
});
overlay.hide();
}
else if(res.status === 405) {
flash({
type: "error",
msg: "Apparently your browser is unable to send post requests..."
});
overlay.hide();
}
else if(res.status === 500) {
flash({
type: "error",
msg: "Something internal broke/went wrong: " + JSON.stringify(json.error)
});
console.error(res, json, form);
}
else if(res.ok && json.success) {
if(json.error) {
flash({
type: "error",
msg: "No order with that ID found!"
});
overlay.hide();
}
else {
document.querySelector("div#order_status span.not_paid").hidden = json.data.paid;
document.querySelector("div#order_status span.not_shipped").hidden = !!json.data.shipments.length;
document.querySelector("table#shipments").hidden = !json.data.shipments.length;
const tbody = document.querySelector("table#shipments tbody");
json.data.shipments.forEach(shipment => {
let row = document.createElement("tr");
let col1 = document.createElement("td"), col2 = document.createElement("td");
col1.textContent = shipment.shipping_company;
col2.textContent = shipment.shipment_id;
row.appendChild(col1);
row.appendChild(col2);
tbody.appendChild(row);
});
overlay.show_order_status();
overlay.set_allow_hide(true);
}
}
}
</script>
</head>
<body>
<div id="overlay" hidden>
<div id="overlay_veil"></div>
<div id="overlay_content">
<div id="overlay_spinner" hidden>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div id="payment" hidden>
<p>Your order id is: <span id="order_id"></span><p>
<p>You should save it somewhere, you'll be able to get your tracking number with it.</p>
<p>You can now pay your order:</p>
<div id="paypal_payment"></div>
</div>
<div id="order_status" hidden>
<p>Your order has <span class="not_paid" hidden>not </span>been paid.</p>
<p>Your order has <span class="not_shipped" hidden>not </span>been shipped.</p>
<table id="shipments" hidden>
<caption>Shipments:</caption>
<thead>
<tr>
<th>Shipping Company</th>
<th>Tracking Code</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
<div id="flash"> </div>
<div id="content">
<h1>w0bm stickers</h1>
<div class="box">
<img src="https://w0bm.com/w0bm%20fixed.svg" alt="w0bm logo"/>
<h3>Hello good people of the internet, you have come to the right place if you always wanted to have a useless and overpriced piece of glued paper to put on your laptop!</h3>
<h2>Backstory</h2>
<p>The idea came first in 2015 when sirx was at the Chaos Communication Congress (32C3) and some very nice dudes had their own stickerprinter with them and printed stickers for us in exchange for a small and voluntary donation, so sirx decided to print some w0bm stickers and offered them to the peeps in the IRC that they can have some if they come to the CCH and pick them up by themself, only one guy came and got some stickers from me but at the end of the day there are still people in the IRC who want to have either a new sticker or a sticker in general and for exactly this reason we are now offering you guys, the users of w0bm.com, the chance to get our limited w0bm.com otter sticker, there will be more events like this and we have already a second thing in our minds which is pretty cool!</p>
<h2>Description</h2>
<p>Each sticker will be a die cutted ~5x4,5 cm large w0bm otter with play button.</p>
<p>The stickers will be ordered at stickermule on 1<sup>st</sup> of June. Ordering will be possible only until then.</p>
<p>
Paying is possible only via <b>PayPal</b>.<br/>
If you're unable to pay via PayPal, please join our IRC or write us a message on Discord, maybe we'll have additional payment methods available.
</p>
<h2>Data Protection</h2>
<p>Your address is only stored on our server for the time of this event, we will wipe all tables after everyone has received their order.</p>
<p>We are unable to create any relation between your address and your username on w0bm.</p>
<p>This page is open source on <a target="_blank" href="https://github.com/w0bm/w0bm-stickers">GitHub</a>, feel free to check the code or report issues!</p>
<h2>Unanswered Questions?</h2>
<p>If your question wasn't answered on this page feel free to ask us on Discord or via IRC!</p>
<h2>Progress</h2>
<p>01.06.2018: The stickers have been ordered at stickermule. They will approximately arrive between 10<sup>th</sup> and 15<sup>th</sup> of June.</p>
</div>
<div class="box">
<h3>Here you can place your order:</h3>
<form class="js-submit" data-submit-callback="order_submit" data-callback="order_data" data-error-callback="form_error" action="add_order.php" method="POST">
<table>
<tbody>
<tr>
<td>Address:</td>
<td>
<input type="text" name="name" placeholder="Full Name" pattern=".+ .+" required/>
<br/>
<input type="text" name="street" placeholder="Street" required/>
<input type="text" name="house_number" placeholder="House Number" pattern="\w{1,5}" required/>
<br/>
<input type="text" name="postal_code" placeholder="Postal Code" pattern="[\w ]{4,10}" required/>
<input type="text" name="city" placeholder="City" required/>
<br/>
<select class="country_select" name="country_code" data-selected="DE"></select>
</td>
</tr>
<tr>
<td>Count:</td>
<td><input type="number" name="count" value="1" min="1" max="100" required/></td>
</tr>
<tr>
<td>Remark:</td>
<td><textarea name="remark" rows="4" cols="30"></textarea></td>
</tr>
<tr>
<td>Order Overview:</td>
<td>
<table id="order_overview">
<tbody>
<tr>
<td>Stickers (<span id="item_count"></span>x)</td>
<td><span id="item_price"></span>€</td>
</tr>
<tr>
<td>Packaging</td>
<td>+ <span id="packaging_cost"></span>€</td>
</tr>
<tr>
<td>Shipping</td>
<td>+ <span id="shipping_cost"></span>€</td>
</tr>
<tr>
<td>PayPal Fee</td>
<td>+ <span id="paypal_fee"></span>€</td>
</tr>
<tr>
<td></td>
<td><span id="total_price"></span>€</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td></td>
<td><div class="g-recaptcha" data-sitekey="6LfAzlUUAAAAAGN0xhJx8hEahcVR1bpg7PUmAMwb" data-callback="enable_order_submit" data-expired-callback="disable_order_submit" data-theme="dark"></div></td>
</tr>
<tr>
<td></td>
<td><button type="submit" disabled>Order</button></td>
</tr>
</tbody>
</table>
</form>
</div>
<div class="box">
<h3>Check the status of your order here:</h3>
<form class="js-submit" data-submit-callback="status_submit" data-callback="status_data" data-error-callback="form_error" action="order_status.php" method="POST">
<table>
<tbody>
<tr><td><input type="text" name="order_id" placeholder="Order ID" pattern="[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}" required/></td></tr>
<tr><td><div class="g-recaptcha" data-sitekey="6LfAzlUUAAAAAGN0xhJx8hEahcVR1bpg7PUmAMwb" data-callback="enable_status_submit" data-expired-callback="disable_status_submit" data-theme="dark"></div></td></tr>
<tr><td><button type="submit" disabled>Check Status</button></td></tr>
</tbody>
</table>
</form>
</div>
</div>
</body>
</html>