<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous"><?php //if(isset($_POST['submit'])){echo "<pre>";print_r($_POST);exit;}
// Merchant key here as provided by Payu
$tax=0;
//$MERCHANT_KEY = "gtKFFx";
//$SALT = "eCwWELxi";
//$PAYU_BASE_URL = "https://test.payu.in";


$MERCHANT_KEY = "e48yYu89";
$SALT = "uJDTqB7One";
$PAYU_BASE_URL = "https://sandboxsecure.payu.in/_payment";

$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('sha256', 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>
<meta name="viewport" content="width=device-width, initial-scale=1">
  <script>
    var hash = '<?php echo $hash ?>';
    function submitPayuForm() {
      if(hash == '') {
        return;
      }
      var payuForm = document.forms.payuForm;
      payuForm.submit();
    }
  </script>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
  </head>
  <body onLoad="submitPayuForm()">
    
    <div id="team" class="container-fluid">  <div class="image-bg"></div>
    <div class="container">
      <div class="row">
            <div class="col-md-12 text-center" style="margin-top:50px;">
               <!-- <div class="page-title">Make Payment <b class="text-danger">for Your Jewellery <?php echo $plan;?></b></div>-->
                <h2 class="text-center text-warning">You are about to Redirect to PayU Payment Gateway</h2>
             <!-- <h3 class="text-warning">We are not currently accepting Online Payment and this will be available soon.</h3>-->
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
      
    <?php if($formError) { ?>
	
      <span style="color:red">Please fill all mandatory fields.</span>
      <br/>
      <br/>
    <?php } ?>
    
                <div class="text-search-holder text-center">
                   <form action="<?php echo $action; ?>" method="post" name="payuForm" id="text-search">
      <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="<?php echo $txnid ?>" />
       <input type="hidden" name="service_provider" value="payu_paisa" />
       <input type="hidden" name="amount" readonly value="<?php echo $amount; ?>" />
         
        
       
       
         
          <input name="phone" type="hidden" value="<?php echo $payee_phone;?>" />
        <input name="productinfo" type="hidden" value="<?php echo (empty($posted['productinfo'])) ? 'Plan '.$plan : $posted['productinfo'] ?>" />
       
        <input name="surl" type="hidden" value="<?php echo base_url()."Rest/razor_pay_status/".$oid;//(empty($posted['surl'])) ? '' : $posted['surl'] ?>" size="64" />
           <input name="firstname" type="hidden" id="firstname" value="<?php echo $payee_name; ?>" />
        <input name="furl" type="hidden" value="<?php echo base_url()."Rest/razor_pay_status/".$oid;//(empty($posted['furl'])) ? '' : $posted['furl'] ?>" size="64" />
        <input name="email" id="email" type="hidden" value="<?php echo $payee_email; ?>"  />
        
        
<h1 class="text-danger text-center">Rs. <?php echo $amount; ?>/-</h1>
       
          <?php if(!$hash) { ?>
           <h3 class="text-danger"><i class="fa fa-spin fa-spinner"></i> We Will be Redirecting you to payment gateway.</h3> 
            <input type="submit" class="btn btn-warning" name="submit" value="Pay Now" />
          <?php } ?>
         <!-- <a href="<?php echo base_url();?>home/PayOffline" class="btn btn-primary">Pay Offline</a>-->
     
    </form>
                           
                        <!--<input type="submit" name="submit" value="Find out" />-->
                    
                </div>
            </div>
        </div>
    </div>
</div>

  </body>
</html>
