-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_payment.php
More file actions
99 lines (69 loc) · 2.32 KB
/
process_payment.php
File metadata and controls
99 lines (69 loc) · 2.32 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
<?php
session_start();
// Check if the user is logged in
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit();
}
// Check if form data is provided
if (!isset($_POST['booking_id']) || !isset($_POST['total_price'])) {
header("Location: member_view_events.php");
exit();
}
$booking_id = $_POST['booking_id'];
$total_price = $_POST['total_price'];
$card_name = $_POST['card_name'];
$card_number = $_POST['card_number'];
$exp_date = $_POST['exp_date'];
$cvv = $_POST['cvv'];
// Simulate payment processing (In real-world, integrate with a payment gateway here)
$payment_success = true; // Assume payment is successful
if ($payment_success) {
// Database connection
$servername = "localhost";
$username = "root"; // Replace with your database username
$password = ""; // Replace with your database password
$dbname = "zoo_website";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Insert payment record
$sql = "INSERT INTO payments (booking_id, user_id, amount_paid, payment_date)
VALUES (?, ?, ?, NOW())";
$stmt = $conn->prepare($sql);
$stmt->bind_param("sid", $booking_id, $_SESSION['user_id'], $total_price);
$stmt->execute();
$stmt->close();
// Update booking status to 'paid'
$sql = "UPDATE bookings SET status = 'paid' WHERE booking_id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $booking_id);
$stmt->execute();
$stmt->close();
$conn->close();
// Redirect to a success page
header("Location: payment_success.php");
exit();
} else {
// Redirect to a failure page
header("Location: payment_failure.php");
exit();
}
?>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST['name'];
$email = $_POST['email'];
$ticket_type = $_POST['ticket_type'];
$quantity = $_POST['quantity'];
$card_number = $_POST['card_number'];
$expiry_date = $_POST['expiry_date'];
$cvv = $_POST['cvv'];
// Here you would add logic to process the payment through a payment gateway
// After processing, redirect back to the tickets.php page with a success message
header("Location: tickets.php?success=1");
exit();
}
?>