<?php

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

$order_id = 'unknown';
if (isset($_SESSION['order_id'])) {
    $order_id = (int) $_SESSION['order_id'];
} else if (isset($_GET['order_id'])) {
    $order_id = (int) $_GET['order_id'];
}

$order_complete_url = HTTPS_SITE_URL . '/shop/checkout/order_complete.php';
$data = [
    'order_id' => $order_id,
    'payment_gateway' => 'sagepay',
];
$order_complete_url .= '?' . http_build_query($data);

$_SESSION['basket_id'] = null;
$_SESSION['requestPost'] = null;
$_SESSION['requestPost3d'] = null;

?><!doctype html>

<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <title>Order Complete</title>

    <script type="text/javascript">
        (function () {
            var fullPageURL = "<?= $order_complete_url ?>";

            if (top.location.href != fullPageURL) {
                top.location.replace(fullPageURL);
            }
        })();
    </script>
</head>

<body>

<style>

    /* iFrame success message before redirect */

    * {
        margin: 0;
        padding: 0;
    }

    h1 {
        font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
        font-size: 18px;
        font-weight: normal;
        margin: 20px 0 10px;
    }

    p {
        font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
        color: #262626;
        margin-bottom: 20px;
    }

    a {
        text-decoration: none;
        color: #000;
    }

</style>

<div class="sagepayServerSuccessMessage">
    <h1>Complete your Order</h1>
    <p><a href="<?= $order_complete_url ?>" target="_parent">Click here if you are not redirected.</a></p>
</div>

</body>
</html>
