-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpayment.html
More file actions
136 lines (127 loc) · 3.45 KB
/
payment.html
File metadata and controls
136 lines (127 loc) · 3.45 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Farm2Table - Payment</title>
<style>
body {
font-family: Arial, sans-serif;
background: #f9fafb;
margin: 0;
padding: 0;
color: #333;
}
header {
background: #4f46e5;
color: white;
text-align: center;
padding: 1rem;
}
.container {
max-width: 600px;
margin: 2rem auto;
background: white;
padding: 2rem;
border-radius: 12px;
box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
h2 {
color: #4f46e5;
margin-bottom: 1rem;
}
.payment-option {
display: flex;
align-items: center;
margin: 10px 0;
}
.payment-option input {
margin-right: 10px;
}
.balance {
margin: 1rem 0;
font-weight: bold;
color: green;
}
.btn {
display: block;
width: 100%;
margin-top: 1.5rem;
padding: 12px;
border: none;
border-radius: 8px;
background: #4f46e5;
color: white;
font-size: 16px;
cursor: pointer;
}
.btn:hover {
background: #4338ca;
}
</style>
</head>
<body>
<header>
<h1>Secure Payment</h1>
</header>
<div class="container">
<h2>Choose Payment Method</h2>
<div class="payment-option">
<input type="radio" id="debit" name="payment" value="Debit Card" checked>
<label for="debit">Debit Card (Balance: <span id="balance">₹99,999</span>)</label>
</div>
<div class="payment-option">
<input type="radio" id="credit" name="payment" value="Credit Card">
<label for="credit">Credit Card</label>
</div>
<div class="payment-option">
<input type="radio" id="upi" name="payment" value="UPI">
<label for="upi">UPI</label>
</div>
<div class="payment-option">
<input type="radio" id="wallet" name="payment" value="Wallet">
<label for="wallet">Wallet</label>
</div>
<div class="balance">Your Cart Total: <span id="cart-total">₹0</span></div>
<button class="btn" onclick="processPayment()">Pay Now</button>
</div>
<script>
const BALANCE = 99999;
function getCart() {
return JSON.parse(localStorage.getItem("cart") || "[]");
}
// Load cart total
function loadCartTotal() {
const cart = getCart();
const products = JSON.parse(localStorage.getItem("products") || "[]");
let total = 0;
if (products.length > 0) {
cart.forEach(item => {
const product = products.find(p => p.id === item.id);
if (product) total += product.price * item.qty;
});
}
document.getElementById("cart-total").textContent = "₹" + total;
return total;
}
// Payment processing
function processPayment() {
const total = loadCartTotal();
const method = document.querySelector("input[name='payment']:checked").value;
if (method === "Debit Card" && total > BALANCE) {
alert("Payment Failed: Insufficient balance on Debit Card!");
return;
}
alert("Payment Successful via " + method + "!");
// update last order status to Paid
let orders = JSON.parse(localStorage.getItem("orders") || "[]");
if (orders.length > 0) {
orders[orders.length - 1].status = "Paid";
localStorage.setItem("orders", JSON.stringify(orders));
}
window.location.href = "delivery.html";
}
// preload cart total
loadCartTotal();
</script>
</body>
</html>