forked from maiz-an/PlaySphere
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_payment.php
More file actions
37 lines (32 loc) · 1.14 KB
/
process_payment.php
File metadata and controls
37 lines (32 loc) · 1.14 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
<?php
require 'staff/db.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$booking_id = $_POST['booking_id'];
$payment_method = $_POST['payment_method'];
if (!$booking_id || !$payment_method) {
echo "Invalid payment details.";
exit;
}
try {
// Update booking payment status
$stmt = $pdo->prepare("
UPDATE bookings SET payment_status = 'paid', status = 'confirmed'
WHERE id = ?
");
$stmt->execute([$booking_id]);
// Insert payment record
$stmt = $pdo->prepare("
INSERT INTO payments (booking_id, payment_method, payment_status, amount)
SELECT bookings.id AS booking_id, ?, 'paid',
TIMESTAMPDIFF(HOUR, bookings.start_time, bookings.end_time) * futsals.price_per_hour
FROM bookings
JOIN futsals ON bookings.futsal_id = futsals.id
WHERE bookings.id = ?
");
$stmt->execute([$payment_method, $booking_id]);
echo "Payment successful! Booking confirmed.";
} catch (PDOException $e) {
echo "Error processing payment: " . $e->getMessage();
}
}
?>