<?php
$path = '../../../';

require_once $path . 'core/includes/header.inc.php';

if(empty($_SESSION['order_id'])) {
    header('Location: ' . SITE_URL . '/shop');
    die;
}

$order = new Order($_SESSION['order_id']);

if(empty($order->paid)) {
    $page_meta = [
        'title' => 'Your order has not been processed | ' . config('app.name'),
        'page_title' => 'Order issue',
        'page_sub_title' => 'Your order has not been processed',
    ];

    echo $twig->render('shop/checkout/order_failed.twig', [
        'page_html' => '',
        'page_meta' => $page_meta,
    ]);
    die;
}

$page_meta = [
    'title' => 'Your order is now complete | ' . config('app.name'),
    'page_title' => 'Order Complete',
    'page_sub_title' => 'Thank you for shopping online with ' . config('app.name'),
];
$tracking_code[] = $twig->render('analytics_js.twig', [
    'order'    => $order,
    'settings' => $settings,
]);

echo $twig->render('shop/checkout/order_complete.twig', [
    'page_html' => '',
    'page_meta' => $page_meta,
    'basket_object' => $order,
    'tracking_code' => $tracking_code,
    'payment_method'       => $_GET['method'] ?? '',
]);

unset($_SESSION['order_id']);
unset($_SESSION['basket_id']);
die;
