if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['client-email']) && isset($_POST['id']) && isset($_POST['name']) && isset($_POST['price'])) { $productId = $_POST['id']; try { $stmt = $pdo->prepare("UPDATE products SET is_on_stock = 0, reserved_at = NOW() WHERE id = :id"); $stmt->bindValue(':id', $productId, PDO::PARAM_INT); $stmt->execute(); $bookingCode = 'RES-' . date('dm') . '-' . bin2hex(random_bytes(3)); $data = array( 'client-email' => $_POST['client-email'], 'id' => $_POST['id'], 'price' => $_POST['price'], 'name' => $_POST['name'], 'booking-code' => $bookingCode, 'email-template' => ['reservation-confirmation'], ); $_SESSION['reservation'] = [ 'product-id' => $_POST['id'], 'product-name' => $_POST['name'], 'price' => $_POST['price'], 'client-email' => $_POST['client-email'], ]; // For demo.web-street.fr $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://demo.web-street.fr/send-reservation.php"); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); //curl_setopt($ch, CURLOPT_CAINFO, "/etc/ssl/certs/cacert.pem"); //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); // включаем проверку //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // проверка CN в сертификате //curl_setopt($ch, CURLOPT_CAINFO, "/etc/ssl/certs/ca-certificates.crt"); // явный путь $response = curl_exec($ch); if ($response === false) { error_log("cURL Error: " . curl_error($ch)); } else { error_log("cURL Success: " . $response); } //curl_setopt($ch, CURLOPT_CAPATH, "/etc/ssl/certs"); // Optional: Temporarily disable SSL verification for debugging /* curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); */ // For localhost /* $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://verre.local/send-reservation.php"); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); $error = curl_error($ch); curl_close($ch); */ $error = curl_error($ch); error_log("RESPONSE: $response"); error_log("CURL ERROR: $error"); curl_close($ch); // Close the cURL connection here error_log("cURL response: " . ($error ?: $response)); if ($error) { // Handle cURL error if needed error_log('cURL error: ' . $error); } else { // Redirect on success header('Location: success-reservation.php'); } } catch (PDOException $e) { // Log the error if needed error_log('Database error: ' . $e->getMessage()); die('Error while booking. Try again later..'); } }