
<?php


date_default_timezone_set('Asia/Kolkata');
$paydate = date('Y-m-d H:i:s') ;






// Merchant key here as provided by Payu
$MERCHANT_KEY = "yVrvFZu2";

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

// 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';
}


?>


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





<div class="container" style="margin:50px auto">

<style>
table {}
td { padding:3px;}
.hd_e { font-family:"Century Gothic";  font-weight:bold; font-size:14px;}
.sido td { padding:10px; text-align:left; border:1px solid #dddddd;}


</style>
<?php
$total_amt = 0;

if($result2):

if($shipdetails): 

?>

<?php echo $final_report; ?>
<div class="col-md-3">

<table width="100%">
<tr><td colspan="2"  class="hd_e"><u>Shipping Date & Time</u></td></tr>
<tr class="tr_2">
    <td width="40%">Delivery Date</td>
    <td width="60%">: &nbsp;&nbsp;<?=$shipdetails->ddate?></td>
</tr>

<tr class="tr_2">
    <td >Delivery Time</td>
    <td >: &nbsp;&nbsp;<?=$shipdetails->dtime?></td>
</tr>


<tr class="tr_2">
    <td>Telephone</td>
    <td>: &nbsp;&nbsp;<?=$shipdetails->tel?></td>
</tr>

<tr class="tr_2">
    <td>Mobile</td>
    <td>: &nbsp;&nbsp;<?=$shipdetails->mobile?></td>
</tr> 

<!--<tr><td colspan="2" style="text-align:left; font-size:16px; font-weight:bold;"><u>Track Details</u></td></tr>

<tr class="tr_2">
    <td colspan="2"><?php echo $shipdetails->track_det=='' ? 'not available' : $shipdetails->track_det ; ?></td>
</tr>-->

</table>

<table width="100%">



<tr><td colspan="2" class="hd_e" ><u>Gift Or Not</u></td></tr>
<tr class="tr_2">
    <td width="40%" tyle="text-align:left; font-size:16px; font-weight:bold;" >Gift  </td>
    <td width="60%">: &nbsp;&nbsp; <?php if($shipdetails->gifts==1){ echo "Gift Odder";} if($shipdetails->gifts==2){ echo "Not Gift";} ?> </td>
</tr>

<tr class="tr_2">
    <td width="30%" tyle="text-align:left; font-size:16px; font-weight:bold;" >Gift Message </td>
    <td width="70%">: &nbsp;&nbsp;<?=$shipdetails->giftmsg?>  </td>
</tr>




</table>


</div>


<div class="col-md-3">
<table>
<tr><td colspan="2" class="hd_e" ><u>Shipping Details</u></td></tr>

<tr class="tr_2">
    <td width="30%">Deliver To</td>
    <td width="70%">: &nbsp;&nbsp;<?=$shipdetails->name?></td>
</tr>

<tr class="tr_2">
    <td>Address</td>
    <td>: &nbsp;&nbsp;<?=$shipdetails->address?></td>
</tr>

<tr class="tr_2">
    <td>Land Mark</td>
    <td>: &nbsp;&nbsp;<?=$shipdetails->city?></td>
</tr>

<tr class="tr_2">
    <td>Pincode</td>
    <td>: &nbsp;&nbsp;<?=$shipdetails->pin?></td>
</tr>

</table>
</div>

<!-- show order details -->
<div class="col-md-6">
<table width="100%" border="0" cellpadding="10" cellspacing="10" align="center" class="sido" >

<tr><td colspan="2">Order ID : <b><?=$shipdetails->order_id?></b></td>
<td colspan="2" style="text-align:right;">Date : <b><?=get_datetime($shipdetails->order_date)?></b></td></tr>  

<tr bgcolor="#333333" style="color:#FFF;">
    <td>Product Name</td>
    <td> No. Unit Price (Qty.)</td>
    <td>Unit Price(Rs.)</td>
    <td>Sub Total(Rs.)</td>
</tr>
  
<?php foreach($result2 as $row): ?>

  <tr bgcolor="#FAFAFA">
    <td><?php foreach($product as $prow): 
  if($prow['pid']==$row['prod_id']):
   ?>
  
    <?php endif; endforeach; ?>
   <?=$row['prod_name']?>
    </td>
    <td><?=$row['prod_qty']?></td>
    <td><?=$row['prod_price']?></td>
    <td style="text-align:right;"><?=$row['subtotal']?></td>
  </tr>
    
<?php 

$total_amt+=$row['subtotal'] ;

endforeach; 

?>

  <tr bgcolor="#F5F5F5" >
    <td colspan="3" align="center">Shipping Charge (<?=get_area_by_id($shipdetails->area)?>)</td>
    <td style="text-align:right;"><?=$shipdetails->ship_charge?></td>
  </tr>
  
<?php $total_amt+= $shipdetails->ship_charge ; ?>  

<tr bgcolor="#dddddd" style="color:#000000;text-align:center;">
<td colspan="3">Total Amount Payable</td><td  style="text-align:right; font-size:20px; font-weight: bold;">Rs.&nbsp;&nbsp;<?=$total_amt?></td>
</tr> 
        
</table>
</div>


<!-- show shipping details -->




<div class="clr"></div>

<img src="<?php echo base_url('assets/images/payumoney-ico.jpg') ; ?>" />






<?php if($formError) { ?>
	
      <span style="color:red">Please fill all mandatory fields.</span>
      <br/>
      <br/>
    <?php } ?>

 <form action="<?php echo $action; ?>" method="post" name="payuForm">
      <input type="text" name="key" value="<?php echo $MERCHANT_KEY ?>" />
      <input type="text" name="hash" value="<?php echo $hash ?>"/>
      <input type="text" name="txnid" value="<?php echo $txnid ?>" />

<input type="text" name="amount" value="<?=$total_amt?>" />
<input type="text"  name="firstname" id="firstname" value="<?=$shipdetails->name?>" />
<input type="text"  name="email" id="email" value="<?=$email?>" />
<input type="text"  name="phone" value="<?=$shipdetails->mobile?>" />
<textarea name="productinfo" >Qunty=<?=$prod_qty?></textarea>

<input type="text"  name="surl" value="http://staremiratesholidays.com/success.php"  />
<input type="text"  name="furl" value="http://staremiratesholidays.com/failure.php"  />
<input  type="text" name="service_provider" value="payu_paisa" />
        
          <?php if(!$hash) { ?>
            <input type="submit" value="Pay Now" name="submit" class="btn btn-md btn-primary btn-block submito" style="width:200px;"  />
          <?php } ?>
      
    </form>

<?php endif; ?>
<?php endif; ?>

</div>