// ============================================================================== // 111 RENTALS - MOBILE APP REST API BRIDGE // ============================================================================== // This is the password your Android app will use to talk to HostGator define('R111_APP_SECRET', 'CHANGE_THIS_TO_A_LONG_RANDOM_PASSWORD_LATER'); add_action('rest_api_init', function () { // Endpoint 1: Get Fleet Settings register_rest_route('111rentals/v1', '/fleet', array( 'methods' => 'GET', 'callback' => 'r111_api_get_fleet', 'permission_callback' => 'r111_api_check_auth' )); // Endpoint 2: Get Upcoming Bookings register_rest_route('111rentals/v1', '/bookings', array( 'methods' => 'GET', 'callback' => 'r111_api_get_bookings', 'permission_callback' => 'r111_api_check_auth' )); // Endpoint 3: Get Revenue and Tax Totals register_rest_route('111rentals/v1', '/revenue', array( 'methods' => 'GET', 'callback' => 'r111_api_get_revenue', 'permission_callback' => 'r111_api_check_auth' )); }); // Security Check: Makes sure the phone app sends the right secret password function r111_api_check_auth($request) { $key = $request->get_header('x-111-api-key'); if ($key !== R111_APP_SECRET) { return new WP_Error('rest_forbidden', 'Unauthorized app access. Fuck off.', array('status' => 401)); } return true; } // Logic to grab Fleet data function r111_api_get_fleet() { global $wpdb; $table_settings = 'wpau_111_service_settings'; $fleet = $wpdb->get_results("SELECT id, service_label, service_slug, price_per_hr, is_active, inventory_limit, image_url, description FROM $table_settings"); return rest_ensure_response($fleet); } // Logic to grab Bookings data function r111_api_get_bookings() { global $wpdb; $table_bookings = 'wpau_111_rentals_master'; $today = date('Y-m-d'); // Grabs bookings from today onwards $bookings = $wpdb->get_results(" SELECT id, customer_name, customer_phone, equipment_type, start_time, duration, total_price, tax_amount, confirmation_code, is_manual FROM $table_bookings WHERE DATE(start_time) >= '$today' AND total_price > 0 ORDER BY start_time ASC LIMIT 150 "); return rest_ensure_response($bookings); } // Logic to grab Revenue data (using your exact math from rental-analytics.php) function r111_api_get_revenue() { global $wpdb; $table_bookings = 'wpau_111_rentals_master'; $bookings = $wpdb->get_results("SELECT confirmation_code, is_manual, total_price, tax_amount, processing_fee FROM $table_bookings WHERE total_price > 0"); $total_revenue = 0; $total_tax = 0; $total_fee = 0; foreach($bookings as $tb) { $gross = floatval($tb->total_price); $is_online = (strpos($tb->confirmation_code, '111RENT-') === 0) || !(isset($tb->is_manual) && $tb->is_manual); if (!$is_online) { $fee = isset($tb->processing_fee) ? floatval($tb->processing_fee) : 0; $t_amt = (isset($tb->tax_amount) && is_numeric($tb->tax_amount)) ? floatval($tb->tax_amount) : 0; } else { $fee = (isset($tb->processing_fee) && $tb->processing_fee > 0) ? floatval($tb->processing_fee) : round(($gross * 0.0299) + 0.30, 2); $t_amt = (isset($tb->tax_amount) && is_numeric($tb->tax_amount) && floatval($tb->tax_amount) > 0) ? floatval($tb->tax_amount) : round($gross - ($gross / 1.13), 2); } $total_tax += $t_amt; $total_fee += $fee; $total_revenue += $gross; } $net = $total_revenue - $total_tax - $total_fee; return rest_ensure_response(array( 'gross' => round($total_revenue, 2), 'taxes' => round($total_tax, 2), 'fees' => round($total_fee, 2), 'net' => round($net, 2) )); } https://jetskigta.com/post-sitemap.xml 2026-04-26T08:02:44+00:00 https://jetskigta.com/page-sitemap.xml 2026-06-06T14:35:28+00:00 https://jetskigta.com/category-sitemap.xml 2026-04-26T08:02:44+00:00