payment_status === 'paid') { $booking_details = $_SESSION['pending_booking']; $pdo = db(); $stmt = $pdo->prepare("INSERT INTO bookings (coach_id, client_id, booking_time, stripe_payment_intent_id, payment_status) VALUES (?, ?, ?, ?, 'paid')"); $stmt->execute([$booking_details['coach_id'], $booking_details['client_id'], $booking_details['booking_time'], $checkout_session->payment_intent]); // Send email notification to coach require_once __DIR__ . '/mail/MailService.php'; $coach_stmt = $pdo->prepare("SELECT email FROM coaches WHERE id = ?"); $coach_stmt->execute([$booking_details['coach_id']]); $coach = $coach_stmt->fetch(); $client_stmt = $pdo->prepare("SELECT name FROM clients WHERE id = ?"); $client_stmt->execute([$booking_details['client_id']]); $client = $client_stmt->fetch(); if ($coach && $client) { $to = $coach['email']; $subject = 'New Booking Confirmation'; $message = "You have a new booking from {$client['name']} for {$booking_details['booking_time']}."; MailService::sendMail($to, $subject, $message, $message); } // Clear the pending booking from the session unset($_SESSION['pending_booking']); header('Location: dashboard.php?booking=success'); exit; } else { header('Location: payment-cancel.php?reason=payment_not_complete'); exit; } } catch (\Stripe\Exception\ApiErrorException $e) { // Handle error header('Location: payment-cancel.php?reason=invalid_session'); exit; }