status == 'succeeded') { // 2. Find Local Order $stmt = $pdo->prepare("SELECT * FROM orders WHERE stripe_payment_intent_id = ?"); $stmt->execute([$payment_intent_id]); $order = $stmt->fetch(PDO::FETCH_OBJ); if ($order) { // 3. Update Order Status (if it's still pending) if ($order->order_status == 'pending') { $update_stmt = $pdo->prepare("UPDATE orders SET order_status = 'completed' WHERE id = ?"); $update_stmt->execute([$order->id]); } // 4. Fetch Order Details for Display $details_stmt = $pdo->prepare( "SELECT o.id as order_id, o.amount, c.name as customer_name, c.email, p.name as plan_name FROM orders o JOIN customers c ON o.customer_id = c.id JOIN plans p ON o.plan_id = p.id WHERE o.id = ?" ); $details_stmt->execute([$order->id]); $order_details = $details_stmt->fetch(PDO::FETCH_OBJ); $message = "Thank you for your order! Your payment was successful."; // 5. Send Confirmation Email (optional, but good practice) require_once __DIR__ . '/mail/MailService.php'; $subject = 'Your Australia Broadband Internet Order Confirmation'; $html_body = "
Thank you for your order. Your new internet service is being processed.
" . "Order Details:
" . "You will receive further updates from us shortly.
"; MailService::sendMail($order_details->email, $subject, $html_body); } else { $error = true; // This is a critical error. Payment succeeded but we can't find the order. error_log("CRITICAL: Payment succeeded for PI {$payment_intent_id} but no matching order found in DB."); $message = "Your payment was successful, but we could not find your order. Please contact support immediately."; } } else { $error = true; $message = "Your payment was not successful. Please try again or contact support."; } } catch (Exception $e) { $error = true; error_log("Order confirmation error: " . $e->getMessage()); $message = "An error occurred while processing your order. Please contact support."; } } ?>Order ID: order_id); ?>
Customer: customer_name); ?>
Plan: plan_name); ?>
Amount Paid: $amount, 2)); ?>