-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpay.php
More file actions
264 lines (233 loc) · 13.8 KB
/
Copy pathpay.php
File metadata and controls
264 lines (233 loc) · 13.8 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
<?php
/**
* pay.php - Interactive Realistic Payment Gateway Simulation
*/
require_once __DIR__ . '/includes/helpers.php';
// Guard authentication
auth_guard(['customer', 'vendor', 'admin']);
$userId = $_SESSION['user_id'];
$orderNumber = clean($_GET['order'] ?? '');
if (empty($orderNumber)) {
die("Invalid order query.");
}
try {
// Fetch Order details
$orderStmt = db()->prepare("SELECT * FROM `orders` WHERE `order_number` = ? AND `user_id` = ? LIMIT 1");
$orderStmt->execute([$orderNumber, $userId]);
$order = $orderStmt->fetch();
if (!$order) {
die("Order not found or access denied.");
}
if ($order['payment_status'] === 'completed') {
redirect("success.php?order=" . $orderNumber);
}
} catch (Exception $e) {
die("Database transaction issue: " . $e->getMessage());
}
// Payment form submission simulation
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['process_payment'])) {
try {
db()->beginTransaction();
// Update order status to paid
$upd = db()->prepare("UPDATE `orders` SET `payment_status` = 'completed' WHERE `id` = ?");
$upd->execute([$order['id']]);
// Release escrow money: update wallet of vendors for this order
$itemsStmt = db()->prepare("SELECT * FROM `order_items` WHERE `order_id` = ?");
$itemsStmt->execute([$order['id']]);
$items = $itemsStmt->fetchAll();
foreach ($items as $item) {
// Update order item status to paid/completed
$updItem = db()->prepare("UPDATE `order_items` SET `status` = 'pending' WHERE `id` = ?");
$updItem->execute([$item['id']]);
}
db()->commit();
set_flash_message('success', 'Online payment verified successfully!');
redirect("success.php?order=" . $orderNumber);
} catch (Exception $e) {
db()->rollBack();
set_flash_message('danger', 'Payment failed: ' . $e->getMessage());
}
}
$pageTitle = "Secure Payment Gateway - " . $order['payment_method'];
require_once __DIR__ . '/includes/header.php';
require_once __DIR__ . '/includes/navbar.php';
?>
<div class="container my-5">
<div class="row justify-content-center">
<div class="col-lg-6 col-md-8">
<div class="card border-0 shadow-lg p-0 rounded-4 overflow-hidden">
<!-- Gateway Branded Header -->
<div class="p-4 text-center text-white <?php
echo $order['payment_method'] === 'Card' ? 'bg-dark' :
($order['payment_method'] === 'PayPal' ? 'bg-primary' :
($order['payment_method'] === 'RazorPay' ? 'bg-info bg-gradient text-dark' :
($order['payment_method'] === 'UddoktoPay' ? 'bg-danger bg-gradient' : 'bg-success bg-gradient')));
?>">
<h5 class="mb-1 text-uppercase fw-bold tracking-wider" style="font-size: 13px;">
<i class="bi bi-shield-lock-fill text-warning me-1 animate-pulse"></i>
<?php echo htmlspecialchars($order['payment_method']); ?> Gateway Terminal
</h5>
<h3 class="fw-bold mt-2 mb-0"><?php echo format_price($order['grand_total']); ?></h3>
<small class="text-white-50">Transaction Ref: <?php echo htmlspecialchars($order['order_number']); ?></small>
</div>
<div class="p-4" id="gateway-body">
<!-- Progress / Spinner Overlay (hidden by default) -->
<div id="processing-overlay" class="text-center py-5 d-none">
<div class="spinner-border text-primary mb-3" style="width: 3rem; height: 3rem;" role="status"></div>
<h5 class="fw-bold mb-1" id="proc-title">Authenticating Sandbox connection...</h5>
<p class="text-muted small" id="proc-desc">Do not close or reload this window.</p>
</div>
<form id="payment-gate-form" action="" method="POST">
<input type="hidden" name="process_payment" value="1">
<!-- METHOD 1: CARD SYSTEM -->
<?php if ($order['payment_method'] === 'Card'): ?>
<div class="mb-4">
<label class="form-label small text-muted">Cardholder Name</label>
<input type="text" class="form-control form-control-lg rounded-3 text-uppercase" placeholder="JOHN DOE" required>
</div>
<div class="mb-4">
<label class="form-label small text-muted">Card Number</label>
<div class="input-group input-group-lg">
<span class="input-group-text bg-white"><i class="bi bi-credit-card-2-front"></i></span>
<input type="text" id="card-num" class="form-control rounded-end-3" placeholder="4111 2222 3333 4444" maxlength="19" required>
</div>
</div>
<div class="row g-3 mb-4">
<div class="col-6">
<label class="form-label small text-muted">Expiration Date</label>
<input type="text" class="form-control form-control-lg rounded-3" placeholder="MM/YY" maxlength="5" required>
</div>
<div class="col-6">
<label class="form-label small text-muted">Security Code (CVV)</label>
<input type="password" class="form-control form-control-lg rounded-3" placeholder="123" maxlength="3" required>
</div>
</div>
<!-- METHOD 2: PAYPAL -->
<?php elseif ($order['payment_method'] === 'PayPal'): ?>
<div class="alert alert-info py-2 small border rounded-3 mb-4">
<i class="bi bi-info-circle-fill me-1"></i> Sandbox Test Email: <code>paypal-sandbox@vortexmarket.com</code>
</div>
<div class="mb-3">
<label class="form-label small text-muted">PayPal Account Email</label>
<input type="email" class="form-control form-control-lg rounded-3" value="paypal-sandbox@vortexmarket.com" required>
</div>
<div class="mb-4">
<label class="form-label small text-muted">Password</label>
<input type="password" class="form-control form-control-lg rounded-3" value="••••••••••••••" required>
</div>
<!-- METHOD 3: RAZORPAY -->
<?php elseif ($order['payment_method'] === 'RazorPay'): ?>
<div class="mb-4 text-center">
<img src="https://razorpay.com/assets/razorpay-glyph.svg" width="60" class="mb-3" onerror="this.style.display='none'">
<p class="text-secondary small">RazorPay Secure Instant Pay. Enter your routing mobile details.</p>
</div>
<div class="mb-4">
<label class="form-label small text-muted">Mobile Number / UPI Link</label>
<input type="text" class="form-control form-control-lg rounded-3 text-center" placeholder="9876543210@pay" required>
</div>
<!-- METHOD 4: UDDOKTOPAY -->
<?php elseif ($order['payment_method'] === 'UddoktoPay'): ?>
<div class="text-center mb-4">
<span class="badge bg-danger px-3 py-2 rounded-pill mb-2">Simulated API Redirect</span>
<p class="text-secondary small">Select your wallet gateway to complete transfer.</p>
</div>
<div class="row g-2 mb-4">
<div class="col-6">
<div class="card p-3 border text-center cursor-pointer hover-up rounded-3" onclick="setUddoktoChannel('bKash')">
<input class="form-check-input mx-auto mb-2" type="radio" name="uddokto_chan" id="chan-bkash" checked>
<label class="form-check-label fw-bold text-dark d-block" for="chan-bkash">bKash</label>
</div>
</div>
<div class="col-6">
<div class="card p-3 border text-center cursor-pointer hover-up rounded-3" onclick="setUddoktoChannel('Nagad')">
<input class="form-check-input mx-auto mb-2" type="radio" name="uddokto_chan" id="chan-nagad">
<label class="form-check-label fw-bold text-dark d-block" for="chan-nagad">Nagad</label>
</div>
</div>
</div>
<!-- METHOD 5: AMARPAY -->
<?php elseif ($order['payment_method'] === 'AmarPay'): ?>
<div class="mb-4 text-center">
<p class="text-secondary small">Choose cards, net-banking or mobile financial services.</p>
</div>
<div class="list-group rounded-3 mb-4">
<label class="list-group-item d-flex gap-3 py-3 cursor-pointer">
<input class="form-check-input flex-shrink-0" type="radio" name="amarpay_opt" checked>
<span>
<strong class="text-dark d-block">Visa / Mastercard Debit Card</strong>
<span class="text-muted small">Pay securely using international debit card.</span>
</span>
</label>
<label class="list-group-item d-flex gap-3 py-3 cursor-pointer">
<input class="form-check-input flex-shrink-0" type="radio" name="amarpay_opt">
<span>
<strong class="text-dark d-block">DBBL Nexus Pay</strong>
<span class="text-muted small">Pay with DBBL domestic network.</span>
</span>
</label>
</div>
<?php endif; ?>
<!-- Shared Pay Button -->
<button type="submit" class="btn btn-primary btn-lg w-100 fw-bold rounded-3 py-3 mb-2" id="pay-submit-btn">
Complete Sandbox Payment <i class="bi bi-shield-check ms-1"></i>
</button>
<a href="checkout.php" class="btn btn-link btn-sm w-100 text-secondary text-decoration-none mt-2">
<i class="bi bi-chevron-left"></i> Cancel and return to store
</a>
</form>
</div>
</div>
</div>
</div>
</div>
<script>
document.getElementById('payment-gate-form').addEventListener('submit', function (e) {
e.preventDefault();
const form = this;
const formInputs = form.querySelectorAll('input, select, button');
const overlay = document.getElementById('processing-overlay');
// Disable inputs
formInputs.forEach(i => i.setAttribute('disabled', 'disabled'));
// Hide form elements, show processing overlay
form.classList.add('d-none');
overlay.classList.remove('d-none');
const steps = [
{ title: "Securing SSL connection...", desc: "Initializing secure sandbox session..." },
{ title: "Verifying credentials...", desc: "Passing parameters to the card processor..." },
{ title: "Authorizing order value...", desc: "Updating ledger wallets and commission variables..." },
{ title: "Transaction Successful!", desc: "Returning to VortexMarket..." }
];
let currentStep = 0;
const interval = setInterval(() => {
if (currentStep < steps.length) {
document.getElementById('proc-title').textContent = steps[currentStep].title;
document.getElementById('proc-desc').textContent = steps[currentStep].desc;
currentStep++;
} else {
clearInterval(interval);
// Re-enable form to allow submission
formInputs.forEach(i => i.removeAttribute('disabled'));
// Submit form
form.submit();
}
}, 900);
});
// Helper for card number formatting
const cardNum = document.getElementById('card-num');
if (cardNum) {
cardNum.addEventListener('input', function (e) {
let value = e.target.value.replace(/\s+/g, '').replace(/[^0-9]/gi, '');
let formatted = '';
for (let i = 0; i < value.length; i++) {
if (i > 0 && i % 4 === 0) formatted += ' ';
formatted += value[i];
}
e.target.value = formatted;
});
}
function setUddoktoChannel(chan) {
if (chan === 'bKash') document.getElementById('chan-bkash').checked = true;
if (chan === 'Nagad') document.getElementById('chan-nagad').checked = true;
}
</script>
<?php require_once __DIR__ . '/includes/footer.php'; ?>