<?php
session_start();
$OrderID = "ANK".rand(00000,99999);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $url = 'https://shivajigateway.com/api/create-order'; // Replace with the actual API endpoint

    $data = array(
        "customer_mobile" => $_POST["customer_mobile"],
        "user_token" => "0f61e67c7465cc40d26726b6143d6731",
        "amount" => $_POST["txnAmount"],
        "order_id" => $OrderID,
        "redirect_url" => "https://uclservices.online/admin/res5.php",
    );
// Store order_id in a session variable
        $_SESSION['order_id'] = $OrderID;
         $_SESSION['customer_mobile'] = $_POST['customer_mobile'];

    $options = array(
        'http' => array(
            'header' => "Content-type: application/x-www-form-urlencoded\r\n",
            'method' => 'POST',
            'content' => http_build_query($data),
        ),
    );

    $context = stream_context_create($options);
    $response = file_get_contents($url, false, $context);

    if ($response === FALSE) {
        die('Error occurred while making the API request');
    }

    $result = json_decode($response, true);

    if ($result['status'] === true) {
        // Success Response

        
        // Delay the redirect by 2 seconds
        sleep(2);

        // Redirect to the payment URL
        header("Location: " . $result['result']['payment_url']);
        exit();
    } else {
        // Failed Response
        echo "Error from API: " . $result['message'] . "\n";
    }
}
?>

<html>
<head>
    <title>Gateway Check Out Page</title>
</head>
<body>
    <center><h1>Please do not refresh this page...</h1></center>
</body>
</html>
