<?php if(!isset($oid)){redirect("home");}?>

<!DOCTYPE HTML>

<html>

<head>

<meta name="viewport" content="width=device-width, initial-scale=1">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>Redirecting to Payment Gateway</title>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">



<!-- jQuery library -->



<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>







<!-- Latest compiled JavaScript -->



<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>







<link href="https://fonts.googleapis.com/css?family=Josefin+Sans&display=swap" rel="stylesheet">



</head>



<body style="font-family: 'Josefin Sans', sans-serif;">



<div class="container">



	<div class="row">



    	<div style="margin-top:50px; background:#fbfbfb; padding:50px;" class="col-md-6 col-md-offset-3 text-center">



        	<div class="row">



                <div class="col-md-6">



                



                <img class="img img-responsive" src="<?php echo base_url();?>asset/images/logo.png"> 



                </div>



                <div class="col-md-6 pull-right">



                <img class="img img-responsive" src="<?php echo base_url();?>asset/images/razorpay.png"> 



                </div>





                



            </div>



            



            <h3>You Will be redirecting to Payment Gateway to make your Payment.</h3>



            <style>.table th{width:150px;}.table{font-size:16px; background:#FF9; text-align:left;}</style>

			<div class="col-md-12 text-center">

            <h3 class="text-danger">Total Order Amount</h3>

            <?php $order_total=$ototal+$shiptot-$odis;?>

            <h2 class="text-danger"><?php echo $order_total;?></h2>

            <button type="button" class="js-pay-bundle btn btn-warning" data-amount="<?php echo $order_total*100;?>" data-processorid="razor" data-qty="1">Pay With RazorPay</button>

            

            </div>



<script>



  // Function to lazy load a script



  // -----------------------------------------------



  var loadExternalScript = function(path) {



    var result = $.Deferred(),



        script = document.createElement("script");







    script.async = "async";



    script.type = "text/javascript";



    script.src = path;



    script.onload = script.onreadystatechange = function(_, isAbort) {



      if (!script.readyState || /loaded|complete/.test(script.readyState)) {



        if (isAbort)



          result.reject();



        else



          result.resolve();



      }



    };







    script.onerror = function() {



      result.reject();



    };







    $("head")[0].appendChild(script);







    return result.promise();



  };



  



  



  



  



  // Use loadScript to load the Razorpay checkout.js



// -----------------------------------------------



var callRazorPayScript = function(itemId, amount, qty, processorId) {

  var merchangeName = "Grocery Store",

      img = "<?php echo base_url();?>asset/images/logo.png",

      name = "<?php echo $this->session->userdata("name");?>",

      description = "Payment for Grocery Order",

      amount = amount,

      qty = qty;

      

  loadExternalScript('https://checkout.razorpay.com/v1/checkout.js').then(function() { 

    var options = {

	  <?php //if($admin->razorpay_demo==""){$key="rzp_live_5pVV6azI8VjHuS";}else{$key="rzp_test_vHaga3JfP6nvpO";}?>

      key: '<?php echo 'rzp_test_vHaga3JfP6nvpO';//$key;?>',//'rzp_live_5RLgL3qMxPGcwD',rzp_test_vHaga3JfP6nvpO

      protocol: 'https',

      hostname: 'api.razorpay.com',

      amount: amount,

      name: merchangeName,

      description: description,

      image: img,

      prefill: {

        name: name,

      },

      theme: {

        color: '#b9a76e'

      },

      handler: function (transaction, response){

       // console.log('Tshirt\\ntransaction id: ' + transaction.razorpay_payment_id);

        //console.log(response.razorpay_payment_id);

		check_status(transaction.razorpay_payment_id);

      }

    };



    window.rzpay = new Razorpay(options);



		console.log('Item Id: ', amount);

    console.log('Amount: ', amount);

    console.log('Quantity: ', qty);

    console.log('Processor Id: ', processorId);



    rzpay.open();

  });

}







function check_status(trid){



	$.ajax({



			 type: "POST",



			 url: '<?php echo base_url();?>home/razor_pay_status',



			 data: {trans_id:trid,oid:<?php echo $oid;?>},



			 success: function(res){

				// console.log(res);



				 if(res==1){



					window.location.href = "<?php echo base_url();?>home/orders?pay_status=success"; 



				 }else{



					 alert("Payment couldnot be completed. please try again.");



				 }



				//$(".otp_error").html(res);



			 }



		});



}



// Trigger call to action buttons depending on the bundle packs



// -----------------------------------------------



var $payBundle = $('.js-pay-bundle');







$payBundle.on('click', function() {



	var itemId = $(this).data('itemid'),



			amount = $(this).data('amount'),



			processorid = $(this).data('processorid'),



			qty = $(this).data('qty');







	callRazorPayScript(itemId, amount, processorid, qty);



});



</script>



        </div>



    </div>



</div>



</body>



</html>