<?php

include("config.php");

$postData = $_POST;

if ($_SERVER["REQUEST_METHOD"] === "POST") {  // Corrected REQUEST_METHOD
    if (empty($postData)) {
        //echo "No POST data received!\n";
    } else {
        $order_id = $postData["orderId"];
        $order_id_encrpyted = $postData["OrderIDEncrypted"];
        $order_session_id = $postData["SessionId"];
        $xmlString = $postData["xmlmsg"];

        // Convert XML string to object
        $xml = simplexml_load_string($xmlString);
        
        if ($xml === false) {
            echo "Error parsing XML!";
            exit();
        }

        // Extract OrderStatus from XML
        $orderStatus = (string) $xml->OrderStatus;

        if ($orderStatus === "CANCELED") {
            echo "<script>window.location.href='".BC_URL."checkout'</script>"; 
        }
    }
}

?>
