-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckout.php
124 lines (96 loc) · 3.94 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
require_once('includes/header.inc.php');
if (!isset($_SESSION['User'])){
header("Location: login.php");
}
?>
<main class="ui segment doubling stackable grid container">
<section class="five wide column">
<h3 class="ui dividing header">Checkout</h3>
<?php
if ($_SERVER["REQUEST_METHOD"] == "GET"){
if (isset($_GET["account"]) && isset($_GET["building_num"]) && isset($_GET["street"]) && isset($_GET["city"])
&& isset($_GET["state"]) && isset($_GET["country"]) && isset($_GET["postal"])){
$account = $_GET["account"];
$building_num = $_GET["building_num"];
$street = $_GET["street"];
$city = $_GET["city"];
$state = $_GET["state"];
$country = $_GET["country"];
$postal = $_GET["postal"];
if ($_SESSION['CartTotal'] == 0){
echo '<h2> Your cart is empty </h2>';
} else if (!canAffordOrder($account,$_SESSION['CartTotal'])){
echo '<h2> Your do not have enough money in your account :( </h2>';
} else {
updateClientAccount($_SESSION["ID"], $account);
$address_id = createAddress($building_num, $street, $city, $state, $country, $postal);
$order_number = place_order($_SESSION["ID"], $address_id);
$cart_items = $_SESSION['Cart'];
foreach($cart_items as $book){
checkout($book[0], $account, $order_number, $book[2]);
}
echo '<h2> Your order was placed successfuly! Your order number is '.$order_number.' </h2>';
$_SESSION["Cart"] = Array();
$_SESSION["CartTotal"] = 0;
return;
}
}
}
?>
<form class="ui form" method="GET">
<h4 class="ui dividing header">Banking Information</h4>
<div class="field">
<label>Account Number</label>
<div class="ui medium icon input">
<input name="account" type="text" placeholder="account number...">
</div>
</div>
<h4 class="ui dividing header">Address</h4>
<div class="field">
<label>Building Number</label>
<div class="ui mini icon input">
<input name="building_num" type="text" placeholder="building number...">
</div>
</div>
<div class="field">
<label>Street</label>
<div class="ui mini icon input">
<input name="street" type="text" placeholder="street...">
</div>
</div>
<div class="field">
<label>City</label>
<div class="ui medium icon input">
<input name="city" type="text" placeholder="city...">
</div>
</div>
<div class="field">
<label>State</label>
<div class="ui mini icon input">
<input name="state" type="text" placeholder="state...">
</div>
</div>
<div class="field">
<label>Country</label>
<div class="ui medium icon input">
<input name="country" type="text" placeholder="country...">
</div>
</div>
<div class="field">
<label>Postal Code</label>
<div class="ui medium icon input">
<input name="postal" type="text" placeholder="postal code...">
</div>
</div>
<button class="small ui orange button" type="submit">
Checkout
</button>
</form>
</section>
</main>
<footer class="ui black inverted segment">
<div class="ui container">LIBER Bookstore - www.LIBER.com</div>
</footer>
</body>
</html>