HEX
Server: Apache
System: Linux gains.arrowcloudlinux.com 4.18.0-553.69.1.lve.el8.x86_64 #1 SMP Wed Aug 13 19:53:59 UTC 2025 x86_64
User: mbkashyap (2642)
PHP: 8.1.33
Disabled: allow_url_include, show_source, symlink, system, passthru, exec, popen, pclose, proc_open, proc_terminate,proc_get_status, proc_close, proc_nice, allow_url_fopen, shell-exec, shell_exec, fpassthru, base64_encodem, escapeshellcmd, escapeshellarg, crack_check,crack_closedict, crack_getlastmessage, crack_opendict, posix_kill, posix_mkfifo, posix_setpgid, posix_setsid, posix_setuid, dl, escap, phpinfo
Upload Files
File: /home/mbkashyap/public_html/wp-content/plugins/astrology-booking/functions.php
<?php
// Include Razorpay SDK and import namespace at the top
require_once ASTRO_BOOKING_PATH . 'assets/lib/razorpay-php/Razorpay.php';
use Razorpay\Api\Api;

// Ajax handler for fetching availability
add_action('wp_ajax_get_availability', 'astro_get_availability');
function astro_get_availability() {
    global $wpdb;
    $table_name = $wpdb->prefix . 'astro_availability';
    $results = $wpdb->get_results("SELECT avail_date, start_time, end_time, price FROM $table_name");
    
    $events = [];
    foreach ($results as $slot) {
        $events[] = [
            'title' => 'Available - ₹' . $slot->price,
            'start' => $slot->avail_date . 'T' . $slot->start_time,
            'end' => $slot->avail_date . 'T' . $slot->end_time,
            'color' => '#4CAF50'
        ];
    }
    
    wp_send_json($events);
}

// Ajax handler for booking
add_action('wp_ajax_book_appointment', 'astro_book_appointment');
add_action('wp_ajax_nopriv_book_appointment', 'astro_book_appointment');
function astro_book_appointment() {
    global $wpdb;
    $table_name = $wpdb->prefix . 'astro_appointments';
    
    $client_name = sanitize_text_field($_POST['client_name']);
    $client_email = sanitize_email($_POST['client_email']);
    $date = sanitize_text_field($_POST['date']);
    $time = sanitize_text_field($_POST['time']);
    $price = floatval($_POST['price']);
    
    // Verify availability
    $avail_table = $wpdb->prefix . 'astro_availability';
    $available = $wpdb->get_var($wpdb->prepare(
        "SELECT COUNT(*) FROM $avail_table WHERE avail_date = %s AND start_time <= %s AND end_time >= %s",
        $date, $time, $time
    ));
    
    if (!$available) {
        wp_send_json_error('Selected slot is not available');
        return;
    }
    
    // Check if slot is already booked
    $booked = $wpdb->get_var($wpdb->prepare(
        "SELECT COUNT(*) FROM $table_name WHERE appointment_date = %s AND appointment_time = %s",
        $date, $time
    ));
    
    if ($booked) {
        wp_send_json_error('This slot is already booked');
        return;
    }
    
    // Create Razorpay order
    $api_key = get_option('astro_booking_razorpay_key');
    $api_secret = get_option('astro_booking_razorpay_secret');
    $api = new Api($api_key, $api_secret);
    
    try {
        $order = $api->order->create([
            'amount' => $price * 100, // In paise
            'currency' => 'INR',
            'payment_capture' => 1
        ]);
        
        $wpdb->insert($table_name, [
            'client_name' => $client_name,
            'client_email' => $client_email,
            'appointment_date' => $date,
            'appointment_time' => $time,
            'price' => $price,
            'payment_id' => $order->id,
            'status' => 'pending'
        ]);
        
        wp_send_json_success(['order_id' => $order->id]);
    } catch (Exception $e) {
        wp_send_json_error('Payment initiation failed: ' . $e->getMessage());
    }
}

// Webhook handler for payment verification
add_action('rest_api_init', function () {
    register_rest_route('astrology-booking', '/webhook', [
        'methods' => 'POST',
        'callback' => 'astro_handle_webhook',
        'permission_callback' => '__return_true'
    ]);
});
function astro_handle_webhook($request) {
    global $wpdb;
    $table_name = $wpdb->prefix . 'astro_appointments';
    
    $payload = $request->get_body();
    $signature = $request->get_header('x-razorpay-signature');
    $webhook_secret = get_option('astro_booking_webhook_secret');
    
    $api = new Api(get_option('astro_booking_razorpay_key'), get_option('astro_booking_razorpay_secret'));
    
    try {
        $api->utility->verifyWebhookSignature($payload, $signature, $webhook_secret);
        $data = json_decode($payload, true);
        
        if ($data['event'] == 'payment.captured') {
            $order_id = $data['payload']['payment']['entity']['order_id'];
            $wpdb->update($table_name, 
                ['status' => 'confirmed'],
                ['payment_id' => $order_id]
            );
            
            // Send notifications
            $appointment = $wpdb->get_row($wpdb->prepare(
                "SELECT * FROM $table_name WHERE payment_id = %s",
                $order_id
            ));
            
            $admin_email = get_option('admin_email');
            $client_email = $appointment->client_email;
            
            wp_mail($client_email, 
                'Appointment Confirmation',
                "Dear {$appointment->client_name},\n\nYour appointment on {$appointment->appointment_date} at {$appointment->appointment_time} has been confirmed.\n\nThank you!",
                ['From: Astrology Booking <' . $admin_email . '>']
            );
            
            wp_mail($admin_email,
                'New Appointment Booked',
                "A new appointment has been booked:\n\nClient: {$appointment->client_name}\nEmail: {$appointment->client_email}\nDate: {$appointment->appointment_date}\nTime: {$appointment->appointment_time}\nPrice: ₹{$appointment->price}",
                ['From: Astrology Booking <' . $admin_email . '>']
            );
        }
    } catch (Exception $e) {
        http_response_code(400);
        exit;
    }
    
    http_response_code(200);
}

// Admin settings page
function astro_booking_settings_page() {
    if (isset($_POST['astro_booking_save_settings'])) {
        update_option('astro_booking_razorpay_key', sanitize_text_field($_POST['razorpay_key']));
        update_option('astro_booking_razorpay_secret', sanitize_text_field($_POST['razorpay_secret']));
        update_option('astro_booking_webhook_secret', sanitize_text_field($_POST['webhook_secret']));
        update_option('astro_booking_default_price', floatval($_POST['default_price']));
        echo '<div class="updated"><p>Settings saved!</p></div>';
    }
    ?>
    <div class="wrap">
        <h1>Astrology Booking Settings</h1>
        <form method="post">
            <table class="form-table">
                <tr>
                    <th>Razorpay Key ID</th>
                    <td><input type="text" name="razorpay_key" value="<?php echo esc_attr(get_option('astro_booking_razorpay_key')); ?>" required></td>
                </tr>
                <tr>
                    <th>Razorpay Key Secret</th>
                    <td><input type="text" name="razorpay_secret" value="<?php echo esc_attr(get_option('astro_booking_razorpay_secret')); ?>" required></td>
                </tr>
                <tr>
                    <th>Webhook Secret</th>
                    <td><input type="text" name="webhook_secret" value="<?php echo esc_attr(get_option('astro_booking_webhook_secret')); ?>" required></td>
                </tr>
                <tr>
                    <th>Default Price (₹)</th>
                    <td><input type="number" step="0.01" name="default_price" value="<?php echo esc_attr(get_option('astro_booking_default_price', 1000.00)); ?>" required></td>
                </tr>
            </table>
            <?php submit_button('Save Settings', 'primary', 'astro_booking_save_settings'); ?>
        </form>
    </div>
    <?php
}

// Admin availability page
function astro_booking_availability_page() {
    global $wpdb;
    $table_name = $wpdb->prefix . 'astro_availability';
    
    if (isset($_POST['astro_booking_save_availability'])) {
        $date = sanitize_text_field($_POST['avail_date']);
        $start_time = sanitize_text_field($_POST['start_time']);
        $end_time = sanitize_text_field($_POST['end_time']);
        $price = floatval($_POST['price']);
        
        $wpdb->insert($table_name, [
            'avail_date' => $date,
            'start_time' => $start_time,
            'end_time' => $end_time,
            'price' => $price
        ]);
        
        echo '<div class="updated"><p>Availability added!</p></div>';
    }
    
    if (isset($_GET['delete_id'])) {
        $wpdb->delete($table_name, ['id' => intval($_GET['delete_id'])]);
        echo '<div class="updated"><p>Availability deleted!</p></div>';
    }
    
    $availabilities = $wpdb->get_results("SELECT * FROM $table_name");
    include ASTRO_BOOKING_PATH . 'templates/admin-availability.php';
}

// Admin bookings page
function astro_booking_admin_page() {
    global $wpdb;
    $table_name = $wpdb->prefix . 'astro_appointments';
    $bookings = $wpdb->get_results("SELECT * FROM $table_name ORDER BY created_at DESC");
    ?>
    <div class="wrap">
        <h1>Astrology Bookings</h1>
        <table class="wp-list-table widefat fixed striped">
            <thead>
                <tr>
                    <th>Client Name</th>
                    <th>Email</th>
                    <th>Date</th>
                    <th>Time</th>
                    <th>Price (₹)</th>
                    <th>Status</th>
                    <th>Created At</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($bookings as $booking) : ?>
                    <tr>
                        <td><?php echo esc_html($booking->client_name); ?></td>
                        <td><?php echo esc_html($booking->client_email); ?></td>
                        <td><?php echo esc_html($booking->appointment_date); ?></td>
                        <td><?php echo esc_html($booking->appointment_time); ?></td>
                        <td><?php echo esc_html($booking->price); ?></td>
                        <td><?php echo esc_html($booking->status); ?></td>
                        <td><?php echo esc_html($booking->created_at); ?></td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <?php
}
?>