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 use PHPMailer\PHPMailer\PHPMailer;use PHPMailer\PHPMailer\Exception;use PHPMailer\PHPMailer\SMTP; session_start();
$page_name = basename($_SERVER['PHP_SELF']);
include("headerstrict.php"); ?>
<title><?php echo $company_name; ?> - Payment Result</title>
<?php
$stmt40 = $con -> prepare('SELECT * FROM top_stuff');
$stmt40 -> execute();
$stmt40 -> store_result();
$stmt40 -> bind_result($id43,$first_order_percentage);
$numrows40 = $stmt40 -> num_rows();
if($numrows40 > 0){
while ($stmt40 -> fetch()) {
}}
?>
<div class="all-title-box">
<div class="container">
<div class="row">
<div class="col-lg-12">
<h2>Payment Result</h2>
<ul class="breadcrumb">
<li class="breadcrumb-item"><a href="#">Home</a></li>
<li class="breadcrumb-item active"></li>
</ul>
</div>
</div>
</div>
</div>
<!-- End All Title Box -->
<div class="checkout">
<div class="container">
<div class="row">
<div class="col-lg-6 pt-4 pt-lg-0">
<?php
if($_SERVER['REQUEST_METHOD'] == 'GET' ){
$paystack_reference = mysqli_real_escape_string($con,$_GET['reference']);
$order_id = mysqli_real_escape_string($con,$_GET['order_id']);
$action = mysqli_real_escape_string($con,$_GET['action']);
$amount_paid = mysqli_real_escape_string($con,$_GET['amount_paid']);
$stmt_order = $con -> prepare('SELECT * FROM my_orders WHERE order_id=?');
$stmt_order -> bind_param('s',$order_id);
$stmt_order -> execute();
$stmt_order -> store_result();
$stmt_order -> bind_result($id,$user_id_db,$order_id,$grand_total,$nice_date,$horrible_date,$order_status,$email_succesful,$email_delivered,$delivery_zone_complete,$payment_method);
$numrows_order = $stmt_order -> num_rows();
if($numrows_order > 0){
while ($stmt_order -> fetch()) { }
}
$divided = explode('-',$delivery_zone_complete,2);
$delivery_zone_id = $divided[0];
$delivery_zone_fee = $divided[1];
$stmt_n = $con -> prepare('SELECT * FROM users WHERE user_id=?');
$stmt_n -> bind_param('s',$user_id_db);
$stmt_n -> execute();
$stmt_n -> store_result();
$stmt_n -> bind_result($id,$user_id,$first_name,$last_name,$email,$password,$phone,$address,$date_signed_up);
$numrows_n = $stmt_n -> num_rows();
if($numrows_n > 0){
$signed_in="Yes";
while ($stmt_n -> fetch()) { }
}
//find out if this is the first payment
$stmt4000 = $con -> prepare('SELECT id FROM my_orders WHERE user_id = ?');
$stmt4000 -> bind_param('s',$user_id);
$stmt4000 -> execute();
$stmt4000 -> store_result();
$stmt4000 -> bind_result($id43yy);
$numrows4000 = $stmt4000 -> num_rows();
if($numrows4000 > 1){
while ($stmt4000 -> fetch()) {$first_order = "false";}
}
else{$first_order = "true";}
//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;
$gt = $grand_total + $delivery_zone_fee + $bank_charges - $first_order_off;
if($action == "Wallet and Paystack Payment"){
//remove the money from the wallet
//recalculate the gt
//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;
}
}
}
//does total wallet and amount paid add up to the money due(gt)?
$amount_person_paid = $total_wallet + $amount_paid;
if($amount_person_paid >= $gt){
//then we can update the wallet and continue with giving value
$wallet_id = substr(md5(rand()), 0, 20);
$fund_amount = $total_wallet;
$amount_remaining=$amount_paid;
$db_id=0;
$type="Debit";
$success = "Success";
$date_wallet = date('Y-m-d H:i:s');
$stmt_wa = $con -> prepare('INSERT INTO wallet VALUES (?,?,?,?,?,?,?,?,?,?)');
$stmt_wa -> bind_param('isssssssss', $db_id,$wallet_id,$user_id,$order_id,$fund_amount,$amount_remaining,$type,$action,$success,$date_wallet);
$stmt_wa -> execute();
//update the gt to now reflect only the amount paid via paystack
$gt = $amount_paid;
}
else{
//the transaction is not valid and should fail
echo "<meta http-equiv=\"refresh\" content=\"0; url=index.php\">";exit();
}
}
$result = array();
//The parameter after verify/ is the transaction reference to be verified
$url = "https://api.paystack.co/transaction/verify/$paystack_reference";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt(
$ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer sk_live_3f04af71e1698ab46bf9b05346ea594dcf8a34a3']
);
$request = curl_exec($ch);
curl_close($ch);
if ($request) {
$result = json_decode($request, true);
//print_r($result);
if($result){
if($result['data']){
//something came in
if($result['data']['status'] == 'success'){
// the transaction was successful, you can deliver value
$status = $result['data']['status'];
$gateway_response = $result['data']['gateway_response'];
$transaction_date = $result['data']['transaction_date'];
echo"<span class='explanation'>Your transaction reference is </span><span class='blue'>$paystack_reference</span><br/>";
echo "<span class='explanation'>The transaction was <span class='blue'>successful.</span></span><br/>";
echo "<span class='explanation'>Transaction Date - <span class='blue'>$transaction_date.<span></span><br/>";
$stmt_asake = $con -> prepare('SELECT * FROM transactions WHERE paystack_reference=?');
$stmt_asake -> bind_param('s',$paystack_reference);
$stmt_asake -> execute();
$stmt_asake -> store_result();
$numrows_asake = $stmt_asake -> num_rows();
if($numrows_asake < 1){
//send email
$subject ="$first_name $last_name successfully paid online";
$message1="";
$message1 .= "
<div style='font-family:Calibri;'>
Name - <b>$first_name $last_name</b><br/>
Email - <b>$email</b><br/>
Amount - <b>$gt</b><br/>
Ref - <b>$paystack_reference</b><br/>
Response - <b>$gateway_response</b><br/>
Date - <b>$transaction_date</b><br/>
Payment Method - <b>$action</b><br/>
Details of order <b style='color:cornflowerblue;'>$order_id</b><br/>
</div>
";
$che = mysqli_query($con,"SELECT * FROM cart_details WHERE order_id='$order_id'");
if (mysqli_num_rows($che) > 0) {
while ($get = mysqli_fetch_array($che)) {
$product_id = $get["product_id"];
$product_title = $get["product_title"];
$product_image = $get["product_image"];
$product_price = $get["product_price"];
$qty = $get["qty"];
$message1 .="
<img src='$link/$admin_no/assets/img/products/$product_image' alt='$product_title' style='width:70px;height:70px;'>
<h5 style='font-weight:700;font-size:14px;line-height:1px;'>$product_title</h5>
<p style='font-size:10px;line-height:1px;'>$currency$product_price.00</p>
<p style='font-size:10px;line-height:1px;'>Quantity - $qty</p>
<div style='color:gainsboro;opacity:0.5;'><hr/></div>
";
}
}
$message1 .="
<span style='font-weight:900;'>$currency$delivery_zone_fee.00</span> - Shipping Fee<br/>
<span style='font-weight:900;'>$currency$gt.00</span> - Total<br/><br/>
";
date_default_timezone_set('Africa/Lagos');
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
require 'PHPMailer/src/Exception.php';
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "smtp.titan.email"; // sets the SMTP server
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Set encryption to STARTTLS
$mail->Port = 587; // Use port 587 for TLS
$mail->Username = "$no_reply_email"; // SMTP account username
$mail->Password = "$no_reply_password"; // SMTP account password
$mail->SetFrom("$no_reply_email", "$company_name");//Use a fixed address in your own domain as the from address
$mail->AddReplyTo("$company_email","$company_name"); //Put the submitter's address in a reply-to header
$mail->Subject = "$subject";
$mail->MsgHTML("<html><body>$message1</body></html>");
$mail->AddAddress("$company_email", 'Payment Page');//Send the message to yourself, or whoever should receive contact for submissions
//$mail->AddAttachment(""); // attachment
if(!$mail->Send()) {
//echo "Mailer Error: " . $mail->ErrorInfo;
$msg = 'Email not sent, please try again';
}
else {
//echo "Thanks for getting in touch, we will get back to ASAP";
$msg = "Hey $first_name thanks for getting in touch, we will get back to you ASAP!";
}
//email an autoresponse to the person too
$mail->clearAddresses();
$mail->clearReplyTos();
$subject = "$first_name thank you for your order $order_id";
$message="";
$button_link="$link/sign_in.php";
$button_text="Log in";
$email_topic="Your order has been successfully paid for.";
include("email_header.php");
$message .= "
Dear $first_name,<br/><br/>
Thank you for shopping up with us at $company_name.Your payment has been received and your order is now being processed.<br/>If you have any questions please contact our dedicated support staff at $company_email<br/><br/>
The $company_name Team.<br/><br/>
Please find the details of your order below:<br/>";
$che = mysqli_query($con,"SELECT * FROM cart_details WHERE order_id='$order_id'");
if (mysqli_num_rows($che) > 0) {
while ($get = mysqli_fetch_array($che)) {
$product_id = $get["product_id"];
$product_title = $get["product_title"];
$product_image = $get["product_image"];
$product_price = $get["product_price"];
$qty = $get["qty"];
$message .="
<img src='$link/$admin_no/assets/img/products/$product_image' alt='$product_title' style='width:70px;height:70px;'>
<h5 style='font-weight:700;font-size:14px;line-height:1px;'>$product_title</h5>
<p style='font-size:10px;line-height:1px;'>$currency$product_price.00</p>
<p style='font-size:10px;line-height:1px;'>Quantity - $qty</p>
<div style='color:gainsboro;opacity:0.5;'><hr/></div>
";
}
}
$message.="$email_logo<br/><br/>
";
include("email_footer.php");
$mail->SetFrom("$no_reply_email", "$company_name");//Use a fixed address in your own domain as the from address
$mail->AddAddress("$email", "$email");//Send the message to yourself, or whoever should receive contact for submissions
$mail->AddReplyTo("$company_email","$company_name"); //Put the submitter's address in a reply-to header
$mail->Subject = "$subject";
$mail->MsgHTML("$message");
if(!$mail->Send()) {
//echo "Mailer Error: " . $mail->ErrorInfo;
$msg = 'Email not sent, please try again';
}
else {
//echo "Thanks for getting in touch, we will get back to ASAP";
$msg = "Hey $first_name thanks for getting in touch, we will get back to you ASAP.";
}
//send notification
$content ="Your order $order_id has been successfully paid for";
$sender ="System";
$receiver = "$user_id";
$seen ="No";
$date_notification = date("D,dS M, Y g:ia");
mysqli_query($con,"INSERT INTO notifications VALUES(
'0',
'$content',
'$sender',
'$receiver',
'$seen',
'$date_notification'
)")or die(mysqli_error($con));
$completed="Completed";
$stmt_com = $con -> prepare('UPDATE my_orders SET status = ? WHERE order_id = ?');
$stmt_com -> bind_param('ss', $completed,$order_id);
$stmt_com -> execute();
$stmt = $con -> prepare('SELECT * FROM transactions WHERE paystack_reference=?');
$stmt -> bind_param('s',$paystack_reference);
$stmt -> execute();
$stmt -> store_result();
$numrows = $stmt -> num_rows();
if($numrows < 1){
$db_id=0;
$stmt = $con -> prepare('INSERT INTO transactions VALUES (?,?,?,?,?,?,?)');
$stmt -> bind_param('issssss', $db_id,$order_id,$gt,$paystack_reference,$status,$gateway_response,$transaction_date);
$stmt -> execute();
}
}
echo"
<form action='your_account.php' action='post'>
<div style='text-align: center;'>
<button class='btn btn-medium' style='background:$color;color:white;' type='submit'>Go to Account</button>
</div> <br><br>
</form>
";
}
else{
// the transaction was not successful, do not deliver value'
//print_r($result); //uncomment this line to inspect the result, to check why it failed.
$status = $result['data']['status'];
$gateway_response = $result['data']['gateway_response'];
$transaction_date = $result['data']['transaction_date'];
echo"<span class='explanation'>Your transaction reference is </span><span class='blue'>$paystack_reference</span><br/>";
echo "<span class='explanation'>The transaction was <span class='blue'> NOT successful.</span></span><br/>";
echo "<span class='explanation'>Gateway Response - <span class='blue'>$gateway_response.<span></span><br/>";
echo "<span class='explanation'>Transaction Date - <span class='blue'>$transaction_date.<span></span><br/>";
//insert transaction details into database
$stmt = $con -> prepare('SELECT * FROM transactions WHERE paystack_reference=?');
$stmt -> bind_param('s',$paystack_reference);
$stmt -> execute();
$stmt -> store_result();
$stmt -> bind_result($id,$heading,$paragraph,$picture);
$numrows = $stmt -> num_rows();
if($numrows < 1){
$db_id=0;
$stmt = $con -> prepare('INSERT INTO transactions VALUES (?,?,?,?,?,?,?)');
$stmt -> bind_param('issssss', $db_id,$order_id,$gt,$paystack_reference,$status,$gateway_response,$transaction_date);
$stmt -> execute();
}
echo"
<form action='your_account.php' action='post'>
<div style='text-align: center;'>
<button class='btn btn-medium' style='background:$color;color:white;' type='submit'>Back</button>
</div>
</form>
";
}
}
else{
echo $result['message'];
}
}
else{
//print_r($result);
die("Something went wrong. Please try again later.");
}
}
else{
//var_dump($request);
die("Something went wrong. Please try again later.");
}
}
else{echo "<meta http-equiv=\"refresh\" content=\"0; url=index.php\">";}
?>
</div>
</div>
</div>
</div>
</main>
<?php include("footer.php"); ?>