-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfirm-order.php
203 lines (171 loc) · 7.23 KB
/
confirm-order.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Are you hungry? You are at the right place. We offer mouth watering foods at your doorstep. Click now and order food online.">
<meta name="author" content="Ashish Acharya, Bibek Mahat, Parask K. Bhandari, Suresh Dahal">
<meta name="theme-color" content="#F7922F">
<link rel="shortcut icon" href="./images/logo.png" type="image/x-icon">
<title>Confirm | RestroHub</title>
<link rel="stylesheet" href="./styles/style.css">
<link rel="stylesheet" href="./styles/responsive.css">
</head>
<body>
<?php require("./components/header.php"); ?>
<main>
<section class="confirm_card text-center p-20 w-fit shadow border-curve">
<div class="w-fit" style="margin: auto">
<h1 class="heading">Confirm Order</h1>
<hr>
</div>
<div class="p-20 checkout-details">
<!-- data coming from js below -->
</div>
</section>
<!-- ======================= eSewa form =======================
<form action="https://uat.esewa.com.np/epay/main" method="POST" class="esewa_form">
<input value="100" id="tAmt" name="tAmt" type="hidden">
<input value="100" id="amt" name="amt" type="hidden">
<input value="0" id="txAmt" name="txAmt" type="hidden">
<input value="0" name="psc" type="hidden">
<input value="0" name="pdc" type="hidden">
<input value="EPAYTEST" name="scd" type="hidden">
<input value="<?php echo time(); ?>" name="pid" type="hidden">
<input value="http://localhost/messy-code/components/esewa/success.php?q=su" type="hidden" name="su">
<input value="http://localhost/messy-code/components/esewa/failed.php?q=fu" type="hidden" name="fu">
</form> -->
</main>
<?php require "./components/footer.php"; ?>
<script>
const cookieString = document.cookie.split("; ")
.find(row => row.startsWith("checkoutFormData"))
.split("checkoutFormData=")[1];
const data = JSON.parse(decodeURIComponent(cookieString));
const checkoutDetails = document.querySelector(".checkout-details");
const tAmt = document.getElementById("tAmt");
const amt = document.getElementById("amt");
const txAmt = document.getElementById("txAmt");
amt.value = parseInt(data.total_price) - parseInt(data.vat);
txAmt.value = data.vat;
tAmt.value = data.total_price;
if (data) {
const p = document.createElement("p");
p.innerHTML = `
${data.name
? `<div class="flex gap mt-20">
<p class="tal"> <b>Name:</b> </p>
<p class="tar"> ${data.name} </p>
</div>`
: ""
}
${data.phone
? `<div class="flex gap mt-20">
<p class="tal"> <b>Phone:</b> </p>
<p class="tar"> ${data.phone} </p>
</div>`
: ""
}
${data.address
? `<div class="flex gap mt-20">
<p class="tal"> <b>Address:</b> </p>
<p class="tar"> ${data.address} </p>
</div>`
: ""
}
${data.note
? `<div class="flex gap mt-20">
<p class="tal"> <b>Note:</b> </p>
<p class="tar"> ${data.note} </p>
</div>`
: ""
}
${data.total_price
? `<div class="flex gap mt-20">
<p class="tal"> <b>Total Price:</b> </p>
<p class="tar"> Rs. ${Math.ceil(parseInt(data.total_price))} </p>
</div>`
: ""
}
${data.pm
? `<div class="flex gap mt-20">
<p class="tal"> <b>Payment Method:</b> </p>
<p class="tar"> ${data.pm == "cod" ? "Cash on Delivery" : "eSewa"} </p>
</div>`
: ""
}
${data['date']
? `<div class="flex gap mt-20">
<p class="tal"> <b>Delivery Date:</b> </p>
<p class="tar"> ${data['date']} </p>
</div>`
: ""
}
${data['time']
? `<div class="flex gap mt-20">
<p class="tal"> <b>Delivery Time:</b> </p>
<p class="tar"> ${data['time']} </p>
</div>`
: ""
}
${data.pm == "cod"
? `<button class="button border-curve mt-20 cod_btn">Place Order</button>`
: ``
}
${data.pm == "esewa"
? `<button class="button border-curve mt-20 esewa_btn">Pay with eSewa</button>`
: ``
}
${data.msg
? `<p class="mt-20">${data.msg}</p>`
: ""
}
${data.btn == "view order"
? `<div class="mt-20"><a href="./track-order.php" class="button border-curve mt-20">View Order</a></div>`
: ""
}
`;
checkoutDetails.appendChild(p);
} else {
const p = document.createElement("p");
p.innerHTML = `
<p class="mt-20">Your cart is empty.</p>
`;
checkoutDetails.appendChild(p);
}
const placeOrder = () => {
const codBtn = document.querySelector('.cod_btn');
const esewaBtn = document.querySelector('.esewa_btn');
const esewaForm = document.querySelector('.esewa_form');
esewaBtn && esewaBtn.addEventListener('click', () => {
esewaForm.submit();
})
codBtn && codBtn.addEventListener('click', () => {
fetch('./backend/place-order.php', {
method: 'POST',
body: JSON.stringify(data)
})
.then(res => res.json())
.then(data => {
if (data.success) {
document.cookie = "checkoutFormData=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=http://localhost/messey-code;";
document.cookie = `checkoutFormData=${JSON.stringify({
msg: "Your order was placed successfully.",
btn: "view order"
})}; path=http://localhost/messey-code`;
window.location.href = './track-order.php'
} else {
alert(data.message)
}
})
.catch(err => {
console.error(err)
})
})
}
placeOrder();
</script>
<script src="./js/app.js" type="module"></script>
</body>
</html>