HAWABA MARKETPLACE — BACKEND FOUNDATION + M-PESA CHECKOUT UI PACKAGE
================================================

Included
--------
- index.html: HAWABA storefront with a Kenyan phone-number field and Pay Now prompt flow preview. The screen validates the number but clearly reports that no STK request is sent until Daraja is activated.
- api/index.php: PHP API foundation for registration/login, customer accounts, seller product management,
  central orders, stock checks, order history, product-level parcel tracking, delivery assignment,
  rider status/location updates, reviews, return requests, notifications, seller order view and admin summary.
- database/schema.sql: MySQL/MariaDB tables.
- config/app.php: database and payment configuration template.

IMPORTANT: This is a deployable backend foundation, NOT a production-ready Jumia clone yet.
The existing index.html still contains its local-demo checkout and needs its frontend actions connected to
these API endpoints before customers use it for live transactions. M-Pesa STK push remains intentionally disabled until a Daraja application, shortcode, passkey, callback URL and payment verification flow have been implemented, supplied and tested. The checkout phone-number prompt in index.html is a UI preview only; it does not send a real payment request.
Email/SMS gateway credentials, rider live GPS app, delivery pricing zones, seller payouts, tax/accounting,
actual refund execution, and full admin/seller/customer screens also require configuration and additional integration. Return status changes do not move money automatically.

Hosting requirements to confirm with Safaricom BEFORE PURCHASE
--------------------------------------------------------------
1. PHP 8.1 or newer (prefer 8.2/8.3) and PDO MySQL enabled.
2. MySQL 8 or compatible MariaDB database, and permission to create/import tables.
3. HTTPS/SSL certificate and ability to set PHP session cookie options.
4. URL rewrite support (Apache mod_rewrite) or ability to route /api requests to api/index.php.
5. Outbound HTTPS requests from PHP to Safaricom Daraja and ability to receive public HTTPS callbacks.
6. Cron jobs (for abandoned orders, notifications and scheduled tasks) and enough resource limits.
7. Ability to keep config secrets outside the public web root, or at minimum deny web access to config files.
8. Automated backups for both database and uploaded product images.

The provider's published shared-hosting terms state 1 CPU, 1 GB memory and 20 concurrent connections.
Ask Safaricom whether a VPS is more appropriate for a multi-vendor marketplace expected to grow.

Setup overview (after an adult account holder has purchased a compatible plan)
-----------------------------------------------------------------------------
1. Create a MySQL database and database user in the hosting control panel.
2. Import database/schema.sql using phpMyAdmin or the host's database tool.
3. Set DB_HOST, DB_NAME, DB_USER and DB_PASS in config/app.php. Use a unique strong password.
4. Upload the project files. Point the domain document root to this project directory.
5. Ensure /config and /database are not publicly downloadable. Prefer moving config outside public_html.
6. Enable HTTPS, then test /api/health and /api/csrf.
7. Connect the storefront frontend to the API and test with test accounts and low-risk test products.
8. Apply for and configure M-Pesa Daraja in sandbox first. Never put consumer secrets or passkeys in browser JavaScript.
9. Test payment callbacks, duplicate callbacks, stock races, failed payments, refunds and backup restoration.
10. Do not accept live customer payments until security review and end-to-end tests pass.

API routes (JSON)
-----------------
GET  /api/health
GET  /api/csrf
POST /api/auth/register      {name,email,phone,password}
POST /api/auth/login         {email,password}
POST /api/auth/logout
GET  /api/auth/me
GET  /api/products           optional ?q=search
POST /api/products           seller/admin; requires X-CSRF-Token
PATCH /api/products/{id}     owner/admin; requires X-CSRF-Token
POST /api/orders             {items:[{product_id,quantity}],address:{county,town,street,instructions},payment_method}
GET  /api/orders
GET  /api/orders/{id}
PATCH /api/orders/{id}/status admin only
POST /api/reviews            delivered purchase only
POST /api/returns            delivered order only
GET  /api/notifications
GET  /api/seller/orders
GET  /api/admin/summary
POST /api/mpesa/stk           disabled until Daraja configuration is completed
POST /api/mpesa/callback      callback receiver stub; must be hardened and verified before production

Security note
-------------
No real admin account is seeded. Create the first admin using the CLI-only create_admin.php script before launch (not by changing a public signup form). Run it from a terminal/SSH session, then delete the script from the server. Never share passwords, ID numbers, KRA PINs, M-Pesa PINs,
Daraja secrets or hosting login credentials in ChatGPT or email. Use a trusted adult account holder for hosting
registration; Safaricom's published hosting terms say registrants must be at least 18.


PRODUCT-LEVEL PARCEL TRACKING
-----------------------------
Each order item can receive its own shipment and unique tracking code. This supports split shipments when a basket contains items from different sellers. Admin creates parcel records after the order exists, using POST /api/orders/{order_id}/shipments and the order_item_id values returned by GET /api/orders/{id}. Share the resulting tracking_code with the customer. A customer can check GET /api/tracking/{tracking_code}; the response does not include the customer's name, phone or full delivery address.

A delivery-role account must be created/approved by the site operator before a rider can be assigned. The rider updates the parcel status and may send GPS coordinates while the parcel is Out for delivery. GPS is not automatic: a rider app or staff interface must request location permission and send updates. The public tracking endpoint only returns a recent location (last 15 minutes) while the parcel status is Out for delivery. Location updates are rate-limited to one per 30 seconds. Do not promise continuous live GPS until a rider interface and consent/retention policy are implemented.

The single-file storefront still runs in local-demo mode until its checkout, account and tracking screens are connected to these API endpoints. The product-specific references shown in that demo are local browser examples, not real carrier tracking numbers.


M-PESA CHECKOUT PROMPT — CURRENT STATUS
---------------------------------------
The storefront now presents a dedicated Kenyan M-Pesa phone-number field and a Pay Now action. It validates the entered number and explains the activation state. It DOES NOT send an STK Push yet. The API route /api/mpesa/stk currently returns a disabled/not-implemented response by design.

Before enabling real STK Push, a developer must implement Daraja OAuth + STK Push initiation, store CheckoutRequestID against the order, validate the Safaricom callback, make callbacks idempotent, verify amount/account/reference, and update payment_status only after verified success. Never trust a browser success message or a customer screenshot as proof of payment. Use HTTPS and keep all Daraja secrets server-side. Test in Safaricom sandbox first.
