prepare("SELECT mi.name, mi.price, c.quantity FROM cart c JOIN menu_items mi ON c.menu_item_id = mi.id WHERE c.user_id = ?"); $stmt->execute([$user_id]); $cart_items = $stmt->fetchAll(); if (empty($cart_items)) { header("Location: cart.php"); exit(); } $line_items = []; foreach ($cart_items as $item) { $line_items[] = [ 'price_data' => [ 'currency' => 'usd', 'product_data' => [ 'name' => $item['name'], ], 'unit_amount' => $item['price'] * 100, // Price in cents ], 'quantity' => $item['quantity'], ]; } // Add delivery fee $delivery_fee = 5.00; $line_items[] = [ 'price_data' => [ 'currency' => 'usd', 'product_data' => [ 'name' => 'Delivery Fee', ], 'unit_amount' => $delivery_fee * 100, ], 'quantity' => 1, ]; $checkout_session = \Stripe\Checkout\Session::create([ 'payment_method_types' => ['card'], 'line_items' => $line_items, 'mode' => 'payment', 'success_url' => 'http://' . $_SERVER['HTTP_HOST'] . '/payment-success.php?session_id={CHECKOUT_SESSION_ID}', 'cancel_url' => 'http://' . $_SERVER['HTTP_HOST'] . '/payment-cancel.php', ]); header("HTTP/1.1 303 See Other"); header("Location: " . $checkout_session->url);