<?php
	// Inialize session
	session_start(0);
	error_reporting(0);
	include("config.php");
	$user=$_SESSION['username'];
	unset($_SESSION['cart']);
	
	//for mail
	 $paytype=$_REQUEST['paytype'];
	 $oid=$_REQUEST['oid'];
	 $email=$_REQUEST['email'];
	 $conca=$_REQUEST['co'];
	 $Order_Id=base64_decode($conca);
	 include("include/functions.php");
	 
	 $delete_profit_empty=mysql_query("delete from `profit` where `product_id`='' and `quantity`=''");
	 
?>

<!DOCTYPE HTML>
<html>
	<head>
		<title><?php echo $tittle;?></title>
		<link href="css/style.css" rel='stylesheet' type='text/css' />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
		</script>
		<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700,800' rel='stylesheet' type='text/css'>
		<script src="js/jquery.min.js"></script>
		<script type="text/javascript" src="js/jquery.easy-ticker.js"></script>
		<script type="text/javascript">
		$(document).ready(function(){
			$('#demo').hide();
			$('.vticker').easyTicker();
		});
		</script>
		<link href="css/megamenu.css" rel="stylesheet" type="text/css" media="all" />
		<script type="text/javascript" src="js/megamenu.js"></script>
		<script>$(document).ready(function(){$(".megamenu").megamenu();});</script>
		<script src="js/menu_jquery.js"></script>
		<link rel="stylesheet" href="css/slippry.css">
       </head>
	
    
    
    <?php
// Merchant key here as provided by Payu
$MERCHANT_KEY = "imteCTVt";

// Merchant Salt as provided by Payu
$SALT = "Fr65DqghJu";

// End point - change to https://secure.payu.in for LIVE mode
$PAYU_BASE_URL = "https://secure.payu.in";

$action = '';

$posted = array();
if(!empty($_POST)) {
    //print_r($_POST);
  foreach($_POST as $key => $value) {    
    $posted[$key] = $value; 
	
  }
}
$formError = 0;
if(empty($posted['txnid'])) {
  // Generate random transaction id
  $txnid = substr(hash('sha512', mt_rand() . microtime()), 0, 20);
} else {
  $txnid = $posted['txnid'];
}
$hash = '';
// Hash Sequence
$hashSequence = "key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5|udf6|udf7|udf8|udf9|udf10";
if(empty($posted['hash']) && sizeof($posted) > 0) {
  if(
          empty($posted['key'])
          || empty($posted['txnid'])
          || empty($posted['amount'])
          || empty($posted['firstname'])
          || empty($posted['email'])
          || empty($posted['phone'])
          || empty($posted['productinfo'])
          || empty($posted['surl'])
          || empty($posted['furl'])
		  || empty($posted['service_provider'])
  ) {
    $formError = 1;
  } else {
    //$posted['productinfo'] = json_encode(json_decode('[{"name":"tutionfee","description":"","value":"500","isRequired":"false"},{"name":"developmentfee","description":"monthly tution fee","value":"1500","isRequired":"false"}]'));
	$hashVarsSeq = explode('|', $hashSequence);
    $hash_string = '';	
	foreach($hashVarsSeq as $hash_var) {
      $hash_string .= isset($posted[$hash_var]) ? $posted[$hash_var] : '';
      $hash_string .= '|';
    }

     $hash_string .= $SALT;

    $hash = strtolower(hash('sha512', $hash_string)); 
    $action = $PAYU_BASE_URL . '/_payment';
  }
} elseif(!empty($posted['hash'])) {
  $hash = $posted['hash'];
  $action = $PAYU_BASE_URL . '/_payment';
} 
?>

<html>
  <head>
  <script>
    var hash = '<?php echo $hash ?>';
    function submitPayuForm() {
      if(hash == '') {
        return;
      }
      var payuForm = document.forms.payuForm;
      payuForm.submit();
    }
  </script>
  </head>
  <body onLoad="submitPayuForm()">
      





<?php include("include/header.php"); ?>
<div class="main">
		<div class="container">
               <?php
        $select1="select * from user_account where username='$user'";
$result1=mysql_query($select1); 
$exc=mysql_fetch_array($result1);
?>
            
  		<div class="center_text" style="padding:10px;">
        <?php
        $id = mysql_query("SELECT order_id FROM orders where email='$user' ORDER BY serial DESC");
		$id = mysql_fetch_array($id);
	    $order_id=$id['order_id'];
	    $inc=$order_id;
		if($_REQUEST['ad']!='su'){echo "";}else{?>
				Your order has been placed! Your Ordered ID  <span style="font-weight:bold;font-size:20px;color:#F00;"><?php echo $Order_Id; ?></span>
			<?php }?>
           <?php
$select="select * from orders where order_id='$Order_Id'";
$result=mysql_query($select);
$row = mysql_fetch_array($result);
$order_id=$row['order_id'];
$order_tot=$row['tot_amount'];
?>
             
      <br>Your Total Amount with shipping Charge&nbsp;:<span style="font-weight:bold;font-size:26px;"> <?php echo number_format($order_tot,2); ?></span>
      
      
      <form action="<?php echo $action; ?>" method="post" name="payuForm">
      <input type="hidden" name="key" value="<?php echo $MERCHANT_KEY ?>" />
      <input type="hidden" name="hash" value="<?php echo $hash ?>"/>
      <input type="hidden" name="txnid" value="<? echo $txnid; ?>" />
      
      <input name="amount" type="hidden" value="<? echo $order_tot; ?>" />
      <input name="firstname" type="hidden" value="<? echo $row['name']; ?>" />
      <input name="email" type="hidden" value="<? echo $row['email']; ?>" />
      <input name="phone" type="hidden" value="<? echo $row['phone']; ?>" />
      
      <table align="center" cellpadding="8"> 
      <input type="hidden" name="surl" value="http://localhost/online_shopping/cryo_medics/success.php">
        <input type="hidden" name="furl" value="http://localhost/online_shopping/cryo_medics/failure.php">
        <input type="hidden" name="productinfo" value="Cryo Medics">
        <input type="hidden" name="service_provider" value="payu_paisa"/>
        <input type="hidden" name="lastname" value=""/>
         <input type="hidden" name="curl" value=""/>
         <input type="hidden" name="address1" value=""/>
          <input type="hidden" name="address2" value=""/>
           <input type="hidden" name="city" value=""/>
            <input type="hidden" name="state" value=""/>
            <input type="hidden" name="country" value=""/>
            <input type="hidden" name="zipcode" value=""/>
             <input type="hidden" name="udf1" value=""/>
              <input type="hidden" name="udf2" value=""/>	
              <input type="hidden" name="udf3" value=""/>	
              <input type="hidden" name="udf4" value=""/>	
              <input type="hidden" name="udf5" value=""/>	
              <input type="hidden" name="pg" value=""/>
        <tr>
          <?php if(!$hash) { ?>
            <td colspan="4"><input type="submit" value="Pay Now With PayUMoney" id="paynow_buton" /><br><br><img src="images/payumoney_button.png" width="200" style="border-radius:10px;"></td>
          <?php } ?>
        </tr>
      </table>
    </form>
    
    <div style="clear:both;"></div>
        
        </div>
        </div>
      
   <?php include("include/footer.php"); ?>
