diff --git a/connector-miravia/classes/class.api.php b/connector-miravia/classes/class.api.php index 7e4d851..b60820f 100644 --- a/connector-miravia/classes/class.api.php +++ b/connector-miravia/classes/class.api.php @@ -20,7 +20,8 @@ if( !class_exists('APIMIRAVIA') ) { 'miravia_get_brands', 'miravia_connect_product', 'disconnect_product_miravia', - 'test_miravia_api_connection' + 'test_miravia_api_connection', + 'debug_miravia_credentials' ); foreach( $actionsPrivate as $action ){ add_action( 'wp_ajax_'.$action, array( $this, $action ) ); @@ -586,6 +587,23 @@ if( !class_exists('APIMIRAVIA') ) { } } + function debug_miravia_credentials() { + if (!current_user_can('manage_options')) { + wp_die('Unauthorized'); + } + + $app_key = get_option('miravia_app_key', ''); + $secret_key = get_option('miravia_secret_key', ''); + $access_token = get_option('miravia_access_token', ''); + + echo "
App Key: " . esc_html(substr($app_key, 0, 10)) . "..." . " (length: " . strlen($app_key) . ")
"; + echo "Secret Key: " . esc_html(substr($secret_key, 0, 10)) . "..." . " (length: " . strlen($secret_key) . ")
"; + echo "Access Token: " . esc_html(substr($access_token, 0, 20)) . "..." . " (length: " . strlen($access_token) . ")
"; + + wp_die(); + } + function miravia_update_product() { if ( !current_user_can( 'manage_woocommerce' ) ) { exit; } $result = array( diff --git a/connector-miravia/classes/shared/MiraviaSdk.php b/connector-miravia/classes/shared/MiraviaSdk.php index bca53d9..2b7e2cb 100644 --- a/connector-miravia/classes/shared/MiraviaSdk.php +++ b/connector-miravia/classes/shared/MiraviaSdk.php @@ -22,6 +22,11 @@ class MiraviaSdk $this->secret_key = get_option('miravia_secret_key', ''); $this->access_token = get_option('miravia_access_token', ''); + if(class_exists('LOG')) { + LOG::add("DEBUG SDK: Loaded credentials - App Key: " . substr($this->app_key, 0, 6) . "..."); + LOG::add("DEBUG SDK: Loaded credentials - Access Token: " . substr($this->access_token, 0, 20) . "..."); + } + if(!empty($this->app_key) && !empty($this->secret_key)) { $this->client = new SimpleIopClient('https://api-sg.aliexpress.com/sync', $this->app_key, $this->secret_key); } @@ -275,10 +280,11 @@ class MiraviaSdk // Try to get a simple product list to test connection $result = $this->getProductList(['page_size' => 1]); - if($result !== false) { + if($result !== false && !isset($result->error_response)) { return ['success' => true, 'message' => 'Connection successful']; } else { - return ['success' => false, 'error' => $this->last_error]; + $error = isset($result->error_response) ? $result->error_response->msg : $this->last_error; + return ['success' => false, 'error' => $error]; } } catch (Exception $e) {