Server : LiteSpeed System : Linux us-phx-web1202.main-hosting.eu 4.18.0-553.84.1.lve.el8.x86_64 #1 SMP Tue Nov 25 18:33:03 UTC 2025 x86_64 User : u615232177 ( 615232177) PHP Version : 8.1.33 Disable Function : NONE Directory : /home/u615232177/public_html/ |
<?php session_start();
$page_name = basename($_SERVER['PHP_SELF']);
include("headerstrict.php"); ?>
<?php
if (isset($_GET['order_id'])){
$order_id = mysqli_real_escape_string($con,$_GET['order_id']);
$stmt = $con -> prepare('SELECT * FROM my_orders WHERE order_id=?');
$stmt -> bind_param('s',$order_id);
$stmt -> execute();
$stmt -> store_result();
$stmt -> bind_result($id,$user_id_db,$order_id,$total,$nice_date,$horrible_date,$status,$email_succesful,$email_delivered,$delivery_zone_complete,$payment_method);
$numrows = $stmt -> num_rows();
//status coloring
if($numrows > 0){
while ($stmt -> fetch()) {
$divided = explode('-',$delivery_zone_complete,2);
$delivery_zone_id = $divided[0];
$delivery_zone_fee = $divided[1];
//get the zone locations
$stmt_de = $con -> prepare('SELECT * FROM delivery_zones WHERE id = ?');
$stmt_de -> bind_param('s',$delivery_zone_id);
$stmt_de -> execute();
$stmt_de -> store_result();
$stmt_de -> bind_result($id_dz,$fee,$zone,$locations,$dis);
$numrows_de = $stmt_de -> num_rows();
if($numrows_de > 0){
while ($stmt_de -> fetch()) {}
}
if($status=="Pending"){$status_color="red";}
if($status=="Completed"){$status_color="forestgreen";}
}
}
else{echo "<meta http-equiv=\"refresh\" content=\"0; url=index.php\">";exit();}
//only owner can view
if($user_id == $user_id_db){
}
else{echo "<meta http-equiv=\"refresh\" content=\"0; url=index.php\">";exit();}
//convert to kobo for paystack
function to_kobo($value)
{
return intval(
strval(floatval(
preg_replace("/[^0-9.]/", "", $value)
) * 100)
);
}
//find out if this is the first payment
$stmt40 = $con -> prepare('SELECT id FROM my_orders WHERE user_id = ?');
$stmt40 -> bind_param('s',$user_id);
$stmt40 -> execute();
$stmt40 -> store_result();
$stmt40 -> bind_result($id43);
$numrows40 = $stmt40 -> num_rows();
if($numrows40 > 1){
while ($stmt40 -> fetch()) {$first_order = "false";}
}
else{$first_order = "true";}
//get percentage off
$stmt400 = $con -> prepare('SELECT * FROM top_stuff');
$stmt400 -> execute();
$stmt400 -> store_result();
$stmt400 -> bind_result($id433,$first_order_percentage);
$numrows400 = $stmt400 -> num_rows();
if($numrows400 > 0){
while ($stmt400 -> fetch()) {}
}
}
else{echo "<meta http-equiv=\"refresh\" content=\"0; url=index3.php\">";exit();}
?>
<title><?php echo $company_name; ?> - Order no <?php echo $order_id; ?></title>
<!-- Start All Title Box -->
<div class="all-title-box">
<div class="container">
<div class="row">
<div class="col-lg-12">
<h2>ORDER ID: <?php echo $order_id ?></h2>
<ul class="breadcrumb">
<li class="breadcrumb-item"><a href="#">Home</a></li>
<li class="breadcrumb-item active"><?php echo $order_id ?></li>
</ul>
</div>
</div>
</div>
</div>
<!-- End All Title Box -->
<div class="checkout">
<div class="container">
<div class="row">
<div class="col-lg-6">
<div class="billing"><br/><br/>
<div class="checkout_title">Order Details</div><br/>
<?php
$stmt1 = $con -> prepare('SELECT * FROM cart_details WHERE order_id=?');
$stmt1 -> bind_param('s',$order_id);
$stmt1 -> execute();
$stmt1 -> store_result();
$stmt1 -> bind_result($id,$order_id,$product_id,$product_title,$product_price,$product_image,$qty);
$numrows1 = $stmt1 -> num_rows();
if($numrows1 > 0){
while ($stmt1 -> fetch()) {
echo"
<a href='product_details.php?u=$product_id'>
<img src='$admin_no/assets/img/products/$product_image' alt='' style='width:100px;height:100px;border-radius:5px;'><br/>
<b>$product_title</b></a><br/>$currency";
echo number_format($product_price);
echo
"
<br/>Qty - $qty<hr/>";
$total = $qty * $product_price;
$total_array[] = $total;
}
echo"<b>Status</b> <span class='number_box_order' style='color:$status_color;'>$status</span><br/>";
$grand_total = array_sum($total_array); ?>
<?php
//check if they have money in the wallet.
$total_wallet=0; $success = "Success"; $failed = "Failed";
$stmt_withdraw = $con -> prepare('SELECT * FROM wallet WHERE user_id = ? AND status = ?');
$stmt_withdraw -> bind_param('ss',$user_id,$success);
$stmt_withdraw -> execute();
$stmt_withdraw -> store_result();
$stmt_withdraw -> bind_result($w_id,$wallet_id,$user_id,$wallet_order_id,$wallet_amount,$amount_remaining,$wallet_type,$wallet_action,$wallet_status,$wallet_date);
$numrows_withdraw = $stmt_withdraw -> num_rows();
if($numrows_withdraw > 0){
while ($stmt_withdraw -> fetch()) {
if($wallet_type == "Credit"){
$total_wallet += $wallet_amount;
}
if($wallet_type == "Debit"){
$total_wallet -= $wallet_amount;
}
}
}
//calculate first_order
if($first_order == "true"){
$percentInDecimal = $first_order_percentage / 100;
$first_order_off = $percentInDecimal * $grand_total;
}
else{
$first_order_off = 0;
}
//calculate bank charges
//$percentInDecimal = $percent_off / 100;
//$bank_charges = $percentInDecimal * $grand_total;
$bank_charges = 0;
//grand total
$gt = $grand_total + $delivery_zone_fee + $bank_charges;
//no coverage
$amount_payable = $gt - $first_order_off;
$amount_in_kobo = to_kobo($amount_payable);
//if partial coverage
$gt_balance = $gt - $total_wallet - $first_order_off;
$amount_in_kobo_balance = to_kobo("$gt_balance");
?>
<script>
function changePayment() {
const select_value = document.getElementById("payment_select").value;
const gt = parseInt(<?php echo $gt; ?>);
const first_order_off = parseInt(<?php echo $first_order_off; ?>);
const total_wallet = parseInt(<?php echo $total_wallet; ?>);
const amount_payable = 0;
if(select_value == "full_coverage"){
//submit buttons
btn_full_coverage.style.display = "block";
btn_no_coverage.style.display = "none";
btn_partial_coverage.style.display = "none"
//wallet
wallet_div.style.display = "block";
wallet_full = gt - first_order_off;
const formatted_wallet_full = wallet_full.toLocaleString("en-US");
const minus_currency = "-<?php echo $currency; ?>"
document.getElementById("wallet").innerHTML =minus_currency + formatted_wallet_full;
//amount payable
const formatted_amount_payable = amount_payable.toLocaleString("en-US");
const currency = "<?php echo $currency; ?>"
document.getElementById("amount_payable").innerHTML =currency + formatted_amount_payable;
}
if(select_value == "no_coverage"){
//submit buttons
btn_full_coverage.style.display = "none";
btn_no_coverage.style.display = "block";
btn_partial_coverage.style.display = "none"
wallet_div.style.display = "none";
const amount_payable_no_cover = gt - first_order_off;
//amount payable full price - first order
const formatted_amount_payable_no_cover = amount_payable_no_cover.toLocaleString("en-US");
const currency = "<?php echo $currency; ?>"
document.getElementById("amount_payable").innerHTML =currency + formatted_amount_payable_no_cover;
}
if(select_value == "partial_coverage"){
//submit buttons
btn_full_coverage.style.display = "none";
btn_no_coverage.style.display = "none";
btn_partial_coverage.style.display = "block"
wallet_div.style.display = "block";
const formatted_total_wallet = total_wallet.toLocaleString("en-US");
const minus_currency = "-<?php echo $currency; ?>"
document.getElementById("wallet").innerHTML =minus_currency + formatted_total_wallet;
//amount payable
const amount_payable_partial = gt - total_wallet - first_order_off
const formatted_amount_payable_partial = amount_payable_partial.toLocaleString("en-US");
const currency = "<?php echo $currency; ?>"
document.getElementById("amount_payable").innerHTML =currency + formatted_amount_payable_partial;
}
}
</script>
<?php
echo"
<div class='lineo'></div>
<b>Subtotal</b><span class='number_box_order'>$currency";echo number_format($grand_total);echo"</span><br/>
<b>Shipping Fee</b><span class='number_box_order'>$currency";echo number_format($delivery_zone_fee);echo"</span><br>Zone $zone <span style='font-size:;'>$locations <br></span>
<b>Bank Charges</b><span class='number_box_order'>$currency";echo number_format($bank_charges); echo"</span><br>";
echo"<div class='lineo'></div>";
echo"<b>Total</b> <span class='number_box_order the_color'>$currency";echo number_format($gt);echo"
</span><br>";
echo"<div class='lineo'></div>";
//first order
if($first_order == "true"){
echo"<b>$first_order_percentage% off first order!</b>
<span class='number_box_order' style='color:forestgreen;'>-
$currency"; echo number_format($first_order_off);echo"
</span>";
}
// wallet
echo"
<div class='hid' id='wallet_div'>
<b>Wallet</b>
<span id='wallet' class='number_box_order' style='color:forestgreen;'></span>
</div>";
// amount payable
echo"
<div id='amount_payable_div'>
<b>Amount Payable</b>
<span id='amount_payable' class='number_box_order the_color'>$currency";echo number_format($amount_payable);echo"</span>
</div>";
echo"<br/><br/>";
}
else{//echo "<meta http-equiv=\"refresh\" content=\"0; url=index4.php\">";exit();
}
?>
</div>
</div>
<div class="col-lg-6">
<div class="billing"><br/><br/>
<div class="checkout_title">Pay Online</div><br/>
<form method="POST" action="payment_result_full_coverage.php" class="php-email-form1">
<script src="https://js.paystack.co/v1/inline.js"></script>
<div style="text-align: center;">
<img src="images/paystack.png" style='width:100%;'/>
</div>
<br/><br/>
<select class="form-control valid" id="payment_select" onchange="changePayment()" name='payment_select' required>
<option value=''>Please choose a payment option</option>
<?php
//if wallet balance can cover the purchase, show this option.
if($total_wallet >= $gt){
?>
<option value="full_coverage">Pay using funds in your wallet. No further payment will be due</option>
<?php
}
?>
<?php
//if wallet balance cannot cover the purchase, show this option.
if($total_wallet > 0 AND $total_wallet < $gt){
?>
<option value="partial_coverage">Use funds in your wallet, then pay the balance now</option>
<?php
}
?>
<option value="no_coverage">Pay full amount using the payment method shown below.</option>
</select>
<br>
<div class="text-center">
<input type="hidden" name='order_id' value='<?php echo $order_id; ?>'>
<button type="submit" name='full_coverage' id='btn_full_coverage' class="btn hvr-hover hid"> Proceed
</button>
<button type="button" id='btn_no_coverage' class="btn hvr-hover hid" onclick="payWithPaystack()"> Pay <?php echo $currency ?><?php echo number_format($amount_payable); ?> Securely
</button>
<button type="button" id='btn_partial_coverage' class="btn hvr-hover hid" onclick="payWithPaystack1()"> Pay <?php echo $currency ?><?php echo number_format($gt_balance); ?> Securely
</button>
</div> <br><br>
</form>
<script>
function payWithPaystack(){
var handler = PaystackPop.setup({
key: 'pk_live_5a9121c182f74f9155a6dae11b69f3f982a56263',
email: '<?php echo $email; ?>',
amount: <?php echo $amount_in_kobo; ?>,
callback: function(response){
//alert('success. transaction ref is ' + response.reference);
window.location = "payment_result.php?<?php echo "order_id=$order_id&action=Paystack Payment&amount_paid=$amount_payable&"; ?>reference=" + response.reference;
},
onClose: function(){
//alert('window closed');
}
});
handler.openIframe();
}
</script>
<script>
function payWithPaystack1(){
var handler = PaystackPop.setup({
key: 'pk_live_5a9121c182f74f9155a6dae11b69f3f982a56263',
email: '<?php echo $email; ?>',
amount: <?php echo $amount_in_kobo_balance; ?>,
callback: function(response){
//alert('success. transaction ref is ' + response.reference);
window.location = "payment_result.php?<?php echo "order_id=$order_id&action=Wallet and Paystack Payment&amount_paid=$gt_balance&"; ?>reference=" + response.reference;
},
onClose: function(){
//alert('window closed');
}
});
handler.openIframe();
}
</script>
</div>
</div>
</div>
</div>
</div>
<?php include("footer.php"); ?>