MMCT TEAM
Server IP : 103.53.40.154  /  Your IP : 18.191.215.30
Web Server : Apache
System : Linux md-in-35.webhostbox.net 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64
User : ppcad7no ( 715)
PHP Version : 8.2.25
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0750) :  /home2/ppcad7no/kanoonisamadhan.in/../rajwadahouse.com/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home2/ppcad7no/kanoonisamadhan.in/../rajwadahouse.com/proceed-razorpay.php
<?php
include_once('site-main-query.php');

if ($_SERVER["REQUEST_METHOD"] === "POST") {
    if (isset($_POST['submit_btn1'])) {
        // Collect the form data
        $name = $_POST['name'];
        $phone = $_POST['phone'];
        $email = $_POST['email'];
        $state = $_POST['state'];
        $pin = $_POST['pin'];
        $payment_method = $_POST['payment_method'];
        $address = $_POST['address'];
        $book_by = $user_id;
        $offer_rate = isset($_POST['product_prices']) ? array_sum($_POST['product_prices']) : 0;
        $quantities = isset($_POST['product_quantities']) ? implode(',', $_POST['product_quantities']) : '';
        $property_name = isset($_POST['product_names']) ? implode(',', $_POST['product_names']) : '';

        // Set timezone and get the current time
        date_default_timezone_set("Asia/Kolkata");
        $currentTime = date("Y-m-d H:i:s");

        // Insert order details into the database
        $query = "INSERT INTO `tbl_booking`(`booking_name`, `state`, `pin`, `address`, `booking_for`, `contact`, `booking_email`, `booking_rate`, `checkin_date`, `quantities`, `payment_status`, `booking_status`, `book_by`) 
                  VALUES ('$name', '$state', '$pin', '$address', '$property_name', '$phone', '$email', '$offer_rate', '$currentTime', '$quantities', 'Pending', 'Pending', '$book_by')";
        $result = mysqli_query($db, $query) or die("Query unsuccessful");

        if ($result) {
            $order_id = mysqli_insert_id($db);

            // Proceed to Razorpay Payment Gateway if "Pay Now" is selected
            if ($payment_method == 'pay_now') { ?>
                <script src="https://checkout.razorpay.com/v1/checkout.js"></script>
                <script>
                    document.addEventListener("DOMContentLoaded", function () {
                        let packCost = "<?php echo $offer_rate; ?>";
                        let name = "<?php echo $name; ?>";
                        let email = "<?php echo $email; ?>";
                        let phone = "<?php echo $phone; ?>";
                
                        let options = {
                            "key": "rzp_live_1yHDjyMKHod20A",
                            "amount": packCost * 100,
                            "currency": "INR",
                            "name": "Product Payment",
                            "description": "Payment For Purchase Product",
                            "handler": function (response) {
                                let transactionId = response.razorpay_payment_id;

                                // Redirect to thank you page with details
                                let successURL = new URL('https://www.rajwadahouse.com/thankyou.php');
                                successURL.searchParams.set('payment_request_id', "<?php echo $order_id; ?>");
                                successURL.searchParams.set('payment_status', 'Credit');
                                successURL.searchParams.set('transaction_id', transactionId);
                                successURL.searchParams.set('ord_payment_gateway', 'Razorpay');
                                successURL.searchParams.set('pack_cost', packCost);
                                successURL.searchParams.set('name', name);
                                successURL.searchParams.set('email', email);
                                successURL.searchParams.set('phone', phone);

                                window.location.href = successURL.toString();
                            },
                            "prefill": {
                                "name": name,
                                "email": email,
                                "contact": phone
                            },
                            "theme": {
                                "color": "#3399cc"
                            }
                        };
                
                        let rzp1 = new Razorpay(options);
                        rzp1.on('payment.failed', function (response) {
                            let failureURL = new URL('https://www.rajwadahouse.com/failure.php');
                            failureURL.searchParams.set('pack_cost', packCost);
                            failureURL.searchParams.set('name', name);
                            failureURL.searchParams.set('email', email);
                            failureURL.searchParams.set('phone', phone);

                            window.location.href = failureURL.toString();
                        });

                        rzp1.open();
                    });
                </script>
            <?php 
            } else {
                // For COD (Cash on Delivery) or Pay Later
                echo "<script>
                    window.alert('Order placed successfully! We will contact you soon.');
                    window.location.href = 'https://www.rajwadahouse.com/thankyou.php';
                    </script>";
            }
        } else {
            echo "Error in processing your request. Please try again later.";
        }
    }
}
?>

MMCT - 2023