<?php //if(isset($_POST['submit'])){echo "<pre>";print_r($_POST);exit;}

// Merchant key here as provided by Payu

$tax=0;

$MERCHANT_KEY = "aXlePx";



// Merchant Salt as provided by Payu

$SALT = "M7chGjjkUD1fIP4yYBZjaBoyqdF1pzmJ";



// 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('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>

  <script>

    var hash = '<?php echo $hash ?>';

    function submitPayuForm() {

      if(hash == '') {

        return;

      }

      var payuForm = document.forms.payuForm;

      payuForm.submit();

    }

  </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">

               <!-- <div class="page-title">Make Payment <b class="text-danger">for Your Jewellery <?php echo $plan;?></b></div>-->

                <div class="page-subtitle">You are about to Redirect to the Payment Gateway</div>

             <!-- <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">

                   <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="text" name="amount" readonly value="<?php echo (empty($posted['amount'])) ? $amount : $posted['amount']; ?>" />

         

        

       

       

         

          <input name="phone" type="hidden" value="<?php echo (empty($posted['phone'])) ? '1234567890' : $posted['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()."home/pre_book_status/".$oid;//(empty($posted['surl'])) ? '' : $posted['surl'] ?>" size="64" />

           <input name="firstname" type="hidden" id="firstname" value="<?php echo (empty($posted['fname'])) ? $name : $posted['fname']; ?>" />

        <input name="furl" type="hidden" value="<?php echo base_url()."home/pre_book_status/".$oid;//(empty($posted['furl'])) ? '' : $posted['furl'] ?>" size="64" />

        <input name="email" id="email" type="hidden" value="<?php echo (empty($posted['email'])) ? 'satshl3112@gmail.com' : $posted['email']; ?>" />

       

        

<input type="hidden" name="service_provider"  value="payu_biz" size="64" />



       

          <?php if(!$hash) { ?>

            <input type="submit" 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>

