-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocess_payment.php
More file actions
41 lines (35 loc) · 1.33 KB
/
Copy pathprocess_payment.php
File metadata and controls
41 lines (35 loc) · 1.33 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
<?php
include 'includes/config.php';
// Ensure user is logged in
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit();
}
// Ensure form data is provided
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['booking_id'], $_POST['amount'], $_POST['payment_method'])) {
$user_id = $_SESSION['user_id'];
$booking_id = $_POST['booking_id'];
$amount = $_POST['amount'];
$payment_method = $_POST['payment_method'];
// Generate a fake transaction ID
$transaction_id = uniqid("txn_");
// Insert payment record
$query = "INSERT INTO payments (user_id, booking_id, amount, payment_status, payment_method, transaction_id)
VALUES (?, ?, ?, 'completed', ?, ?)";
$stmt = $conn->prepare($query);
$stmt->bind_param("iidss", $user_id, $booking_id, $amount, $payment_method, $transaction_id);
if ($stmt->execute()) {
// Update booking table to mark as paid
$updateBooking = $conn->prepare("UPDATE bookings SET status = 'confirmed' WHERE booking_id = ?");
$updateBooking->bind_param("i", $booking_id);
$updateBooking->execute();
// Redirect to confirmation page
header("Location: confirmation.php?booking_id=$booking_id");
exit();
} else {
echo "Payment failed!";
}
} else {
echo "Invalid request!";
}
?>