-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsuccess.html
More file actions
64 lines (58 loc) · 2.44 KB
/
Copy pathsuccess.html
File metadata and controls
64 lines (58 loc) · 2.44 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Payment Successful</title>
<link rel="stylesheet" href="css/app.css">
<script src="user.js"></script>
</head>
<body>
<div style="text-align: center; padding: 50px;">
<h1 id="status-message">Verifying your payment... please wait.</h1>
<p>You will be redirected to your account page shortly.</p>
</div>
<script>
(async () => {
const messageEl = document.getElementById('status-message');
const urlParams = new URLSearchParams(window.location.search);
const sessionId = urlParams.get('session_id');
let user = null;
if (sessionId) {
const sessionResp = await fetch(`${window.API_ROOT}/auth/current_user`, {
credentials: 'include'
});
if (sessionResp.status === 200) {
user = await sessionResp.json();
}
}
if (sessionId && user) {
try {
const response = await fetch(`${window.API_ROOT}/order/success`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
body: JSON.stringify({ session_id: sessionId, user: user })
});
const data = await response.json();
if (response.ok) {
messageEl.textContent = 'Thank you for your order!';
// Clear the cart in the browser's local storage
const updatedUser = { ...user, user_cart: '[]' };
window.setCurrentUser(updatedUser);
// Redirect to account/dashboard after 3 seconds
setTimeout(() => {
window.location.href = 'dashboard.html';
}, 3000);
} else {
throw new Error(data.error || 'Failed to process order.');
}
} catch (error) {
messageEl.textContent = `Error: ${error.message}`;
}
} else {
messageEl.textContent = 'Could not verify payment. Session ID or user missing.';
}
})();
</script>
</body>
</html>