prefix; // if (session_status() === PHP_SESSION_NONE) { // session_start(); // } // if ( // empty($_SESSION[$table_prefix . 'userid']) // ) { // wp_send_json([ // 'isSuccess' => false, // 'returnMessage' => 'Unauthorized', // 'returnCode' => 'UNAUTHORIZED' // ]); // wp_die(); // } // return $_SESSION[$table_prefix . 'userid']; // } //new one // function six_storage_validate_session_user() // { // global $wpdb; // $table_prefix = $wpdb->prefix; // if (session_status() === PHP_SESSION_NONE) { // session_start(); // } // error_log('=== SESSION DEBUG ==='); // error_log(print_r($_SESSION, true)); // if ( // !isset($_SESSION[$table_prefix . 'six_storage_sessionObject']['result']['userId']) // ) { // error_log('SESSION USERID NOT FOUND'); // wp_send_json([ // 'isSuccess' => false, // 'returnMessage' => 'Unauthorized' // ]); // wp_die(); // } // $userId = $_SESSION[$table_prefix . 'six_storage_sessionObject']['result']['userId']; // error_log('SESSION USERID FOUND: ' . $userId); // return $userId; // } function six_storage_validate_session_user() { error_log( 'VALIDATION => is_user_logged_in = ' . (is_user_logged_in() ? 'YES' : 'NO') ); error_log( 'VALIDATION => current_user_id = ' . get_current_user_id() ); if ( !is_user_logged_in() || !current_user_can('read') ) { error_log('VALIDATION FAILED'); wp_send_json([ 'isSuccess' => false, 'returnMessage' => 'Unauthorized' ]); wp_die(); } $wp_user_id = get_current_user_id(); $userId = get_user_meta( $wp_user_id, 'six_storage_user_id', true ); error_log( 'META USER ID => ' . print_r($userId, true) ); if (empty($userId)) { error_log( 'USER META NOT FOUND' ); wp_send_json([ 'isSuccess' => false, 'returnMessage' => 'User mapping not found' ]); wp_die(); } return $userId; } function six_storage_nav_replace_login_to_dashboard($item_output, $item) { if ($item->title == 'Login' || strpos($item->url, 'sign-in') != false) { if (is_page('Dashboard')) { $plugin_output_html = ' account_circle keyboard_arrow_down '; return $plugin_output_html; } } return $item_output; } public function six_storage_getConfiguration() { error_log('=============================='); error_log('GET CLIENT AUTH DETAILS'); error_log('WP USER ID => ' . get_current_user_id()); error_log('LOGGED IN => ' . (is_user_logged_in() ? 'YES' : 'NO')); error_log('COOKIE => ' . print_r($_COOKIE, true)); error_log('=============================='); $isAjax = true; global $wpdb; $table_prefix = $wpdb->prefix; $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); $url = $this->six_storage_api_url . 'common/config'; $response = wp_remote_post(esc_url_raw($url), array( 'method' => 'GET', 'timeout' => 45, 'headers' => $this->six_storage_http_header )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { // $_SESSION[$table_prefix ."clientConfig"] = json_decode($response['body'], true); $responseDataForCache = json_decode($response['body'], true); set_transient( 'six_storage_client_config', $responseDataForCache, HOUR_IN_SECONDS ); $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { $six_storage_online_fc_group_the_unit_based_on_size_toggle = $Obj->six_storage_online_fc_group_the_unit_based_on_size_toggle; if (array_key_exists('result', $response)) { $responseData = $response['result']; // $this->six_storage_groupUnitsSizes = $response['result']['groupUnitSizes']; $this->six_storage_groupUnitsSizes = get_option('six_storage_online_fc_group_the_unit_based_on_size_toggle'); $this->six_storage_inclusiveofTax = $responseData["inclusiveofTax"]; $this->six_storage_autoPaymentsEnabled = $responseData["autoPaymentsEnabled"]; $this->six_storage_leadSource = $responseData["leadSources"]; $this->six_storage_invoice_period = $responseData["invoicePeriods"]; $this->six_storage_invoice_reccuring = $responseData["recurringTypes"]; $this->six_storage_identityDocuments = $responseData["identityFields"]; } else { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Storage type retrival failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); } if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Storage type retrival failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; // $_SESSION[$table_prefix ."clientConfig"] = json_decode($response['body'], true); set_transient( 'six_storage_client_config', $response, HOUR_IN_SECONDS ); wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { // $_SESSION[$table_prefix ."clientConfig"] = json_decode($response['body'], true); set_transient( 'six_storage_client_config', $response, HOUR_IN_SECONDS ); wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_getBuyedInsurance(){ $sessionUserId = $this->six_storage_validate_session_user(); $userId = $sessionUserId; // $userId = sanitize_text_field($_POST['userId']); $isAjax = true; $url = $this->six_storage_api_url2 . 'Insurance/GetTenantInsuranceDetails'; $response = wp_remote_request(esc_url_raw($url), array( 'method' => 'POST', 'timeout' => 45, 'headers' => $this->six_storage_http_header, 'body' => json_encode([ 'tenantId' => $userId, ]) )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Storage type retrival failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_get_total_leasebalance(){ $sessionUserId = $this->six_storage_validate_session_user(); $userId = $sessionUserId; // global $wpdb; // $table_prefix = $wpdb->prefix; // session_start(); // $six_storage_sessionObject = $_SESSION[$table_prefix ."six_storage_sessionObject"]; // $userId = $six_storage_sessionObject['result']["userId"]; $isAjax = true; $url = $this->six_storage_api_url2 . 'lease/leasebalance/' . $userId; $response = wp_remote_request(esc_url_raw($url), array( 'method' => 'GET', 'timeout' => 45, 'headers' => $this->six_storage_http_header )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Storage type retrival failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_changeplanbuyinginsurance(){ $sessionUserId = $this->six_storage_validate_session_user(); $insurancePremiumId = sanitize_text_field($_POST['insurancePremiumId']); $contractId = sanitize_text_field($_POST['contractId']); $unitId = sanitize_text_field($_POST['unitId']); // $userId = sanitize_text_field($_POST['tenantId']); $userId = $sessionUserId; $isAjax = true; $url = $this->six_storage_api_url2 . 'Insurance/ChangePlanBuyingInsurance'; $response = wp_remote_request(esc_url_raw($url), array( 'method' => 'POST', 'timeout' => 45, 'headers' => $this->six_storage_http_header, 'body' => json_encode([ 'insurancePremiumId' =>$insurancePremiumId, 'contractId' => $contractId, 'unitId' => $unitId, 'tenantId' =>$userId, ]) )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Storage type retrival failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_updateBuyInsurance(){ $invoiceIds = sanitize_text_field($_POST['insuranceDetails']); // $invoiceIds = urldecode($invoiceIds); $invoiceIds = str_replace('\"', '"', $invoiceIds); $isAjax = true; $url = $this->six_storage_api_url2 . 'Insurance/UpdateBuyingInsuranceDetails'; $response = wp_remote_request(esc_url_raw($url), array( 'method' => 'POST', 'timeout' => 45, 'headers' => $this->six_storage_http_header, 'body' => $invoiceIds )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Storage type retrival failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } // public function six_storage_getTenatAuthDetail(){ // global $wpdb; // $table_prefix = $wpdb->prefix; // session_start(); // $isAjax == true; // $response = $_SESSION[$table_prefix ."six_storage_sessionObject"]; // wp_send_json(json_encode($response)); // wp_die(); // } public function six_storage_getTenatAuthDetail() { error_log('=============================='); error_log('GET CLIENT AUTH DETAILS'); error_log('WP USER ID => ' . get_current_user_id()); error_log('LOGGED IN => ' . (is_user_logged_in() ? 'YES' : 'NO')); error_log('COOKIE => ' . print_r($_COOKIE, true)); error_log('=============================='); if (!is_user_logged_in()) { wp_send_json([ 'isSuccess' => false, 'returnMessage' => 'Unauthorized' ]); wp_die(); } $wpUserId = get_current_user_id(); $response = [ 'wpUserId' => $wpUserId, 'userId' => get_user_meta( $wpUserId, 'six_storage_user_id', true ) ]; wp_send_json($response); wp_die(); } public function six_storage_getCultureInfo() { $response = get_option("six_storage_online_api_culture"); wp_send_json($response); } // public function six_storage_savePaymentInformation() // { // //added code // $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); // $this->six_storage_http_header['Content-Type'] = 'application/json'; // // $invoiceIds = sanitize_text_field($_POST['invoiceIds']); // // $invoiceIds = str_replace('\\', '', $invoiceIds); // $invoiceIds = wp_unslash($_POST['invoiceIds']); // $invoiceIds = str_replace('\\', '', $invoiceIds); // $userId = sanitize_text_field($_POST['userId']); // $paidAmount = sanitize_text_field($_POST['paidAmount']); // $paymentRefNumber = sanitize_text_field($_POST['paymentRefNumber']); // $userLocationInformation = sanitize_text_field($_POST['log']); // $paymentTransactionResponse = sanitize_text_field($_POST['paymentTransactionResponse']); // $paymentType = sanitize_text_field($_POST['paymentType']); // if($paymentType == 'null' || $paymentType == ''){ // $paymentType = 'CreditCard'; // } // // ===== REQUIRED JSON HANDLING (MINIMAL FIX) ===== // $leaseInvoices = json_decode($invoiceIds, true); // if (json_last_error() !== JSON_ERROR_NONE) { // wp_send_json([ // 'isSuccess' => false, // 'returnMessage' => 'Invalid invoice data' // ]); // wp_die(); // } // // ===== ADDED VALIDATION (ONLY FIX) ===== // if (empty($leaseInvoices) || empty($leaseInvoices[0]['invoiceId'])) { // wp_send_json([ // 'isSuccess' => false, // 'returnMessage' => 'InvoiceId missing in payment request' // ]); // wp_die(); // } // if ($userLocationInformation != "" || $userLocationInformation != null || !empty( $userLocationInformation)){ // $userLocationInformation = str_replace('\\', '', $userLocationInformation); // $getdyip=$this->six_storage_getIpAddress(); /* Code to get dynamic IP */ // $userLocationInformation = json_decode($userLocationInformation); // $userLocationInformation->ipAddress = $getdyip; // $userLocationInformation = json_encode($userLocationInformation); // } // $paymentTransactionResponse = str_replace('\\', '', $paymentTransactionResponse); // $isAjax = true; // $url = $this->six_storage_api_url . 'unit/payment/' . $userId; // $response = wp_remote_request(esc_url_raw($url), array( // 'method' => 'POST', // 'timeout' => 45, // 'headers' => $this->six_storage_http_header, // 'body' => json_encode([ // 'leaseInvoices' => json_decode($invoiceIds), // 'totalPayment' => $paidAmount, // 'paymentRefNumber' => $paymentRefNumber, // 'paymentType' => $paymentType, // 'logger' => json_decode($userLocationInformation), // 'paymentTransactionResponse' => json_decode($paymentTransactionResponse) // ]) // )); // if (is_wp_error($response)) { // $message = 'Something went wrong. Please contact support team.'; // $message = esc_html__($message,'6storage-rentals'); // $error = [ // 'isSuccess' => false, // 'returnMessage' =>$message , // 'returnCode' => '' // ]; // if (isset($isAjax) && $isAjax == true) { // wp_send_json(json_encode($error)); // wp_die(); // } // } else { // $response = json_decode($response['body'], true); // if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { // if (isset($isAjax) && $isAjax == true) { // $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Storage type retrival failed. Please contact support team.'; // $message = esc_html__($message,'6storage-rentals'); // $response['returnMessage'] = $message; // wp_send_json(json_encode($response)); // wp_die(); // } // } else { // $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; // $message = esc_html__($message,'6storage-rentals'); // $error = [ // 'isSuccess' => false, // 'returnMessage' => $message, // 'returnCode' => "" // ]; // if (isset($isAjax) && $isAjax == true) { // wp_send_json(json_encode($error)); // wp_die(); // } // } // } // } public function six_storage_savePaymentInformation() { $sessionUserId = $this->six_storage_validate_session_user(); //added code $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); $this->six_storage_http_header['Content-Type'] = 'application/json'; // $invoiceIds = sanitize_text_field($_POST['invoiceIds']); // $invoiceIds = str_replace('\\', '', $invoiceIds); $invoiceIds = wp_unslash($_POST['invoiceIds']); $invoiceIds = str_replace('\\', '', $invoiceIds); // $userId = sanitize_text_field($_POST['userId']); $userId = $sessionUserId; $paidAmount = sanitize_text_field($_POST['paidAmount']); $paymentRefNumber = sanitize_text_field($_POST['paymentRefNumber']); $userLocationInformation = sanitize_text_field($_POST['log']); $paymentTransactionResponse = sanitize_text_field($_POST['paymentTransactionResponse']); $paymentType = sanitize_text_field($_POST['paymentType']); if($paymentType == 'null' || $paymentType == ''){ $paymentType = 'CreditCard'; } // ===== DEBUG LOGGING (IMPORTANT) ===== error_log("===== PAYMENT API HIT ====="); error_log("RAW invoiceIds: " . $invoiceIds); // ===== REQUIRED JSON HANDLING (MINIMAL FIX) ===== $leaseInvoices = json_decode($invoiceIds, true); // if (json_last_error() !== JSON_ERROR_NONE) { // error_log("Invalid JSON invoiceIds"); // // 🔥 FALLBACK: try to recover from session (if you implement frontend fix) // if (isset($_SESSION['invoiceIds'])) { // $leaseInvoices = json_decode($_SESSION['invoiceIds'], true); // error_log("Recovered invoiceIds from session"); // } // } if (json_last_error() !== JSON_ERROR_NONE) { error_log("Invalid JSON invoiceIds"); wp_send_json([ 'isSuccess' => false, 'returnMessage' => 'Invalid invoice data' ]); wp_die(); } // ===== ADDED VALIDATION (ONLY FIX) ===== if (empty($leaseInvoices) || empty($leaseInvoices[0]['InvoiceId'])) { error_log("InvoiceId missing - Attempting fallback"); // ❗ DO NOT FAIL — just log // You can optionally stop here if business requires strict validation // but better to log and continue // Optional: return graceful response instead of breaking wp_send_json([ 'isSuccess' => false, 'returnMessage' => 'InvoiceId missing (logged for investigation)' ]); wp_die(); } if ($userLocationInformation != "" || $userLocationInformation != null || !empty( $userLocationInformation)){ $userLocationInformation = str_replace('\\', '', $userLocationInformation); $getdyip=$this->six_storage_getIpAddress(); /* Code to get dynamic IP */ $userLocationInformation = json_decode($userLocationInformation); $userLocationInformation->ipAddress = $getdyip; $userLocationInformation = json_encode($userLocationInformation); } $paymentTransactionResponse = str_replace('\\', '', $paymentTransactionResponse); $isAjax = true; $url = $this->six_storage_api_url . 'unit/payment/' . $userId; $response = wp_remote_request(esc_url_raw($url), array( 'method' => 'POST', 'timeout' => 45, 'headers' => $this->six_storage_http_header, 'body' => json_encode([ 'leaseInvoices' => json_decode($invoiceIds), 'totalPayment' => $paidAmount, 'paymentRefNumber' => $paymentRefNumber, 'paymentType' => $paymentType, 'logger' => json_decode($userLocationInformation), 'paymentTransactionResponse' => json_decode($paymentTransactionResponse) ]) )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Storage type retrival failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_getInsuranceUnitTenantDetails(){ $sessionUserId = $this->six_storage_validate_session_user(); $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); $planId = sanitize_text_field($_POST['planId']); $unitId = sanitize_text_field($_POST['unitId']); // $userId = sanitize_text_field($_POST['tenantId']); $userId = $sessionUserId; $contractId = sanitize_text_field($_POST['contractId']); $isAjax = true; $url = $this->six_storage_api_url2 . 'Insurance/GetInsuranceUnitTenantDetails'; $response = wp_remote_request(esc_url_raw($url), array( 'method' => 'POST', 'timeout' => 45, 'headers' => $this->six_storage_http_header, 'body' => json_encode([ "planId"=> $planId, "unitId"=> $unitId, "tenantId"=> $userId, "contractId"=> $contractId, ]) )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Storage type retrival failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_buyInsurance(){ $sessionUserId = $this->six_storage_validate_session_user(); $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); // $userId = sanitize_text_field($_POST['userId']); $userId = $sessionUserId; $six_storage_locationId = sanitize_text_field($_POST['locationId']); $isAjax = true; $url = $this->six_storage_api_url2 . 'Insurance/GetInsurancePlans'; $response = wp_remote_request(esc_url_raw($url), array( 'method' => 'POST', 'timeout' => 45, 'headers' => $this->six_storage_http_header, 'body' => json_encode([ "companyId" => null, "locationId"=>$six_storage_locationId, "storageTypeId"=> null ]) )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Storage type retrival failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_getTenantInvoices() { $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); $sessionUserId = $this->six_storage_validate_session_user(); $userId = $sessionUserId; // $userId = sanitize_text_field($_POST['userId']); // $pageNumber = sanitize_text_field($_POST['pageNumber']); // $PageSize = sanitize_text_field($_POST['pageSize']); $isAjax = true; // $url = $this->six_storage_api_url . 'unit/invoice/' . $userId.'?PageNumber='.$pageNumber.'&PageSize='.$PageSize ; $url = $this->six_storage_api_url . 'unit/invoice/' . $userId; $response = wp_remote_request(esc_url_raw($url), array( 'method' => 'GET', 'timeout' => 45, 'headers' => $this->six_storage_http_header )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Storage type retrival failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_sendStatement() { $sessionUserId = $this->six_storage_validate_session_user(); $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); // $userId = sanitize_text_field($_POST['userId']); $userId = $sessionUserId; $userLocationInformation = sanitize_text_field($_POST['log']); if ($userLocationInformation != "" || $userLocationInformation != null || !empty( $userLocationInformation)){ $userLocationInformation = str_replace('\\', '', $userLocationInformation); $getdyip=$this->six_storage_getIpAddress(); /* Code to get dynamic IP */ $userLocationInformation = json_decode($userLocationInformation); $userLocationInformation->ipAddress = $getdyip; $userLocationInformation = json_encode($userLocationInformation); } $isAjax = true; $url = $this->six_storage_api_url . 'user/statement/' . $userId; $response = wp_remote_request(esc_url_raw($url), array( 'method' => 'POST', 'timeout' => 45, 'headers' => $this->six_storage_http_header, 'body' => json_encode([ 'logger' => json_decode($userLocationInformation) ]) )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Storage type retrival failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_getUserInfo() { $sessionUserId = $this->six_storage_validate_session_user(); // global $wpdb; // $table_prefix = $wpdb->prefix; $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); // $userId = sanitize_text_field($_POST['userId']); $userId = $sessionUserId; $isAjax = true; $url = $this->six_storage_api_url . 'user/' . $userId; $response = wp_remote_post(esc_url_raw($url), array( 'method' => 'GET', 'timeout' => 45, 'headers' => $this->six_storage_http_header )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' && $response['returnMessage'] == "SUCCESS") { // $_SESSION[$table_prefix . 'userid'] = $response['result']['userId']; update_user_meta( get_current_user_id(), 'six_storage_user_id', $response['result']['userId'] ); } if (array_key_exists('result', $response)) { $this->signIn = $response['result']; } else { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Storage type retrival failed. Please contact support team.'; } if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Storage type retrival failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_getTenantTransactions() { $sessionUserId = $this->six_storage_validate_session_user(); $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); // $userId = sanitize_text_field($_POST['userId']); $userId = $sessionUserId; // $pageNumber = sanitize_text_field($_POST['pageNumber']); // $PageSize = sanitize_text_field($_POST['pageSize']); $isAjax = true; //$url = $this->six_storage_api_url . 'user/transaction/' . $userId.'?PageNumber='.$pageNumber.'&PageSize='.$PageSize; $url = $this->six_storage_api_url . 'user/transaction/' . $userId; $response = wp_remote_request(esc_url_raw($url), array( 'method' => 'GET', 'timeout' => 45, 'headers' => $this->six_storage_http_header )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if(is_array($response['result']) == false){ $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } }else{ for($i=0; $i < count($response['result']); $i++){ $transactionDescription = $response['result'][$i]['description']; $rest = explode("^",$transactionDescription); $translated_arr = array(); foreach($rest as $val){ $translated_arr[] = __(trim($val),'6storage-online'); } $translatedText = join(" ",$translated_arr); $response['result'][$i]['description'] = $translatedText; //Category Translation $transactionCategory = $response['result'][$i]['category']; $restCateg = explode("^",$transactionCategory); $translated_array = array(); foreach($restCateg as $value){ $translated_array[] = __(trim($value),'6storage-online'); } $translatedCatText = join(" ",$translated_array); $response['result'][$i]['category'] = $translatedCatText; } } if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Storage type retrival failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_applyRecallPromocode() { $sessionUserId = $this->six_storage_validate_session_user(); $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); $couponCode = sanitize_text_field($_POST['couponCode']); // $userId = sanitize_text_field($_POST['userId']); $userId = $sessionUserId; $leaseId = sanitize_text_field($_POST['leaseId']); $transportationId = sanitize_text_field($_POST['transportationId']); if ($leaseId == 'null' || $leaseId == '') { $leaseId = 0; } $isAjax = true; $url = $this->six_storage_api_url . 'recall/promoCode/' . $leaseId . '/' . $transportationId . '/' . $couponCode; $response = wp_remote_request(esc_url_raw($url), array( 'method' => 'GET', 'timeout' => 45, 'headers' => $this->six_storage_http_header )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Storage type retrival failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_getPaymentForm($isAjax) { $sessionUserId = $this->six_storage_validate_session_user(); $userId = $sessionUserId; $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); // $tenantId = sanitize_text_field($_POST['tenantId']); $invoiceIds = sanitize_text_field($_POST['invoiceIds']); $invoiceIds = str_replace('\\', '', $invoiceIds); $chargeableAmount = sanitize_text_field($_POST['chargeableAmount']); $hostURL = sanitize_text_field($_POST['hostURL']); $PaymentModeId = sanitize_text_field( $_POST['paymentModeId']); $paymentgateway = sanitize_text_field($_POST['paymentgateway']); if($paymentgateway === "PAYA"){ // $url = $this->six_storage_api_url2 . 'user/paymentform/' . $tenantId; $url = $this->six_storage_api_url2 . 'user/paymentform/' . $userId; }else{ // $url = $this->six_storage_api_url . 'user/paymentform/' . $tenantId; $url = $this->six_storage_api_url . 'user/paymentform/' . $userId; } $PayloadObject = sanitize_text_field($_POST['PayloadObject']); $PayloadObject = str_replace('\\', '', $PayloadObject); $sixStoragelanguageCode = ''; if ($sixStorageln == '') { $sixStoragelanguageCode = get_locale(); } $sixStoragelanguageCode = str_replace("_","-",$sixStoragelanguageCode); //$p24responsePage = get_option('six_storage_ptwofour_response_page_id'); if (function_exists('pll_get_post')) { $p24responsePage = get_permalink(pll_get_post(get_option('six_storage_ptwofour_response_page_id'))); } else{ $p24responsePage = get_permalink(get_option('six_storage_ptwofour_response_page_id')); } $bodyRequest = ''; if($PaymentModeId !== '' && $PaymentModeId !== null){ $bodyRequest = json_encode([ 'chargeableAmount' => $chargeableAmount, 'leaseInvoices' => json_decode($invoiceIds), 'hostURL' => $hostURL, 'language' => $sixStoragelanguageCode, 'transactionCallback' => $p24responsePage, 'paymentModeId' => $PaymentModeId ]); } else { $bodyRequest = json_encode([ 'chargeableAmount' => $chargeableAmount, 'hostURL' => $hostURL, 'language' => $sixStoragelanguageCode, 'transactionCallback' => $p24responsePage, 'callPlace' => "PAYNOW", 'PayloadObject'=> $PayloadObject ]); } $isAjax = true; $response = wp_remote_get($url, array( 'method' => 'POST', 'timeout' => 45, 'headers' => $this->six_storage_http_header, 'body' => $bodyRequest )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (array_key_exists('result', $response)) { $this->payment = $response['result']; } else { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Payment Form retrival failed. Please contact support team.'; } if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Payment Form retrival failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_cancelRecallDetails() { $sessionUserId = $this->six_storage_validate_session_user(); $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); $leaseId = sanitize_text_field($_POST['leaseId']); // $userId = sanitize_text_field($_POST['userId']); $userId = $sessionUserId; if ($leaseId == 'null' || $leaseId == '') { $leaseId = 0; } $isAjax = true; $url = $this->six_storage_api_url . 'recall/cancel/' . $leaseId . '/' . $userId; $response = wp_remote_request(esc_url_raw($url), array( 'method' => 'POST', 'timeout' => 45, 'headers' => $this->six_storage_http_header )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Storage type retrival failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_cancelScheduledMoveoutDetails() { $sessionUserId = $this->six_storage_validate_session_user(); $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); $leaseId = sanitize_text_field($_POST['leaseId']); // $userId = sanitize_text_field($_POST['userId']); $userId = $sessionUserId; $userLocationInformation = sanitize_text_field($_POST['log']); $unitNumber = sanitize_text_field($_POST['unitNumber']); if ($userLocationInformation != "" || $userLocationInformation != null || !empty( $userLocationInformation)){ $userLocationInformation = str_replace('\\', '', $userLocationInformation); $getdyip=$this->six_storage_getIpAddress(); /* Code to get dynamic IP */ $userLocationInformation = json_decode($userLocationInformation); $userLocationInformation->ipAddress = $getdyip; $userLocationInformation = json_encode($userLocationInformation); } if ($leaseId == 'null' || $leaseId == '') { $leaseId = 0; } $isAjax = true; $url = $this->six_storage_api_url . 'moveOut/cancel/' . $leaseId . '/' . $userId; $response = wp_remote_request(esc_url_raw($url), array( 'method' => 'POST', 'timeout' => 45, 'headers' => $this->six_storage_http_header, 'body' => json_encode([ 'logger' => json_decode($userLocationInformation), 'unitNumber' => $unitNumber ]) )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Storage type retrival failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_saveScheduledMoveoutDetails() { $sessionUserId = $this->six_storage_validate_session_user(); $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); $leaseId = sanitize_text_field($_POST['leaseId']); // $userId = sanitize_text_field($_POST['userId']); $userId = $sessionUserId; $scheduleDate = sanitize_text_field($_POST['scheduleDate']); $reason = sanitize_text_field($_POST['reason']); $unitNumber = sanitize_text_field($_POST['unitNumber']); $userLocationInformation = sanitize_text_field($_POST['log']); if ($userLocationInformation != "" || $userLocationInformation != null || !empty( $userLocationInformation)){ $userLocationInformation = str_replace('\\', '', $userLocationInformation); $getdyip=$this->six_storage_getIpAddress(); /* Code to get dynamic IP */ $userLocationInformation = json_decode($userLocationInformation); $userLocationInformation->ipAddress = $getdyip; $userLocationInformation = json_encode($userLocationInformation); } if ($leaseId == 'null' || $leaseId == '') { $leaseId = 0; } if ($scheduleDate == 'null') { $scheduleDate = date('Y-m-d'); } else { $scheduleDate = date('Y-m-d', strtotime($scheduleDate)); } $isAjax = true; $url = $this->six_storage_api_url . 'moveOut/scheduleMoveOut/' . $leaseId; $response = wp_remote_request(esc_url_raw($url), array( 'method' => 'POST', 'timeout' => 45, 'headers' => $this->six_storage_http_header, 'body' => json_encode([ 'tenantId' => $userId, 'scheduleDate' => $scheduleDate, 'reason' => $reason, 'logger' => json_decode($userLocationInformation), 'unitNumber' => $unitNumber ]) )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Storage type retrival failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_saveRecallDetails() { $sessionUserId = $this->six_storage_validate_session_user(); $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); $leaseId = sanitize_text_field($_POST['leaseId']); // $userId = sanitize_text_field($_POST['userId']); $userId = $sessionUserId; $palletAccessInfoId = sanitize_text_field($_POST['palletAccessInfoId']); $recallDate = sanitize_text_field($_POST['recallDate']); $promoCodeId = sanitize_text_field($_POST['promoCodeId']); $price = sanitize_text_field($_POST['price']); $price = str_replace('\\', '', $price); $scheduleDate = sanitize_text_field($_POST['scheduleDate']); $isScheduledMoveout = sanitize_text_field($_POST['isScheduledMoveout']); if ($leaseId == 'null' || $leaseId == '') { $leaseId = 0; } if ($recallDate == 'null') { $recallDate = date('Y-m-d'); } else { $recallDate = date('Y-m-d', strtotime($recallDate)); } if ($promoCodeId == 'null') { $promoCodeId = null; } $isAjax = true; $url = $this->six_storage_api_url . 'recall/' . $leaseId; if ($scheduleDate !== 'undefined' && $scheduleDate != 'null' && $scheduleDate != "" && ($isScheduledMoveout === true || $isScheduledMoveout === 'true')) { $url = $this->six_storage_api_url . 'recall/scheduleMoveOut/' . $leaseId; $scheduleDate = date('Y-m-d', strtotime($scheduleDate)); } $response = wp_remote_request(esc_url_raw($url), array( 'method' => 'POST', 'timeout' => 45, 'headers' => $this->six_storage_http_header, 'body' => json_encode([ 'tenantId' => $userId, 'palletAccessInfoId' => $palletAccessInfoId, 'recallDate' => $recallDate, 'price' => json_decode($price), 'scheduleDate' => $scheduleDate, 'promoCodeText' => $promoCodeId ]) )); if (is_wp_error($response)) { update_option('six_storage_online_api_error', $url . ' : Request => ' . json_encode([ 'tenantId' => $userId, 'palletAccessInfoId' => $palletAccessInfoId, 'recallDate' => $recallDate, 'price' => json_decode($price), 'scheduleDate' => $scheduleDate, 'promoCodeText' => $promoCodeId ]) . 'Response => ' . json_encode($response), true); $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($isAjax) && $isAjax == true) { if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Storage type retrival failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } else { wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_getRecallDetails() { $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); $leaseId = sanitize_text_field($_POST['leaseId']); if ($leaseId == 'null' || $leaseId == '') { $leaseId = 0; } $isAjax = true; $url = $this->six_storage_api_url . 'recall/' . $leaseId; $response = wp_remote_request(esc_url_raw($url), array( 'method' => 'GET', 'timeout' => 45, 'headers' => $this->six_storage_http_header )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Storage type retrival failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_getRentedUnits() { $sessionUserId = $this->six_storage_validate_session_user(); $userId = $sessionUserId; // global $wpdb; // $table_prefix = $wpdb->prefix; // session_start(); $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); // $six_storage_sessionObject = $_SESSION[$table_prefix ."six_storage_sessionObject"]; // $userId = $six_storage_sessionObject['result']["userId"]; $pageNumber = sanitize_text_field($_POST['pageNumber']); $PageSize = sanitize_text_field($_POST['pageSize']); // if($userId == null || $userId == ''){ // $message = 'Something went wrong. Please contact support team.'; // $message = __($message,'6storage-rentals'); // $error = [ // 'isSuccess' => false, // 'returnMessage' =>$message , // 'returnCode' => 'invalid username' // ]; // wp_send_json(json_encode($error)); // wp_die(); // } $rentalsearch = sanitize_text_field($_POST['rentalsearch']); if ($rentalsearch == 'null' || $rentalsearch == '') { $rentalsearch = null; } $isAjax = true; $url = $this->six_storage_api_url . 'movein/lease/' . $userId; $response = wp_remote_request($url, array( 'method' => 'POST', 'timeout' => 45, 'headers' => $this->six_storage_http_header, 'body' => json_encode([ 'searchText' => $rentalsearch, 'pageNumber' => $pageNumber, 'pageSize' => $PageSize, ]) )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Storage type retrival failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_getRentedAgreement() { $sessionUserId = $this->six_storage_validate_session_user(); $userId = $sessionUserId; // global $wpdb; // $table_prefix = $wpdb->prefix; // session_start(); $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); // $six_storage_sessionObject = $_SESSION[$table_prefix ."six_storage_sessionObject"]; // $userId = $six_storage_sessionObject['result']["userId"]; $contractId = sanitize_text_field($_POST['contractId']); if ($contractId == 'null' || $contractId == '') { $contractId = null; } $isAjax = true; $url = $this->six_storage_api_url . 'movein/lease/documents/' . $userId; $response = wp_remote_request(esc_url_raw($url), array( 'method' => 'POST', 'timeout' => 45, 'headers' => $this->six_storage_http_header, 'body' => json_encode([ 'contractId' => $contractId ]) )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Storage type retrival failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } // public function six_storage_logOut() // { // $sessionUserId = $this->six_storage_validate_session_user(); // global $wpdb; // $table_prefix = $wpdb->prefix; // // session_start(); // if (session_status() === PHP_SESSION_NONE) { // session_start(); // } // // $userId = sanitize_text_field($_POST['userId']); // $userId = $sessionUserId; // $userLocationInformation = sanitize_text_field($_POST['log']); // if ($userLocationInformation != "" || $userLocationInformation != null || !empty( $userLocationInformation)){ // $userLocationInformation = str_replace('\\', '', $userLocationInformation); // $getdyip=$this->six_storage_getIpAddress(); /* Code to get dynamic IP */ // $userLocationInformation = json_decode($userLocationInformation); // $userLocationInformation->ipAddress = $getdyip; // $userLocationInformation = json_encode($userLocationInformation); // } // $isAjax = true; // $url = $this->six_storage_api_url . 'user/logout'; // $response = wp_remote_post(esc_url_raw($url), array( // 'method' => 'POST', // 'timeout' => 45, // 'headers' => $this->six_storage_http_header, // 'body' => json_encode([ // 'userId' => $userId, // 'logger' => json_decode($userLocationInformation) // ]) // )); // // unset($_SESSION[$table_prefix . 'six_storage_sessionObject']); // unset($_SESSION[$table_prefix . 'six_storage_sessionObject']); // unset($_SESSION[$table_prefix . 'userid']); // if (is_wp_error($response)) { // $response = [ // 'isSuccess' => false, // 'returnMessage' => 'Something went wrong. Please contact support team.', // 'returnCode' => "" // ]; // wp_send_json(json_encode($response)); // wp_die(); // } // else{ // // $_SESSION[$table_prefix . 'userid'] = ''; // $_SESSION = []; // session_unset(); // session_destroy(); // $response = [ // 'isSuccess' => true, // 'returnMessage' => "", // 'returnCode' => "" // ]; // wp_send_json(json_encode($response)); // wp_die(); // } // } public function six_storage_logOut() { // $sessionUserId = $this->six_storage_validate_session_user(); $sessionUserId = ''; $userId = sanitize_text_field( wp_unslash($_POST['userId'] ?? '') ); global $wpdb; $table_prefix = $wpdb->prefix; // if (session_status() === PHP_SESSION_NONE) { // session_start(); // } // $userId = $sessionUserId; // $userLocationInformation = isset($_POST['log']) // ? sanitize_text_field($_POST['log']) // : ''; $userLocationInformation = isset($_POST['log']) ? sanitize_text_field(wp_unslash($_POST['log'])) : ''; if (!empty($userLocationInformation)) { $userLocationInformation = str_replace('\\', '', $userLocationInformation); $getdyip = $this->six_storage_getIpAddress(); $userLocationInformation = json_decode($userLocationInformation); if (is_object($userLocationInformation)) { $userLocationInformation->ipAddress = $getdyip; } $userLocationInformation = json_encode($userLocationInformation); } $url = $this->six_storage_api_url . 'user/logout'; $response = wp_remote_post( esc_url_raw($url), array( 'method' => 'POST', 'timeout' => 45, 'headers' => $this->six_storage_http_header, 'body' => json_encode([ 'userId' => $userId, 'logger' => json_decode($userLocationInformation) ]) ) ); // Always clear PHP session locally if (session_status() === PHP_SESSION_NONE) { session_start(); } // Remove all session variables $_SESSION = []; // Clear session variables session_unset(); // Destroy the session if (session_id()) { session_destroy(); } // Remove the PHP session cookie if (ini_get('session.use_cookies')) { $params = session_get_cookie_params(); setcookie( session_name(), '', time() - 42000, $params['path'], $params['domain'], $params['secure'], $params['httponly'] ); } if (is_wp_error($response)) { wp_send_json(json_encode([ 'isSuccess' => false, 'returnMessage' => 'Something went wrong. Please contact support team.', 'returnCode' => '' ])); wp_die(); } error_log( 'LOGOUT HIT => USER=' . get_current_user_id() ); /* Logout WordPress user */ wp_logout(); error_log( 'AFTER LOGOUT => USER=' . get_current_user_id() ); wp_send_json(json_encode([ 'isSuccess' => true, 'returnMessage' => '', 'returnCode' => '' ])); wp_die(); } public function six_storage_updateProfile() { $sessionUserId = $this->six_storage_validate_session_user(); $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); // $userId = sanitize_text_field($_POST['userId']); $userId = $sessionUserId; $firstName = sanitize_text_field($_POST['firstName']); $lastName = sanitize_text_field($_POST['lastName']); $email = sanitize_email($_POST['email']); $phoneNumber = sanitize_text_field($_POST['phoneNumber']); $phoneNumbertwo = sanitize_text_field($_POST['phoneNumber2']); $addressLineOne = sanitize_text_field($_POST['addressLineOne']); $addressLineTwo = sanitize_text_field($_POST['addressLineTwo']); $city = sanitize_text_field($_POST['city']); $state = sanitize_text_field($_POST['state']); $zipCode = sanitize_text_field($_POST['zipCode']); $country = sanitize_text_field($_POST['country']); $ssn = sanitize_text_field($_POST['ssn']); $userLocationInformation = sanitize_text_field($_POST['log']); if ($userLocationInformation != "" || $userLocationInformation != null || !empty( $userLocationInformation)){ $userLocationInformation = str_replace('\\', '', $userLocationInformation); $getdyip=$this->six_storage_getIpAddress(); /* Code to get dynamic IP */ $userLocationInformation = json_decode($userLocationInformation); $userLocationInformation->ipAddress = $getdyip; $userLocationInformation = json_encode($userLocationInformation); } $isAjax = true; $url = $this->six_storage_api_url . 'user/UpdateProfile/' . $userId; $response = wp_remote_request(esc_url_raw($url), array( 'method' => 'POST', 'timeout' => 45, 'headers' => $this->six_storage_http_header, 'body' => json_encode([ 'firstName' => $firstName, 'lastName' => $lastName, 'email' => $email, 'phoneNumber' => $phoneNumber, 'phoneNumber2' => $phoneNumbertwo, 'addressLine1' => $addressLineOne, 'addressLine2' => $addressLineTwo, 'city' => $city, 'state' => $state, 'postalCode' => $zipCode, 'country' => $country, 'ssn' =>$ssn, 'logger' => json_decode($userLocationInformation) ]) )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (array_key_exists('result', $response)) { $this->six_storage_update_profile = $response['result']; } else { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Storage type retrival failed. Please contact support team.'; } if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Storage type retrival failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_updatePassword() { $sessionUserId = $this->six_storage_validate_session_user(); $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); $currentPassword = sanitize_text_field($_POST['currentPassword']); $newPassword = sanitize_text_field($_POST['newPassword']); $confirmNewPassword = sanitize_text_field($_POST['confirmNewPassword']); $token = sanitize_text_field($_POST['token']); // $userId = sanitize_text_field($_POST['userId']); $userId = $sessionUserId; $userLocationInformation = sanitize_text_field($_POST['log']); if ($userLocationInformation != "" || $userLocationInformation != null || !empty( $userLocationInformation)){ $userLocationInformation = str_replace('\\', '', $userLocationInformation); $getdyip=$this->six_storage_getIpAddress(); /* Code to get dynamic IP */ $userLocationInformation = json_decode($userLocationInformation); $userLocationInformation->ipAddress = $getdyip; $userLocationInformation = json_encode($userLocationInformation); } $isAjax = true; $url = $this->six_storage_api_url . 'user/password/' . $userId . '/update'; $response = wp_remote_request(esc_url_raw($url), array( 'method' => 'POST', 'timeout' => 45, 'headers' => $this->six_storage_http_header, 'body' => json_encode([ 'currentPassword' => $currentPassword, 'newPassword' => $newPassword, 'conformNewPassword' => $confirmNewPassword, 'token' => $token, 'logger' => json_decode($userLocationInformation) ]) )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); $beforetransReturnMsg = $response['returnMessage']; if($beforetransReturnMsg === "New Password must contain atleast a special character, lowercase, uppercase and a number and length must be 8 to 12 characters."){ $beforetransReturnMsg = "New Password must contain atleast a lowercase, uppercase and a number and length must be 8 to 12 characters."; } $aftertransReturnMsg = esc_html__(trim($beforetransReturnMsg),'6storage-rentals'); $response['returnMessage'] = $aftertransReturnMsg; if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Storage type retrival failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_getMoveinFieldsSettings() { $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); $isAjax = true; $url = $this->six_storage_api_url . 'moveIn/fields'; $response = wp_remote_post(esc_url_raw($url), array( 'method' => 'POST', 'timeout' => 45, 'headers' => $this->six_storage_http_header, 'body' => json_encode([ 'visibility' => 1 ]) )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Vehicle information save failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_loadAddCreditCardForm() { $sessionUserId = $this->six_storage_validate_session_user(); $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); // $userId = sanitize_text_field($_POST['userId']); $userId = $sessionUserId; $platform = "WEB"; $hostURL = sanitize_text_field($_POST['hostURL']); $userLocationInformation = sanitize_text_field($_POST['log']); $paymentModeId = sanitize_text_field($_POST['paymentModeId']); if ($userLocationInformation != "" || $userLocationInformation != null || !empty( $userLocationInformation)){ $userLocationInformation = str_replace('\\', '', $userLocationInformation); $getdyip=$this->six_storage_getIpAddress(); /* Code to get dynamic IP */ $userLocationInformation = json_decode($userLocationInformation); $userLocationInformation->ipAddress = $getdyip; $userLocationInformation = json_encode($userLocationInformation); } $isAjax = true; $sixStoragelanguageCode = ''; if ($sixStorageln == '') { $sixStoragelanguageCode = get_locale(); } $sixStoragelanguageCode = str_replace("_","-",$sixStoragelanguageCode); //$p24responsePage = get_option('six_storage_ptwofour_response_page_id'); if (function_exists('pll_get_post')) { $p24responsePage = get_permalink(pll_get_post(get_option('six_storage_ptwofour_response_page_id'))); } else{ $p24responsePage = get_permalink(get_option('six_storage_ptwofour_response_page_id')); } $url = $this->six_storage_api_url . 'cards/add/form/' . $userId; $response = wp_remote_get($url, array( 'method' => 'POST', 'timeout' => 45, 'headers' => $this->six_storage_http_header, 'body' => json_encode([ 'hostURL' => $hostURL, 'platform' => $platform, 'logger' => json_decode($userLocationInformation), 'paymentModeId' => $paymentModeId, 'language' => $sixStoragelanguageCode, 'transactionCallback' => $p24responsePage ]) )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Vehicle information save failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_getUserDocuments() { $sessionUserId = $this->six_storage_validate_session_user(); $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); // $userId = sanitize_text_field($_POST['userId']); $userId = $sessionUserId; $isAjax = true; $url = $this->six_storage_api_url . 'user/documents/' . $userId; $response = wp_remote_post(esc_url_raw($url), array( 'method' => 'GET', 'timeout' => 45, 'headers' => $this->six_storage_http_header )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Vehicle information save failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_postUserDocument() { $sessionUserId = $this->six_storage_validate_session_user(); $userId = $sessionUserId; // $userId = sanitize_text_field($_POST['userId']); $uploadedName = sanitize_text_field($_POST['documentName']); $uploadedFileName = sanitize_text_field($_POST['documentFileName']); $filePath = $_FILES["documentFile"]["tmp_name"]; $fp = fopen($filePath, 'r'); $file_data = fread($fp, filesize($filePath)); fclose($fp); $mime_boundary=md5(time()); $eol = "\r\n"; $post_fields = ''; $post_fields .= '------' . $mime_boundary . $eol; $post_fields .= 'Content-Disposition: form-data; name="FileData"; filename= "' . $uploadedFileName . '"' . $eol; $post_fields .= 'Content-Type: multipart/form-data' . $eol . $eol; $post_fields .= $file_data . $eol; $post_fields .= "------" . $mime_boundary . $eol; $post_fields .= 'Content-Disposition: form-data; name="logger"' . $eol. $eol; $post_fields .= $userLocationInformation . $eol; $post_fields .= "------" . $mime_boundary . $eol; $post_fields .= 'Content-Disposition: form-data; name="FileName"' . $eol. $eol; $post_fields .= $uploadedName . $eol; $post_fields .= "------" . $mime_boundary . "--"; $isAjax = true; $url = $this->six_storage_api_url . 'user/documents/' . $userId; $custom_headers=[ 'Authorization' => 'Bearer ' . $this->six_storage_access_token, 'Content-Type' => 'multipart/form-data; boundary=----' . $mime_boundary, 'accept' => 'application/json', 'Content-Length' => strlen($post_fields), 'Pragma' => 'no-cache', 'Connection' => 'keep-alive', 'Cache-Control' => 'no-cache', 'Accept-Language' => 'en-US,en;q=0.9', 'Accept-Encoding' => 'gzip, deflate, br' ]; $request = array( 'method' => 'POST', 'timeout' => 45, 'headers' => $custom_headers, 'body' => $post_fields ); $response = wp_remote_post(esc_url_raw($url), $request); if (is_wp_error($response)) { $error = [ 'isSuccess' => false, 'returnMessage' => 'Something went wrong. Please contact support team.', 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Vehicle information save failed. Please contact support team.'; $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_gateCreditCardsList() { $sessionUserId = $this->six_storage_validate_session_user(); $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); // $userId = sanitize_text_field($_POST['userId']); $userId = $sessionUserId; $isAjax = true; $url = $this->six_storage_api_url . 'cards/details/' . $userId; $response = wp_remote_post(esc_url_raw($url), array( 'method' => 'GET', 'timeout' => 45, 'headers' => $this->six_storage_http_header )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Vehicle information save failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_getIbanDetailList() { $sessionUserId = $this->six_storage_validate_session_user(); $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); // $userId = sanitize_text_field($_POST['userId']); $userId = $sessionUserId; $isAjax = true; $url = $this->six_storage_api_url . 'cards/ach-details/' . $userId; $response = wp_remote_post(esc_url_raw($url), array( 'method' => 'GET', 'timeout' => 45, 'headers' => $this->six_storage_http_header )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Vehicle information save failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_deleteCreditCard() { $sessionUserId = $this->six_storage_validate_session_user(); $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); // $userId = sanitize_text_field($_POST['userId']); $userId = $sessionUserId; $cardId = sanitize_text_field($_POST['cardId']); $cardNumber = sanitize_text_field($_POST['cardNumber']); $paymentModeId = sanitize_text_field($_POST['paymentModeId']); $userLocationInformation = sanitize_text_field($_POST['log']); if ($userLocationInformation != "" || $userLocationInformation != null || !empty( $userLocationInformation)){ $userLocationInformation = str_replace('\\', '', $userLocationInformation); $getdyip=$this->six_storage_getIpAddress(); /* Code to get dynamic IP */ $userLocationInformation = json_decode($userLocationInformation); $userLocationInformation->ipAddress = $getdyip; $userLocationInformation = json_encode($userLocationInformation); } $isAjax = true; $url = $this->six_storage_api_url . 'cards/delete/' . $userId . '/' . $cardId; $response = wp_remote_post(esc_url_raw($url), array( 'method' => 'POST', 'timeout' => 45, 'headers' => $this->six_storage_http_header, 'body' => json_encode([ 'cardLastFour' =>$cardNumber, 'paymentModeId' => $paymentModeId, 'logger' => json_decode($userLocationInformation) ]) )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Vehicle information save failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_defaultCreditCard() { $sessionUserId = $this->six_storage_validate_session_user(); $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); // $userId = sanitize_text_field($_POST['userId']); $userId = $sessionUserId; $cardId = sanitize_text_field($_POST['cardId']); $cardLastFour = sanitize_text_field($_POST['cardLastFour']); $paymentModeId = sanitize_text_field($_POST['paymentModeId']); $userLocationInformation = sanitize_text_field($_POST['log']); if ($userLocationInformation != "" || $userLocationInformation != null || !empty( $userLocationInformation)){ $userLocationInformation = str_replace('\\', '', $userLocationInformation); $getdyip=$this->six_storage_getIpAddress(); /* Code to get dynamic IP */ $userLocationInformation = json_decode($userLocationInformation); $userLocationInformation->ipAddress = $getdyip; $userLocationInformation = json_encode($userLocationInformation); } $isAjax = true; $url = $this->six_storage_api_url . 'cards/makedefault/' . $userId . '/' . $cardId; $response = wp_remote_post(esc_url_raw($url), array( 'method' => 'POST', 'timeout' => 45, 'headers' => $this->six_storage_http_header, 'body' => json_encode([ 'cardLastFour' => $cardLastFour, 'paymentModeId' => $paymentModeId, 'logger' => json_decode($userLocationInformation) ]) )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Vehicle information save failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_changeAutopayStatus() { $sessionUserId = $this->six_storage_validate_session_user(); $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); // $userId = sanitize_text_field($_POST['userId']); $userId = $sessionUserId; $status = sanitize_text_field($_POST['status']); $userLocationInformation = sanitize_text_field($_POST['log']); //$paymentModeId = sanitize_text_field($_POST['paymentModeId']); if ($userLocationInformation != "" || $userLocationInformation != null || !empty( $userLocationInformation)){ $userLocationInformation = str_replace('\\', '', $userLocationInformation); $getdyip=$this->six_storage_getIpAddress(); /* Code to get dynamic IP */ $userLocationInformation = json_decode($userLocationInformation); $userLocationInformation->ipAddress = $getdyip; $userLocationInformation = json_encode($userLocationInformation); } $isAjax = true; $url = $this->six_storage_api_url . 'cards/autopay/activate/' . $userId; if ($status == false || $status == "false" || $status == 'false') { $url = $this->six_storage_api_url . 'cards/autopay/deactivate/' . $userId; } $response = wp_remote_post(esc_url_raw($url), array( 'method' => 'POST', 'timeout' => 45, 'headers' => $this->six_storage_http_header, 'body' => json_encode([ 'logger' => json_decode($userLocationInformation) //'paymentModeId' => json_decode($paymentModeId), ]) )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Vehicle information save failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_addUserCard() { $sessionUserId = $this->six_storage_validate_session_user(); $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); // $userId = sanitize_text_field($_POST['userId']); $userId = $sessionUserId; $cardLastFourNum = sanitize_text_field($_POST['cardLastFour']); $userLocationInformation = sanitize_text_field($_POST['logger']); if ($userLocationInformation != "" || $userLocationInformation != null || !empty( $userLocationInformation)){ $userLocationInformation = str_replace('\\', '', $userLocationInformation); $getdyip=$this->six_storage_getIpAddress(); /* Code to get dynamic IP */ $userLocationInformation = json_decode($userLocationInformation); $userLocationInformation->ipAddress = $getdyip; $userLocationInformation = json_encode($userLocationInformation); } $isAjax = true; $url = $this->six_storage_api_url . 'cards/add/' . $userId; $response = wp_remote_post(esc_url_raw($url), array( 'method' => 'POST', 'timeout' => 45, 'headers' => $this->six_storage_http_header, 'body' => json_encode([ 'cardLastFour' =>$cardLastFourNum, 'logger' => json_decode($userLocationInformation) ]) )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Vehicle information save failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_saveTenantPhoto() { $sessionUserId = $this->six_storage_validate_session_user(); $filePath = $_FILES["six_storage_profile_image"]["tmp_name"]; $fp = fopen($filePath, 'r'); $file_data = fread($fp, filesize($filePath)); fclose($fp); // $userId = sanitize_text_field($_POST['userId']); $userId = $sessionUserId; $fileName = sanitize_text_field($_POST['fileName']); $userLocationInformation = sanitize_text_field($_POST['log']); if ($userLocationInformation != "" || $userLocationInformation != null || !empty( $userLocationInformation)){ $userLocationInformation = str_replace('\\', '', $userLocationInformation); $getdyip=$this->six_storage_getIpAddress(); /* Code to get dynamic IP */ $userLocationInformation = json_decode($userLocationInformation); $userLocationInformation->ipAddress = $getdyip; $userLocationInformation = json_encode($userLocationInformation); } $isAjax = true; $url = $this->six_storage_api_url . 'user/profile/picture/' . $userId; $mime_boundary=md5(time()); $eol = "\r\n"; $post_fields = ''; $post_fields .= '------' . $mime_boundary . $eol; $post_fields .= 'Content-Disposition: form-data; name="FileData"; filename= "' . $fileName . '"' . $eol; $post_fields .= 'Content-Type: image/png' . $eol . $eol; $post_fields .= $file_data . $eol; $post_fields .= "------" . $mime_boundary . $eol; $post_fields .= 'Content-Disposition: form-data; name="logger"' . $eol. $eol; $post_fields .= $userLocationInformation . $eol; $post_fields .= "------" . $mime_boundary . $eol; $post_fields .= 'Content-Disposition: form-data; name="FileName"' . $eol. $eol; $post_fields .= 'Test' . $eol; $post_fields .= "------" . $mime_boundary . "--"; $custom_headers=[ 'Authorization' => 'Bearer ' . $this->six_storage_access_token, 'Content-Type' => 'multipart/form-data; boundary=----' . $mime_boundary, 'accept' => 'application/json', 'Content-Length' => strlen($post_fields), 'Pragma' => 'no-cache', 'Connection' => 'keep-alive', 'Cache-Control' => 'no-cache', 'Accept-Language' => 'en-US,en;q=0.9', 'Accept-Encoding' => 'gzip, deflate, br' ]; $isAjax = true; $response = wp_remote_post(esc_url_raw($url), array( 'method' => 'POST', 'timeout' => 45, 'headers' => $custom_headers, 'body' => $post_fields )); if (is_wp_error($response)) { $error = [ 'isSuccess' => false, 'returnMessage' => 'Something went wrong. Please contact support team.', 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team'; $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team'; $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } public function six_storage_removeTenantPhoto() { $sessionUserId = $this->six_storage_validate_session_user(); $this->six_storage_http_header['Content-Language'] = str_replace("_","-",get_locale()); // $userId = sanitize_text_field($_POST['userId']); $userId = $sessionUserId; $isAjax = true; $url = $this->six_storage_api_url . 'user/profile/picture/remove/' . $userId; $response = wp_remote_post(esc_url_raw($url), array( 'method' => 'GET', 'timeout' => 45, 'headers' => $this->six_storage_http_header, )); if (is_wp_error($response)) { $message = 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' =>$message , 'returnCode' => '' ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } else { $response = json_decode($response['body'], true); if (isset($response) && array_key_exists('isSuccess', $response) && $response['isSuccess']) { if (isset($isAjax) && $isAjax == true) { $message = array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Error code: #2 - Vehicle information save failed. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $response['returnMessage'] = $message; wp_send_json(json_encode($response)); wp_die(); } } else { $message = isset($response) && array_key_exists('returnMessage', $response) && $response['returnMessage'] != '' ? $response['returnMessage'] : 'Something went wrong. Please contact support team.'; $message = esc_html__($message,'6storage-rentals'); $error = [ 'isSuccess' => false, 'returnMessage' => $message, 'returnCode' => "" ]; if (isset($isAjax) && $isAjax == true) { wp_send_json(json_encode($error)); wp_die(); } } } } // public function six_storage_verifyOtp() // { // $userId = sanitize_text_field( // wp_unslash($_POST['userId']) // ); // $clientId = sanitize_text_field( // wp_unslash($_POST['clientId']) // ); // $otpCode = sanitize_text_field( // wp_unslash($_POST['otpCode']) // ); // // Dynamic verification channel // // SMS / EMAIL // $channel = sanitize_text_field( // wp_unslash($_POST['channel']) // ); // if (empty($channel)) { // $channel = 'SMS'; // } // $url = $this->six_storage_api_url . 'otp/verify'; // $headers = array( // 'Authorization' => // 'Bearer ' . // $this->six_storage_access_token, // 'Content-Type' => // 'application/json', // 'accept' => // 'application/json' // ); // $body = array( // 'userId' => // $userId, // 'clientId' => // $clientId, // 'otpCode' => // $otpCode, // 'channel' => // strtoupper($channel) // ); // $response = wp_remote_post( // esc_url_raw($url), // array( // 'method' => 'POST', // 'timeout' => 45, // 'headers' => $headers, // 'body' => wp_json_encode($body) // ) // ); // if (is_wp_error($response)) { // wp_send_json(array( // 'isSuccess' => false, // 'returnMessage' => // $response->get_error_message() // )); // wp_die(); // } // $responseBody = // wp_remote_retrieve_body( // $response // ); // $decodedBody = // json_decode( // $responseBody, // true // ); // wp_send_json($decodedBody); // wp_die(); // } // public function six_storage_verifyOtp() // { // die('VERIFY OTP PHP HIT'); // error_log('================================'); // error_log('VERIFY OTP FUNCTION STARTED'); // error_log('POST DATA:'); // error_log(print_r($_POST, true)); // error_log('================================'); // error_log('=== OTP VERIFY FUNCTION HIT ==='); // // if (session_status() === PHP_SESSION_NONE) { // // session_start(); // // } // $userId = sanitize_text_field( // wp_unslash($_POST['userId']) // ); // $email = sanitize_email( // wp_unslash($_POST['email'] ?? '') // ); // error_log('EMAIL FROM POST => ' . $email); // $clientId = sanitize_text_field( // wp_unslash($_POST['clientId']) // ); // $otpCode = sanitize_text_field( // wp_unslash($_POST['otpCode']) // ); // // Dynamic verification channel // // SMS / EMAIL // $channel = sanitize_text_field( // wp_unslash($_POST['channel']) // ); // if (empty($channel)) { // $channel = 'SMS'; // } // $url = $this->six_storage_api_url . 'otp/verify'; // $headers = array( // 'Authorization' => // 'Bearer ' . // $this->six_storage_access_token, // 'Content-Type' => // 'application/json', // 'accept' => // 'application/json' // ); // $body = array( // 'userId' => // $userId, // 'clientId' => // $clientId, // 'otpCode' => // $otpCode, // 'channel' => // strtoupper($channel) // ); // $response = wp_remote_post( // esc_url_raw($url), // array( // 'method' => 'POST', // 'timeout' => 45, // 'headers' => $headers, // 'body' => wp_json_encode($body) // ) // ); // if (is_wp_error($response)) { // wp_send_json(array( // 'isSuccess' => false, // 'returnMessage' => // $response->get_error_message() // )); // wp_die(); // } // $responseBody = // wp_remote_retrieve_body( // $response // ); // // $decodedBody = // // json_decode( // // $responseBody, // // true // // ); // // wp_send_json($decodedBody); // // wp_die(); // $decodedBody = json_decode($responseBody, true); // error_log('OTP RESPONSE:'); // error_log(print_r($decodedBody, true)); // if ( // isset($decodedBody['isSuccess']) && // $decodedBody['isSuccess'] === true // ) { // error_log('OTP SUCCESS'); // error_log('EMAIL => ' . $email); // global $wpdb; // $table_prefix = $wpdb->prefix; // // error_log('SESSION AFTER OTP:'); // // error_log(print_r($_SESSION, true)); // // $email = ''; // // global $wpdb; // // $table_prefix = $wpdb->prefix; // // if ( // // isset($_SESSION[$table_prefix . 'six_storage_sessionObject']['result']['email']) // // ) { // // $email = $_SESSION[$table_prefix . 'six_storage_sessionObject']['result']['email']; // // } // error_log('EMAIL RECEIVED => ' . $email); // if (!empty($email)) { // error_log('CHECKING USER => ' . $email); // $user = get_user_by('email', $email); // if (!$user) { // $random_password = wp_generate_password(); // error_log('USER NOT FOUND, CREATING WP USER'); // $user_id = wp_create_user( // $email, // $random_password, // $email // ); // error_log('USER CREATE RESULT => ' . print_r($user_id, true)); // if (is_wp_error($user_id)) { // error_log( // 'USER CREATE ERROR => ' . // $user_id->get_error_message() // ); // } // if (!is_wp_error($user_id)) { // $user = get_user_by( // 'ID', // $user_id // ); // $user->set_role('subscriber'); // } // } // // if ($user) { // // wp_set_current_user( // // $user->ID // // ); // // wp_set_auth_cookie( // // $user->ID, // // true // // ); // // do_action( // // 'wp_login', // // $user->user_login, // // $user // // ); // // } // if ($user) { // error_log('OTP VERIFIED SUCCESS'); // error_log( // 'BEFORE LOGIN => is_user_logged_in: ' . // (is_user_logged_in() ? 'YES' : 'NO') // ); // error_log('LOGIN USER ID => ' . $user->ID); // wp_set_current_user( // $user->ID // ); // wp_set_auth_cookie( // $user->ID, // true // ); // error_log( // 'AFTER COOKIE => is_user_logged_in=' . // (is_user_logged_in() ? 'YES' : 'NO') // ); // error_log( // 'CURRENT USER => ' . // get_current_user_id() // ); // do_action( // 'wp_login', // $user->user_login, // $user // ); // error_log( // 'AFTER LOGIN => is_user_logged_in: ' . // (is_user_logged_in() ? 'YES' : 'NO') // ); // error_log( // 'CURRENT WP USER ID => ' . // get_current_user_id() // ); // update_user_meta( // $user->ID, // 'six_storage_user_id', // $userId // ); // error_log( // 'SAVED six_storage_user_id => ' . // get_user_meta( // $user->ID, // 'six_storage_user_id', // true // ) // ); // } // } // } // wp_send_json($decodedBody); // wp_die(); // } public function six_storage_verifyOtp() { $userId = sanitize_text_field( wp_unslash($_POST['userId']) ); $email = sanitize_email( wp_unslash($_POST['email'] ?? '') ); $clientId = sanitize_text_field( wp_unslash($_POST['clientId']) ); $otpCode = sanitize_text_field( wp_unslash($_POST['otpCode']) ); $channel = sanitize_text_field( wp_unslash($_POST['channel']) ); if (empty($channel)) { $channel = 'SMS'; } $url = $this->six_storage_api_url . 'otp/verify'; // $url = 'https://api.8storage.com/v1/otp/verify'; $headers = array( 'Authorization' => 'Bearer ' . $this->six_storage_access_token, 'Content-Type' => 'application/json', 'accept' => 'application/json' ); $body = array( 'userId' => $userId, 'clientId' => $clientId, 'otpCode' => $otpCode, 'channel' => strtoupper($channel) ); $response = wp_remote_post( esc_url_raw($url), array( 'method' => 'POST', 'timeout' => 45, 'headers' => $headers, 'body' => wp_json_encode($body) ) ); if (is_wp_error($response)) { wp_send_json(array( 'isSuccess' => false, 'returnMessage' => $response->get_error_message() )); wp_die(); } $responseBody = wp_remote_retrieve_body($response); $decodedBody = json_decode( $responseBody, true ); error_log('OTP RESPONSE =>'); error_log(print_r($decodedBody, true)); if ( isset($decodedBody['isSuccess']) && $decodedBody['isSuccess'] === true ) { error_log('OTP SUCCESS'); $this->six_storage_create_wp_user( $email, $userId ); } wp_send_json($decodedBody); wp_die(); } // public function six_storage_create_wp_user( // ) { // $email = sanitize_email( // wp_unslash($_POST['email'] ?? '') // ); // $userId = sanitize_text_field( // wp_unslash($_POST['userId'] ?? '') // ); // error_log('CREATE WP USER STARTED'); // error_log('EMAIL => ' . $email); // error_log('USER ID => ' . $userId); // error_log( // 'CREATE WP USER STARTED' // ); // if (empty($email)) { // error_log( // 'EMAIL EMPTY' // ); // return false; // } // $user = get_user_by( // 'email', // $email // ); // if (!$user) { // $password = // wp_generate_password(); // $wpUserId = // wp_create_user( // $email, // $password, // $email // ); // if ( // is_wp_error( // $wpUserId // ) // ) { // error_log( // 'CREATE USER ERROR => ' . // $wpUserId->get_error_message() // ); // return false; // } // $user = // get_user_by( // 'ID', // $wpUserId // ); // $user->set_role( // 'subscriber' // ); // } // wp_set_current_user( // $user->ID // ); // wp_set_auth_cookie( // $user->ID, // true // ); // do_action( // 'wp_login', // $user->user_login, // $user // ); // update_user_meta( // $user->ID, // 'six_storage_user_id', // $userId // ); // error_log( // 'WP USER LOGGED IN => ' . // $user->ID // ); // return true; // // wp_die(); // } public function six_storage_create_wp_user() { /* * Get the one-time token generated after * successful 6Storage email/password login. */ $login_token = sanitize_text_field( wp_unslash( $_POST['loginToken'] ?? '' ) ); if (empty($login_token)) { wp_send_json([ 'isSuccess' => false, 'returnMessage' => 'Unauthorized' ]); wp_die(); } /* * Build the server-side token key. */ $token_key = 'six_storage_wp_login_' . hash( 'sha256', $login_token ); /* * Retrieve authentication data that was * stored after successful email/password login. */ $login_data = get_transient( $token_key ); if ( empty($login_data) || empty($login_data['email']) || empty($login_data['userId']) ) { wp_send_json([ 'isSuccess' => false, 'returnMessage' => 'Invalid or expired login token' ]); wp_die(); } /* * Make the token single-use. */ delete_transient( $token_key ); /* * IMPORTANT: * * Do NOT read email/userId from $_POST. * These values are trusted because they came from * the server-side transient created after successful * 6Storage authentication. */ $email = sanitize_email( $login_data['email'] ); $userId = sanitize_text_field( $login_data['userId'] ); if ( empty($email) || empty($userId) ) { wp_send_json([ 'isSuccess' => false, 'returnMessage' => 'Invalid user information' ]); wp_die(); } error_log( 'CREATE WP USER STARTED' ); error_log( 'USER ID => ' . $userId ); /* * Find existing WordPress user. */ $user = get_user_by( 'email', $email ); /* * Create WordPress user if it does not exist. */ if (!$user) { $password = wp_generate_password(); $wpUserId = wp_create_user( $email, $password, $email ); if ( is_wp_error( $wpUserId ) ) { error_log( 'CREATE USER ERROR => ' . $wpUserId->get_error_message() ); wp_send_json([ 'isSuccess' => false, 'returnMessage' => 'Unable to create WordPress user' ]); wp_die(); } $user = get_user_by( 'ID', $wpUserId ); if (!$user) { wp_send_json([ 'isSuccess' => false, 'returnMessage' => 'Unable to retrieve WordPress user' ]); wp_die(); } $user->set_role( 'subscriber' ); } /* * Store the 6Storage user ID. */ update_user_meta( $user->ID, 'six_storage_user_id', $userId ); /* * Authenticate WordPress user. */ wp_set_current_user( $user->ID ); wp_set_auth_cookie( $user->ID, true ); do_action( 'wp_login', $user->user_login, $user ); error_log( 'WP USER LOGGED IN => ' . $user->ID ); // return true; wp_send_json_success([ 'message' => 'WordPress user logged in successfully' ]); } public function six_storage_sendOtp() { $userId = sanitize_text_field( wp_unslash($_POST['userId']) ); $clientId = sanitize_text_field( wp_unslash($_POST['clientId']) ); $url = $this->six_storage_api_url . 'otp/send'; // $url = 'https://api.8storage.com/v1/otp/send'; $headers = array( 'Authorization' => 'Bearer ' . $this->six_storage_access_token, 'Content-Type' => 'application/json', 'accept' => 'application/json' ); $body = array( 'userId' => $userId, 'clientId' => $clientId ); $response = wp_remote_post( esc_url_raw($url), array( 'method' => 'POST', 'timeout' => 45, 'headers' => $headers, 'body' => wp_json_encode($body) ) ); if (is_wp_error($response)) { wp_send_json(array( 'success' => false, 'message' => $response->get_error_message() )); wp_die(); } $responseBody = wp_remote_retrieve_body( $response ); $decodedBody = json_decode( $responseBody, true ); wp_send_json($decodedBody); wp_die(); } public function six_storage_updatePhone() { $userId = sanitize_text_field( wp_unslash($_POST['userId']) ); $clientId = sanitize_text_field( wp_unslash($_POST['clientId']) ); $mobileNo = sanitize_text_field( wp_unslash($_POST['mobileNo']) ); $url = $this->six_storage_api_url . 'otp/update-phone'; // $url = 'https://api.8storage.com/v1/otp/update-phone'; $headers = array( 'Authorization' => 'Bearer ' . $this->six_storage_access_token, 'Content-Type' => 'application/json', 'accept' => 'application/json' ); $body = array( 'userId' => $userId, 'clientId' => $clientId, 'mobileNo' => $mobileNo ); $response = wp_remote_post( esc_url_raw($url), array( 'method' => 'POST', 'timeout' => 45, 'headers' => $headers, 'body' => wp_json_encode($body) ) ); if (is_wp_error($response)) { wp_send_json(array( 'isSuccess' => false, 'returnMessage' => $response->get_error_message() )); wp_die(); } $responseBody = wp_remote_retrieve_body( $response ); $decodedBody = json_decode( $responseBody, true ); wp_send_json($decodedBody); wp_die(); } public function six_storage_dashboardForm() { ob_start(); $currentHour = date('h:i'); echo ''; // enqueue all our style wp_enqueue_style('cc-move-in-style', $this->six_storage_plugin_url . 'assets/css/cc-move-in-style.css' ,array(), $this->six_storage_plugin_version); wp_enqueue_style('materialize', $this->six_storage_plugin_url . 'assets/css/materialize/materialize.css' ,array(), $this->six_storage_plugin_version); wp_enqueue_style('icon', $this->six_storage_plugin_url . 'assets/fonts/icon.css'); require_once $this->six_storage_plugin_path . 'template/portal/dashboard.php'; // enqueue all our scripts wp_enqueue_script('six-storage-dashboard.min', $this->six_storage_plugin_url . 'assets/js/six-storage-dashboard.min.js' ,array(), $this->six_storage_plugin_version); wp_localize_script('six-storage-dashboard.min', 'wordpress_vars', array('six_storage_plugin_path' => SIX_STORAGE_PLUGIN_FILE)); //localize plugin vars wp_localize_script('six-storage-dashboard.min', 'wordpress_vars', $this->six_storage_getPluginvars()); wp_enqueue_script('iframe-resizer', $this->six_storage_plugin_url . 'assets/js/iframe-resizer.js'); return ob_get_clean(); } }