-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkout.php
102 lines (74 loc) · 2.29 KB
/
checkout.php
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
<?php
/// This must come first when we need access to the current session
session_start();;
require("classes/components.php");
require("classes/utils.php");
require("classes/basket.php");
$basket = Basket::getBasketArray();
/// Redirect user from this page if they're already logged in
if(!isset($_SESSION["loggedIn"])){
header("Location: " . Utils::$projectFilePath . "/login.php");
}
/**
* Redirects to the book list page if the basket is empty.
*
* @param array $basket The basket containing items
*/
if(empty($basket)){
header("Location: " . Utils::$projectFilePath . "/book-list.php");
}
$output = ""; ///< Variable to store output as a string.
/**
* Validates and processes the order when the HTTP request method is POST.
*/
if($_SERVER["REQUEST_METHOD"] === "POST"){
require("classes/order.php");
$output = Order::validate();
if(!$output){
Order::create($basket);
header("Location: " . Utils::$projectFilePath . "/user.php");
}
}
Components::pageHeader("Checkout", ["style"], ["mobile-nav"]);
?>
<h2>Checkout</h2>
<form method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?>" enctype="multipart/form-data" class="form">
<h3>Shipping Address</h3>
<label>Address Line</label>
<input type="text" name="address_line" value="<?php if ($output) {
echo $_POST["address_line"];
} ?>">
<label>Town</label>
<input type="text" name="town" value="<?php if ($output) {
echo $_POST["town"];
} ?>">
<label>County</label>
<input type="text" name="county" value="<?php if ($output) {
echo $_POST["county"];
} ?>">
<label>Postcode</label>
<input type="text" name="postcode" value="<?php if ($output) {
echo $_POST["postcode"];
} ?>">
<h3>Payment Details</h3>
<label>Card Number</label>
<input type="text" name="card_number">
<div class="form-row">
<div>
<label>Expiry</label>
<div class="inline-inputs">
<input type="text" name="month" placeholder="month">
<input type="text" name="year" placeholder="year">
</div>
</div>
<div>
<label>Security Number</label>
<input type="text" name="security_number">
</div>
</div>
<input class="button" type="submit" value="Complete order">
<?php if ($output) { echo $output; } ?>
</form>
<?php
Components::pageFooter();
?>