-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpayment.html
More file actions
321 lines (283 loc) · 13.4 KB
/
Copy pathpayment.html
File metadata and controls
321 lines (283 loc) · 13.4 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
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Secure Checkout - नगरCYCLE</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="mobile.css">
<style>
.checkout-container {
max-width: 900px;
margin: 4rem auto;
display: grid;
grid-template-columns: 1.5fr 1fr;
gap: 2rem;
}
.payment-methods {
display: grid;
gap: 1rem;
}
.method-card {
background: var(--card-bg);
border: 1px solid var(--border-color);
padding: 1.5rem;
border-radius: var(--radius-md);
cursor: pointer;
transition: all 0.3s ease;
display: flex;
align-items: center;
gap: 1rem;
}
.method-card:hover {
border-color: var(--primary-color);
background: rgba(143, 216, 160, 0.05);
}
.method-card.active {
border-color: var(--primary-color);
background: rgba(143, 216, 160, 0.1);
box-shadow: 0 0 20px rgba(143, 216, 160, 0.1);
}
.order-summary {
background: var(--card-bg);
border: 1px solid var(--border-color);
padding: 2rem;
border-radius: var(--radius-md);
height: fit-content;
}
.Summary-item {
display: flex;
justify-content: space-between;
margin-bottom: 0.75rem;
color: var(--text-light);
}
</style>
</head>
<body>
<header>
<div class="container">
<nav>
<a href="index.html" class="logo" style="display: flex; align-items: center; text-decoration: none;">
<img src="logo_final.jpg" alt="Logo" style="height: 55px; width: auto; margin-right: 10px;">
<span style="font-size: 1.5rem; font-weight: bold; color: var(--text-color);">नगर<span
style="font-family: sans-serif;">CYCLE</span></span>
</a>
</nav>
</div>
</header>
<div class="container">
<div class="checkout-container">
<main>
<h1 style="margin-bottom: 2rem;">Secure Checkout</h1>
<h3 style="margin-bottom: 1rem;">Select Payment Method</h3>
<div class="payment-methods">
<div class="method-card active" onclick="selectMethod('razorpay', this)">
<div style="font-size: 1.5rem;">💳</div>
<div>
<strong>UPI / Cards / NetBanking</strong>
<div style="font-size: 0.8rem; color: var(--text-light);">Secure payment via Razorpay</div>
</div>
</div>
<div class="method-card" onclick="selectMethod('cash', this)">
<div style="font-size: 1.5rem;">💵</div>
<div>
<strong>Cash on Pickup</strong>
<div style="font-size: 0.8rem; color: var(--text-light);">Pay directly to the collector
</div>
</div>
</div>
</div>
<button id="payBtn" class="btn btn-primary btn-block" style="margin-top: 2rem; padding: 1.25rem;"
onclick="processPayment()">
Proceed with Checkout
</button>
</main>
<aside class="order-summary">
<h3 style="margin-bottom: 1.5rem; border-bottom: 1px solid var(--border-color); padding-bottom: 1rem;">
Order Summary</h3>
<div id="summaryContent">
<!-- Dynamic Content -->
</div>
<div style="margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--border-color);">
<div class="Summary-item" style="color: var(--text-color); font-weight: bold; font-size: 1.2rem;">
<span>Total</span>
<span id="finalTotal">Rs.0</span>
</div>
</div>
</aside>
</div>
</div>
<script src="js/matching-engine.js"></script>
<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
<script>
let currentTotal = 0;
let checkoutData = [];
document.addEventListener('DOMContentLoaded', () => {
checkoutData = JSON.parse(localStorage.getItem('checkoutItem') || '[]');
if (checkoutData.length === 0) {
alert("No items selected for checkout.");
window.location.href = 'marketplace.html';
return;
}
let summaryHtml = '';
let subtotal = 0;
checkoutData.forEach(item => {
const priceNum = parseInt(item.price.replace(/[^0-9]/g, '')) || 0;
subtotal += priceNum;
summaryHtml += `
<div style="display: flex; gap: 1rem; margin-bottom: 1.5rem; border-bottom: 1px solid rgba(255,255,255,0.05); padding-bottom: 1rem;">
<img src="${item.img}" style="width: 60px; height: 60px; object-fit: cover; border-radius: 8px;">
<div>
<div style="font-weight: 600;">${item.title}</div>
<div style="font-size: 0.8rem; color: var(--text-light);">Seller: ${item.seller}</div>
<div style="color: var(--primary-color); font-weight: 500;">${item.price}</div>
</div>
</div>
`;
});
currentTotal = subtotal;
document.getElementById('summaryContent').innerHTML = summaryHtml + `
<div class="Summary-item">
<span>Subtotal</span>
<span>Rs.${subtotal}</span>
</div>
<div class="Summary-item">
<span>Platform Fee</span>
<span>Rs.0</span>
</div>
`;
document.getElementById('finalTotal').innerText = `Rs.${subtotal}`;
});
function selectMethod(method, element) {
selectedMethod = method;
document.querySelectorAll('.method-card').forEach(card => card.classList.remove('active'));
element.classList.add('active');
}
function processPayment() {
if (selectedMethod === 'razorpay') {
startRazorpay();
} else {
completeOrder('Cash');
}
}
function startRazorpay() {
const amount = currentTotal * 100;
try {
if (typeof Razorpay === 'undefined') throw new Error('Razorpay not loaded');
const options = {
"key": "rzp_test_5h8v8v8v8v8v8v", // Dummy test key format
"amount": amount,
"currency": "INR",
"name": "नगरCYCLE",
"description": "Purchase of " + checkoutData.length + " items",
"handler": function (response) {
completeOrder('Online');
},
"prefill": {
"name": "User Name",
"email": "user@example.com"
},
"theme": { "color": "#8fd8a0" }
};
const rzp = new Razorpay(options);
rzp.open();
} catch (e) {
console.warn("Razorpay script error, using high-fidelity fallback:", e);
showMockRazorpay();
}
}
function showMockRazorpay() {
const mock = document.createElement('div');
mock.id = 'mockRazorpay';
mock.style.position = 'fixed';
mock.style.top = '50%';
mock.style.left = '50%';
mock.style.transform = 'translate(-50%, -50%)';
mock.style.width = '350px';
mock.style.background = '#fff';
mock.style.borderRadius = '12px';
mock.style.boxShadow = '0 20px 50px rgba(0,0,0,0.5)';
mock.style.zIndex = '100001';
mock.style.overflow = 'hidden';
mock.style.color = '#333';
mock.style.fontFamily = 'Inter, sans-serif';
mock.innerHTML = `
<div style="background: #1e2129; padding: 1.5rem; color: white; display: flex; align-items: center; gap: 1rem;">
<div style="width: 40px; height: 40px; background: #8fd8a0; border-radius: 8px;"></div>
<div>
<div style="font-weight: bold;">नगरCYCLE</div>
<div style="font-size: 0.8rem; opacity: 0.7;">Secure Payment Gateway</div>
</div>
</div>
<div style="padding: 2rem; text-align: center;">
<div style="font-size: 1.2rem; margin-bottom: 0.5rem;">Amount to Pay</div>
<div style="font-size: 2rem; font-weight: bold; margin-bottom: 2rem;">Rs.${currentTotal}</div>
<div style="display: flex; flex-direction: column; gap: 1rem;">
<button class="btn btn-primary" onclick="this.disabled=true; this.innerText='Processing...'; setTimeout(() => { document.getElementById('mockRazorpay').remove(); completeOrder('Online'); }, 1500)" style="background: #3399cc; border: none; padding: 1rem; color: white; font-weight: bold;">
Pay Securely via UPI
</button>
<button onclick="document.getElementById('mockRazorpay').remove()" style="background: none; border: none; color: #666; cursor: pointer;">Cancel</button>
</div>
</div>
<div style="background: #f9f9f9; padding: 1rem; font-size: 0.75rem; text-align: center; color: #999;">
Protected by Razorpay Security
</div>
`;
document.body.appendChild(mock);
}
function completeOrder(method) {
// Simulation of Matching Engine trigger for each item
const saved = localStorage.getItem('ActiveOrders');
const activeOrders = saved ? JSON.parse(saved) : [];
checkoutData.forEach(item => {
const newJob = {
id: 'MISSION-' + Date.now() + '-' + Math.floor(Math.random()*1000),
type: item.title,
img: item.img,
weight: (item.quantity ? item.quantity.split(' ')[0] : 5),
pickupLoc: { lat: 28.57, lng: 77.25 },
pickupAddress: item.seller + ", Delhi",
dropAddress: "Buyer Location (Sector 4), Delhi",
payout: Math.floor((parseInt(item.price.replace(/[^0-9]/g, '')) || 0) * 0.4),
status: 'Unassigned'
};
activeOrders.push(newJob);
});
localStorage.setItem('ActiveOrders', JSON.stringify(activeOrders));
// [NEW] Remove items from Marketplace
const marketplaceItems = JSON.parse(localStorage.getItem('MarketplaceItems') || '[]');
const idsToRemove = checkoutData.map(i => i.id);
const updatedMarketplace = marketplaceItems.filter(i => !idsToRemove.includes(i.id));
localStorage.setItem('MarketplaceItems', JSON.stringify(updatedMarketplace));
// Clear Cart after successful checkout
localStorage.removeItem('shoppingCart');
// Store payment status for invoice
localStorage.setItem('paymentStatus', method === 'Cash' ? 'Payment Pending' : 'Paid');
// Show Success Overlay instead of auto-redirect
const overlay = document.createElement('div');
overlay.style.position = 'fixed';
overlay.style.top = '0';
overlay.style.left = '0';
overlay.style.width = '100%';
overlay.style.height = '100%';
overlay.style.background = 'rgba(0,0,0,0.9)';
overlay.style.display = 'flex';
overlay.style.flexDirection = 'column';
overlay.style.alignItems = 'center';
overlay.style.justifyContent = 'center';
overlay.style.zIndex = '100000';
overlay.style.color = 'white';
overlay.style.textAlign = 'center';
overlay.innerHTML = `
<div style="font-size: 4rem; color: var(--primary-color); margin-bottom: 1rem;">✅</div>
<h2 style="margin-bottom: 0.5rem;">Payment Successful!</h2>
<p style="color: var(--text-light); margin-bottom: 2rem;">Order confirmed via ${method}. Collector is being assigned.</p>
<button class="btn btn-primary" onclick="window.location.replace('invoice.html')" style="padding: 1rem 2rem;">
📄 Generate Invoice
</button>
`;
document.body.appendChild(overlay);
}
</script>
<script src="script.js"></script></body>
</html>