
<?php


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


 
if(isset($_POST['submit']) && $_POST['txnid']!='' && $_POST['amount']!=0){
$final_report.="The System is redirecting... Please wait a few seconds. You will be redirected automatically.";
}





// Merchant key here as provided by Payu  Rs0gwA
//$MERCHANT_KEY = "hujpuZEK";  //Please change this value with live key for production
$MERCHANT_KEY = "hujpuZEK";


$hash_string = '';
// Merchant Salt as provided by Payu
//$SALT = "nQ2BZBZzil"; //Please change this value with live salt for production  ishcELwQ
$SALT = "nQ2BZBZzil";

// End point - change to https://secure.payu.in for LIVE mode
$PAYU_BASE_URL = "https://test.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'])
  ) { 
  } 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';
	//header('Location: $PAYU_BASE_URL . '/_payment'');
	
  }
} elseif(!empty($posted['hash'])) {
 $hash = $posted['hash']; 
 echo $action = $PAYU_BASE_URL . '/_payment';
 // header('Location: $PAYU_BASE_URL . '/_payment'');
}


?>



<script  type="text/jscript">
setTimeout(function() { document.payuForm.submit() }, 5000)
</script>

<div class="container marg_top" >
<div class="row">
<div class="col-md-12 registor">

<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): 

?>


<p style="text-align:left; color:#FF0000;"><?php echo $final_report; ?></p>
<?php if($shipdetails->status=='P') { echo "<h4 style='color:#008000;' >Thank you for shopping with us. Your order has been placed successfully, We will contact you shortly. </h4>"; } ?>

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


<p>&nbsp;</p>
<table width="100%" style="font-size:13px;">
<tr><td colspan="2"  class="hd_e"><u>Shipping Date & Time</u></td></tr>

<tr class="tr_2">
    <td width="40%">Delivery Type</td>
    <td width="60%">: &nbsp;&nbsp;<?php 
	
	if($shipdetails->dtype==1) { echo "Shop Delivery";}
	if($shipdetails->dtype==2) { echo "Door  Delivery";}
	
	?></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>Order Status</td>
    <td>: &nbsp;&nbsp;
     <?php

    switch($shipdetails->status)

	{

		case 'P' : $status =  'Pending' ; break; 

		case 'D' : $status =  'Couriered' ; break; 

		case 'C' : $status =  'Cancelled by you' ; break; 
		
		case 'A' : $status =  'Cancelled by Admin' ; break; 

		case '1' : $status =  'Confirmed' ; break; 

		default : $status =  'Pending' ; 

	}

	echo $status ;

	?>
    </td>
</tr> 


<tr class="tr_2">
    <td>Payment Method</td>
    <td>: &nbsp;&nbsp;<?php if($shipdetails->gifts==1){ echo "Cash On Delivery"; } elseif($shipdetails->gifts==2){  echo "Online Payment";  } else{  echo "Card on Delivery";  }?></td>
</tr> 


<tr class="tr_2">
    <td>Payment Status</td>
    <td>: &nbsp;&nbsp;
    
     <?php if($shipdetails->payment=='' || $shipdetails->payment=='0') {  echo"Not Paid"; } 
  elseif ($shipdetails->payment==1) { echo "Paid, Transaction Complete"; }
  elseif ($shipdetails->payment==3) { echo "Payment Failed"; }
  elseif ($shipdetails->payment==5) { echo "Paid, Transaction Complete"; }
  elseif ($shipdetails->payment==6) { echo "Paid, Transaction Complete"; }
 ?>
    
    </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>


<p>&nbsp;</p>
<table>
<tr><td colspan="2" class="hd_e" ><u>Shipping Details</u></td></tr>

<tr class="tr_2">
    <td width="30%">Name</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>Postal Area</td>
    <td>: &nbsp;&nbsp;<?=$shipdetails->post?></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 class="tr_2">
    <td>Pincode</td>
    <td>: &nbsp;&nbsp;<?=$shipdetails->pin?></td>
</tr>


<tr class="tr_2">
    <td>GST No.</td>
    <td>: &nbsp;&nbsp;<?=$shipdetails->gst?></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> Quantity</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') ; ?>"  align="right" />



<?php if($formError) { ?>
	
      <span style="color:red">Please fill all mandatory fields.</span>
      <br/>
      <br/>
    <?php } ?>
    
    
<h3>Payment Amount : <span style="color:#FF0000">Rs.  <?=$total_amt?></span> </h3>


<!--
 <form action="<?php echo $action; ?>" method="post" name="payuForm" id="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="<?php echo $txnid ?>" />

<input type="hidden" name="amount" value="<?=$total_amt?>" />
<input type="hidden"  name="firstname" id="firstname" value="<?=$shipdetails->name?>" />
<input type="hidden"  name="email" id="email" value="<?=$email?>" />
<input type="hidden"  name="phone" value="<?=$shipdetails->mobile?>" />
<textarea name="productinfo"  style="display:none;"><?=$shipdetails->order_id?></textarea>


<input type="hidden"  name="surl" value="https://www.edansemart.com/Userpage/payment_response"  />
<input type="hidden"  name="furl" value="https://www.edansemart.com/Userpage/payment_response"  />
<input type="hidden" name="service_provider" value="payu_paisa" size="64" />
        
         
<?php if($shipdetails->remove==1 || $shipdetails->payment==1 || $shipdetails->payment==5 || $shipdetails->payment==6 || $shipdetails->status==1  || $shipdetails->status=="D" || $shipdetails->status=="C" || $shipdetails->gifts==1  ) {} else { ?>
		 
		 <?php if(!$hash) { ?>
            <input type="submit" value="Pay Now" name="submit" class="btn btn-md btn-primary btn-block submito btn-danger" style="width:200px;"  />
      <?php }  else {?> <?php } } ?>
      
    </form>-->

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

</div>
</div></div>