<?php

include("config.php");

echo '<div style="max-width: 600px; margin: 50px auto; font-family: Arial, sans-serif; padding: 20px; text-align: left; border: 1px solid #ccc; border-radius: 8px; box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.1);">
      <h2 style="color: red; margin-bottom: 15px;">Transaction Failed</h2>
      <p>Sorry! We could not process your transaction. Possible reasons for failure include:</p>
      <ul style="padding-left: 20px;">
          <li>You might have entered the wrong card number, expiry date, or CVV code.</li>
          <li>You might have entered the wrong OTP / Verification code.</li>
          <li>Your card issuing bank might have declined the card processing. Please ask your bank to enable "Online Transaction" on your card.</li>
          <li>If you think everything is fine, please try again.</li>
      </ul>
      <p><strong>You will be redirected back in 5 seconds...</strong></p>
      </div>';



// Flush output so message appears before redirection
flush();


// Redirect after 5 seconds
echo "<script>
        setTimeout(function() {
            window.location.href = '" . BC_URL . "checkout';
        }, 5000);
      </script>";


/*$postData = $_POST;

if ($_SERVER["REQUEST_METHOD"] === "POST") {  
    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 === "DECLINED") {
            echo "<script>window.location.href='".BC_URL."checkout'</script>";
        }
    }
}*/

?>
