<?php
// public/order-submit.php

require_once __DIR__ . '/../app/orders.php';
require_once __DIR__ . '/../app/layout.php';

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    header('Location: ' . sparrow_url('/order.php'));
    exit;
}

try {
    $data = sparrow_build_order_data_from_post($_POST, false);

    sparrow_create_order($data);

    header('Location: ' . sparrow_url('/order.php?success=1'));
    exit;
} catch (Throwable $e) {
    header('Location: ' . sparrow_url('/order.php?error=1'));
    exit;
}