$qty) { if (!isset($catalog[$id])) { continue; } $p = $catalog[$id]; $name = $p['title'] ?? ($p['name'] ?? ''); $image = $p['image'] ?? ''; $price = isset($p['currentPrice']) ? (float)$p['currentPrice'] : (float)($p['price'] ?? 0); $qty = max(1, (int)$qty); $subtotal = $price * $qty; $cart[] = [ 'id' => (string)$id, 'name' => $name, 'image' => $image, 'price' => $price, 'quantity' => $qty, 'subtotal' => $subtotal, ]; $cartTotal += $subtotal; } $cartCount = count($cart); // ---------- DEFAULTS ---------- $shippingFlat = 500; // KSh 500 nationwide $discountAmount = 0; $total = $cartTotal + $shippingFlat - $discountAmount; $errors = []; $step = 'form'; $orderId = null; // Preserve form values $firstName = ''; $lastName = ''; $phone = ''; $email = ''; $county = 'Nairobi'; $streetAddress = ''; $orderNotes = ''; $paymentMethod = 'mpesa'; $mpesaPhone = ''; // Kenya counties list $KENYA_COUNTIES = [ "Mombasa", "Kwale", "Kilifi", "Tana River", "Lamu", "Taita Taveta", "Garissa", "Wajir", "Mandera", "Marsabit", "Isiolo", "Meru", "Tharaka-Nithi", "Embu", "Kitui", "Machakos", "Makueni", "Nyandarua", "Nyeri", "Kirinyaga", "Murang'a", "Kiambu", "Turkana", "West Pokot", "Samburu", "Trans Nzoia", "Uasin Gishu", "Elgeyo-Marakwet", "Nandi", "Baringo", "Laikipia", "Nakuru", "Narok", "Kajiado", "Kericho", "Bomet", "Kakamega", "Vihiga", "Bungoma", "Busia", "Siaya", "Kisumu", "Homa Bay", "Migori", "Kisii", "Nyamira", "Nairobi" ]; sort($KENYA_COUNTIES); // ---------- HANDLE POST (PLACE ORDER) ---------- if ($_SERVER['REQUEST_METHOD'] === 'POST' && $cartCount > 0) { $firstName = trim($_POST['first_name'] ?? ''); $lastName = trim($_POST['last_name'] ?? ''); $phone = trim($_POST['phone'] ?? ''); $email = trim($_POST['email'] ?? ''); $county = trim($_POST['county'] ?? 'Nairobi'); $streetAddress = trim($_POST['street_address'] ?? ''); $orderNotes = trim($_POST['order_notes'] ?? ''); $paymentMethod = $_POST['payment_method'] ?? 'mpesa'; $mpesaPhone = trim($_POST['mpesa_phone'] ?? ''); // Basic validation – honest, minimal but real if ($firstName === '') { $errors['first_name'] = 'First name is required.'; } if ($lastName === '') { $errors['last_name'] = 'Last name is required.'; } if ($phone === '') { $errors['phone'] = 'Phone number is required.'; } if ($email === '') { $errors['email'] = 'Email address is required.'; } if ($streetAddress === '') { $errors['street_address'] = 'Delivery address / landmark is required.'; } if ($paymentMethod === 'mpesa' && $mpesaPhone === '') { $errors['mpesa_phone'] = 'M-PESA phone number is required.'; } if (empty($errors)) { // Generate simple order ID $orderId = 'ORD-' . mt_rand(100000, 999999); $step = 'success'; // (Optional) Save a simple text log of the order – good for real operations, but not required // This is transparent: we are not claiming anything Google-hype, just a local log. $orderLogDir = __DIR__ . '/orders'; if (!is_dir($orderLogDir)) { @mkdir($orderLogDir, 0755, true); } $orderData = [ 'order_id' => $orderId, 'created_at' => date('Y-m-d H:i:s'), 'first_name' => $firstName, 'last_name' => $lastName, 'phone' => $phone, 'email' => $email, 'county' => $county, 'street_address' => $streetAddress, 'order_notes' => $orderNotes, 'payment_method' => $paymentMethod, 'mpesa_phone' => $mpesaPhone, 'items' => $cart, 'subtotal' => $cartTotal, 'shipping' => $shippingFlat, 'discount' => $discountAmount, 'total' => $total, ]; @file_put_contents( $orderLogDir . '/' . $orderId . '.json', json_encode($orderData, JSON_PRETTY_PRINT) ); // Clear cart so they don't re-submit the same items $_SESSION['cart'] = []; $cartCount = 0; } } // ---------- META FOR THIS PAGE ---------- $pageTitle = 'Checkout – Nofba'; $pageDescription = 'Secure checkout for your Nofba order. Enter your delivery details, select payment method and review your order summary.'; $pageCanonical = $businessUrl . '/checkout.php'; $pageType = 'checkout'; $noIndex = false; ?>
Thank you for your purchase. We’ll contact you shortly to confirm delivery and payment.
A confirmation SMS or call will be made from our official number 0799 177 061. We will never ask you for your M-PESA PIN.
Nationwide Delivery: Standard shipping fee of KSh 500 applies to all orders across Kenya.
Delivery Times: Nairobi (24–48 hrs). Upcountry (2–3 business days) via trusted courier partners.
M-PESA: You will complete payment securely from your own phone. We never ask for your M-PESA PIN.
Pay on Delivery: Inspect your items upon arrival before paying via Cash or M-PESA where available.
Nationwide Delivery: Standard shipping fee of KSh 500 applies to all orders across Kenya.
Delivery Times: Nairobi (24–48 hrs). Upcountry (2–3 business days) via trusted courier partners.
M-PESA: You will complete payment securely from your own phone. We never ask for your M-PESA PIN.
Pay on Delivery: Inspect your items upon arrival before making payment.