-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkout.php
124 lines (121 loc) · 6.01 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
124
<?php
require_once 'classes.php';
// If a customer tries to checkout without being logged in, a session variable
// named loginFalse will be created, and the customer will be redirected to
// the login page. After a succesfull login the variable loginFalse will be set
// to false and the customer will be redirected to the checkout page.
if(!is_customer_logged_in()) {
$_SESSION['loginFalse'] = 1;
header('Location: customer_login.php');
}
include 'views/header.php';
include 'views/navigation.php';
?>
<div class="wrappercontent">
<?php
// After a logged in customer has succeeded in selecting a payment method, and
// has confirmed to want to pay, a form called 'checkout_complete' will be
// submitted. After checkout_complete has been submitted, Order::tryOrder will
// be called to try to pull the given product quantities from the database.
// Order::tryOrder creates a session variable called dbPullSucces. dbPullSucces
// will be true if the pull from the database has succeeded, and false if it has
// failed. If dbPullSuccess is false an error message will be printed and the
// script will exit.
if (isset($_POST['checkout_complete'])) {
Order::tryOrder($_SESSION['products'],
$_SESSION['quantities'],
Order::getProductNames($_SESSION['products']));
if(!$_SESSION['dbPullSuccess']) {
Order::printError();
include 'views/footer.php';
exit();
}
// If Order::tryOrder has succeeded in pulling the data from the database, then
// Order::executeOrder will insert all the information about the order into
// the database (that information will be: customer id, the ordered products,
// quantities, and payment method; the date and order id are automatically
// created when the order is inserted into the database.
Order::executeOrder($_SESSION['customer_id'],
$_SESSION['products'],
$_SESSION['quantities'],
Order::getProductPrices($_SESSION['products']),
Order::getProductNames($_SESSION['products']),
$_SESSION['payment']);
unset($_SESSION['products']);
unset($_SESSION['quantities']);
unset($_SESSION['subtotal']);
unset($_SESSION['payment']);
unset($_SESSION['total']);
echo '<h2 class="contenttitle">Betaling voldaan</h2>';
echo '<a href="customer_orders.php" class="button"><span>'
. '</span>factuuroverzicht</a><br><br>';
echo '<a href="products.php" class="button"><span>'
. '</span>verder winkelen</a>';
// The nested else if statements below are used to check the value of the
// selected payment method so that the script knows to which external page
// it has to redirect in case that the user has selected to pay electronically.
// After clicking on the button created by these statements, checkout_complete
// will be submitted. (if checkout_complete is submitted, the script will try
// to pull the data from the database).
} else if(isset($_POST['payment']) && $_POST['payment'] == "acceptgiro") {
echo "<h2 class='contenttitle'>Betalen via acceptgiro</h2>"
. "Klik op de button om uw bestelling te voltooien.<br>"
. "<form method='post' action='checkout.php'>"
. "<button type='submit' name='checkout_complete' class='button'>"
. "<span></span>betaling voltooien</button>"
. "</form>";
$_SESSION['payment'] = $_POST['payment'];
} else if (isset($_POST['payment']) && $_POST['payment'] == "bitcoin") {
echo "<h2 class='contenttitle'>Betalen via BitCoin</h2>"
. "Klik op de button om uw betaling te voltooien.<br>"
. "<form method='post' action='checkout.php'>"
. "<button type='submit' name='checkout_complete' class='button'>"
. "<span></span>betaling voltooien</button>"
. "</form>";
$_SESSION['payment'] = $_POST['payment'];
} else if (isset($_POST['payment']) && $_POST['payment'] == "ideal") {
echo "<h2 class='contenttitle'>Betalen via iDeal</h2>"
. "Klik op de button om uw betaling te voltooien.<br>"
. "<form method='post' action='checkout.php'>"
. "<button type='submit' name='checkout_complete' class='button'>"
. "<span></span>betaling voltooien</button>"
. "</form>"; $_SESSION['payment'] = $_POST['payment'];
} else if (isset($_POST['payment']) && $_POST['payment'] == "paypal") {
echo "<h2 class='contenttitle'>Betalen via Paypal</h2>"
. "Klik op de button om uw betaling te voltooien.<br>"
. "<form method='post' action='checkout.php'>"
. "<button type='submit' name='checkout_complete' class='button'>"
. "<span></span>betaling voltooien</button>"
. "</form>";
$_SESSION['payment'] = $_POST['payment'];
} else if (isset($_POST['payment']) && $_POST['payment'] == "rembours") {
echo "<h2 class='contenttitle'>Betalen onder rembours</h2>"
. "Klik op de button om uw bestelling te voltooien.<br>"
. "<form method='post' action='checkout.php'>"
. "<button type='submit' name='checkout_complete' class='button'>"
. "<span></span>betaling voltooien</button>"
. "</form>";
$_SESSION['payment'] = $_POST['payment'];
} else {
echo ' <h2 class="contenttitle">Selecteer betaalwijze:</h2>
<form method="post" action="checkout.php">
<input type="radio" name="payment" value="acceptgiro">
<span class="stockicon"></span>Acceptgiro<br>
<input type="radio" name="payment" value="bitcoin">
<span class="stockicon"></span>Bitcoin <br>
<input type="radio" name="payment" value="ideal">
<span class="stockicon"></span>Ideal <br>
<input type="radio" name="payment" value="paypal">
<span class="stockicon"></span>Paypal <br>
<input type="radio" name="payment" value="rembours">
<span class="stockicon"></span>Rembours<br>
<br>
<button type="submit" class="button">
<span></span>betaalwijze bevestigen</button>
</form>';
}
?>
</div>
<?php
include 'views/footer.php';
?>