BLACKSITE
:
216.73.217.4
:
104.37.75.190 / alpenpass.ca
:
Linux server3.pointsplan.com 5.14.0-503.38.1.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Apr 18 08:52:10 EDT 2025 x86_64
:
/
home
/
apca
/
www
/
Upload File:
files >> /home/apca/www/rental_checkout.php
<?php session_start(); include('includes/config.php'); function getAllRentalCartItems($dbh, $user_id) { // Prepare and execute the query to get all rental items for the user $stmt = $dbh->prepare("SELECT * FROM rental_cart WHERE user_id = :user_id ORDER BY created_at DESC"); $stmt->bindParam(':user_id', $user_id, PDO::PARAM_STR); $stmt->execute(); // Fetch all rows as an associative array return $stmt->fetchAll(PDO::FETCH_ASSOC); } if (!isset($_SESSION['login'])) { header("Location: index2.php?message=Please Log In To View Checkout"); die; } $head.=" <style> .imageBox{ height: 450px; overflow:hidden; } .imageStyle{ width: 100%; object-fit: cover; min-height: 450px; } #rateList .currency{ text-align:right; } #rateList td{ font-weight: bold; } .fr{ text-align: right; padding-right: 20px; } .error-message { color: red; font-size: 0.9em; margin-top: 5px; display: none; position: relative; /* changed from absolute to relative */ } .form-group { position: relative; margin-bottom: 20px; } .form-group.has-error { margin-bottom: 40px; /* Increase margin when error is shown */ } form{ font-size: 18px; } form input{ min-width: 300px; } </style> <script src=\"https://js.stripe.com/v3/\"></script> "; include("includes/head.php"); include("includes/header.php"); /** $fromdate = $_SESSION['fromdate']; $todate = $_SESSION['todate']; $vehicleName = $_SESSION['vehicleName']; $vehicleID = $_SESSION['vehicleID']; $message = $_SESSION['message']; $useremail = $_SESSION['login']; $rateName = $_SESSION['rateName']; $bookingno = $_SESSION['bookingno']; $deposit = $_SESSION['deposit']; */ // Ensure user is logged in $user_email = $_SESSION['login']; // Use email as user_id $user_id=$_SESSION['id']; // Fetch all rental cart details from the database $cart_items = getAllRentalCartItems($dbh, $user_id); if (!$cart_items) { die("Error: No rental cart found."); } // Debug output (optional) //echo "<pre>"; //print_r($cart_items); //echo "</pre>"; // Initialize totals $total_due = 0; $taxable_total = 0; $gst_total = 0; $pst_total = 0; // Loop through all rental items $grand_total=0; $grand_total_rental_fee=0; foreach ($cart_items as $item) { $total=0; $fromdate = $item['from_date']; $todate = $item['to_date']; $vehicleName = $item['vehicle_name']; $vehicleID = $item['vehicle_id']; $message = $item['message']; $rateName = $item['rate_name']; $bookingno = $item['booking_no']; //$deposit = $item['security_deposit']; $amount_charged = $item['amount_charged']; $insurance_fee= $item['insurance_fee']; $vehicleList.=$vehicleName.", "; // $total=$deposit+$amount_charged+$insurance_fee; $total=$amount_charged+$insurance_fee; // $gst=($total-$deposit)*.05; // $pst=($total-$deposit)*.07; $gst=($total)*.05; $pst=($total)*.07; $grand_total+=$total+$gst+$pst;; $grand_total_rental_fee+=$amount_charged; //$grand_total_deposit+=$deposit; ob_start(); print_r($item); $xxx=ob_get_clean(); // echo "Got to line ".__LINE__." in ".__FILE__." xxx is $xxx and grand_total is $grand_total and grand_total_deposit is $grand_total_deposit and grand_total_rental_fee is $grand_total_rental_fee<br />"; } $totalDue=$grand_total; ?> ?> <div class="container"> <div class="row justify-content-center"> <div class="col-sm-12"> <h1><br />Motorcycle Rental Checkout<br /></h1> <?php $ret="SELECT * FROM tblbooking where (:fromdate BETWEEN date(FromDate) and date(ToDate) || :todate BETWEEN date(FromDate) and date(ToDate) || date(FromDate) BETWEEN :fromdate and :todate) and VehicleId=:vehicleID"; $query1 = $dbh -> prepare($ret); $query1->bindParam(':vehicleID',$vehicleID, PDO::PARAM_STR); $query1->bindParam(':fromdate',$fromdate,PDO::PARAM_STR); $query1->bindParam(':todate',$todate,PDO::PARAM_STR); $query1->execute(); $results1=$query1->fetchAll(PDO::FETCH_OBJ); if($query1->rowCount()>0) { ?> <h2><br />The <?php echo $vehicleName; ?> is already booked for the dates and times you chose.</h2> <h2><br />Please return to our Motorcycle Listings page and choose another vehicle, or choose other dates.</h2><br /><br /> <a href="listing.php" class="btn">Listings <span class="angle_arrow"><i class="fa fa-angle-right" aria-hidden="true"></i></span></a> <?php }else{ ?> <h2><br />Rental for the <?php echo trim($vehicleList,","); ?></h2> <h2>The Rental Fee is: <?php echo number_format($grand_total_rental_fee,2); ?><br /><br /> You are being charged today $<?php echo number_format($totalDue,2); ?> which also includes insurance and tax.</h2><br /><br /><h5><h3>A deposit of $<?php echo number_format($item['security_deposit'],2); ?> is due at the time of rental, and will be returned providing there is no damage to the vehicle.</h3></h5> <br /><br /> <form id="payment-form"> <label for="customer-name">Name</label> <input type="text" id="customer-name" name="name" placeholder="Your Name" required value="<?php echo $_SESSION['fname'];?>"><br /><br /> <label for="customer-email">Email</label> <input type="email" id="customer-email" name="email" placeholder="Your Email" required value="<?php echo $user_email;?>" readonly><br /><br /> <label for="total-amount">Amount</label> <h3>$ <?php echo number_format($totalDue, 2); ?></h3> <input type="hidden" id="total-amount" name="amount" value="<?php echo $totalDue; ?>"> <br /><br /> <button type="button" id="checkout-button">Pay Now</button> </form> </div> </div> </div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /> <?php } ?> <script> const stripe = Stripe('pk_test_51QGPzg2K4CCTmLnJR9zpSF379OewtVdx4P3OkWX8YMEq47C1XgOLlIQLiBN1j9ZRNi0P1ShpIBRxYLTmKfA6I7Jf00qrQtDE2t'); document.getElementById('checkout-button').addEventListener('click', async () => { const name = document.getElementById('customer-name').value; const email = document.getElementById('customer-email').value; const amount = document.getElementById('total-amount').value; try { const response = await fetch('/create-checkout-session.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name, email, amount }), }); if (!response.ok) { throw new Error('Failed to create checkout session'); } const session = await response.json(); if (session.id) { await stripe.redirectToCheckout({ sessionId: session.id }); } else { throw new Error('Session ID is missing in the response'); } } catch (error) { console.error('Error during checkout:', error); alert('An error occurred. Please try again.'); } }); </script>