<?php use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'PHPMailer/Exception.php';
require 'PHPMailer/PHPMailer.php';
require 'PHPMailer/SMTP.php';
$logo = "https://www.orangegroceries.com/img/logo.png";
    $logo_width = "100%";
    $logo_height = "";
    // All CSS
    // Body
    $body_title = "Orange Groceries";
    $width_of_mail_body = "80%"; // Please write in % percentage for better view...
    $padding_of_mail_body = "20px";
    $body_background_color = "";
    $body_text_color = "";
    // Header
    $header_background_color = "";
    $header_text_color = "";
    $header_font_size = "";
    $header_font_family = "";
    // Footer
    $footer_background_color = "#2F3B59";
    $footer_text_color = "white";
    $footer_font_size = "10px";
    $footer_font_family = "monospace";
    // Button
    $button_background_color = "#4db7fe";
    $button_text_color = "white";
    $button_font_size = "20px";
    $button_font_family = "monospace";
    $button_padding = "15px";
    $button_border_radius = "10px";
    // Highlight
    $highlight_color = "#4db7fe";
    $highlight_font_size = "25px";
    $highlight_font_family = "monospace";
    // Heading
    $heading_color = "#4db7fe";
    $heading_font_size = "25px";
    $heading_font_family = "monospace";
    // Paragraph
    $paragraph_color = "";
    $paragraph_font_size = "14px";
    $paragraph_font_family = "monospace";
    // Write the email id and team name that you send From
    $from_team = "Anajghar";
   $from_email = "support@orangegroceries.com";
   $from_website = "http://orangegroceries.com/index.php";

include("db_config.php"); 
if($_SERVER['REQUEST_METHOD']=='POST'){
extract($_POST);
     date_default_timezone_set('Asia/Kolkata');
    $created_at = date( 'Y-m-d h:i:s A', time () );
    $transactionId=$_POST['transactionId']; 
    $payment_method="Razorpay";
    $payment_status="completed";
    $statuss=1;
$sql_pay ="UPDATE  user_payment SET payment_method='$payment_method',pay_status='$payment_status',payment_id='$payment_id',transactionId='$transactionId',payable_status='$statuss',created_date='$created_at' WHERE order_id='".$order_id."'"; 
if  (mysqli_query($conn, $sql_pay))
{ $sql_pet="select * from user_payment where order_id='".$order_id."'";
    $relt_ptm = mysqli_query($conn, $sql_pet);
    $res_pt= mysqli_fetch_array($relt_ptm);
    $id=$res_pt['id']; 
    $order_id=$res_pt['order_id'];
    $cart_id=$res_pt['cart_id'];
     $rid = explode(",",$cart_id);  
    foreach($rid as $pm_id){
     $stat="1";
     $statuss="0";
     $sql_paytmss ="UPDATE  addto_cart SET payment_status='$stat',invoice_id='$statuss' WHERE id='".$pm_id."'"; 
     $result_ptmss=mysqli_query($conn,$sql_paytmss) or die(mysqli_error());
     }
      $user_id=$res_pt['user_id'];
     $sql1=mysqli_query($conn, "select * from user_profile where id=".$user_id);
    $row1=mysqli_fetch_array($sql1);
    $email = $row1['email'];
    $name = $row1['fname'];
    $date = date("d-m-Y");
    $to = $email;
    $subject = "Order Placed And Payment Successfully Completed";
    $message = "
                <html>
                    <head>
                        <title>$body_title</title>
                    </head>
                    <body style='background-color: $body_background_color; color: $body_text_color;'>
                        <center>
                            <div style='width: $width_of_mail_body; padding: $padding_of_mail_body;' >
                                <br/><br/>
                                <p style='color: $paragraph_color; font-size: $paragraph_font_size; font-family: $paragraph_font_family;'> 
                                    <span style='color: $highlight_color; font-size: $highlight_font_size; font-family: $highlight_font_family;'>
                                        Hi $name,
                                    </span> 
                                    <br/>
                                    Welcome to <span style='color: $highlight_color; font-size: $highlight_font_size; font-family: $highlight_font_family;'> $from_team</span>, Your Order Placed And Payment successfully Completed <br/> Thankyou!!!
                                </p>
                                <br/><br/><br/><br/>
                                <div style='width: 100%; background-color: $footer_background_color; color: $footer_text_color; font-family: $footer_font_family; font-size: $footer_font_size; padding-top: 30px; padding-bottom: 30px;'>
                                    Thanks And Regards
                                    <br/>
                                    <span style='color: white;'>$from_website</span>
                                </div>
                            </div>
                        </center>
                    </body>
                </html>";
   $email = new PHPMailer();
   $email->Body      =  ($message);
   $email->SetFrom('support@orangegroceries.com', 'Anajghar'); //Name is optional
   $email->Subject   ="Order Placed And Payment Successfully Completed";
   $email->IsHTML(true);
   $email->Body      =  ($message);
   $email->AddAddress($to);
   if (! $email->Send()) {
       //echo "<script>alert('Problem in sending email!');</script>";
    } else {
    $sql1=mysqli_query($conn, "select * from user_profile where id=".$_SESSION['user_id']);
    $row1=mysqli_fetch_array($sql1);
    $phone = $_SESSION['mob_no'];
    $user_id = $_SESSION['id'];
    $email = $row1['email'];
    $name = $row1['fname'];
    $date = date("d-m-Y");
    $to = "support@orangegroceries.com";
    $subject = "Order Placed And Payment Successfully Completed";
     $message = "
                <html>
                    <head>
                        <title>$body_title</title>
                    </head>
                    <body style='background-color: $body_background_color; color: $body_text_color;'>
                        <center>
                            <div style='width: $width_of_mail_body; padding: $padding_of_mail_body;' >
                                <br/><br/>
                                <p style='color: $paragraph_color; font-size: $paragraph_font_size; font-family: $paragraph_font_family;'> 
                                    <span style='color: $highlight_color; font-size: $highlight_font_size; font-family: $highlight_font_family;'>
                                        Hi Team,
                                    </span> 
                                    <br/>
                                    Order Placed By <span style='color: $highlight_color; font-size: $highlight_font_size; font-family: $highlight_font_family;'> $name</span>, Payment successfully Completed By Razorpay ..<br/> !!!
                                </p>
                            </div>
                        </center>
                    </body>
                </html>";
   $email = new PHPMailer();
$email->Body      =  ($message);
$email->SetFrom('support@orangegroceries.com', 'Anajghar'); //Name is optional
$email->Subject   = $name . " Placed An Order";
$email->IsHTML(true);
$email->Body      =  ($message);
$email->AddAddress('support@orangegroceries.com' );
   if (! $email->Send()) {
    } else { }
 }
$response['id']=$id;   
$response['status']=1;
}else{
$response['status']=0;
}
	echo json_encode($response);
	mysqli_close($conn);
}

?>