diff --git a/connector-miravia/classes/shared/MiraviaSdk.php b/connector-miravia/classes/shared/MiraviaSdk.php index 2b7e2cb..072d83f 100644 --- a/connector-miravia/classes/shared/MiraviaSdk.php +++ b/connector-miravia/classes/shared/MiraviaSdk.php @@ -268,7 +268,7 @@ class MiraviaSdk } /** - * Test API connection + * Test API connection with different methods */ public function testConnection() { @@ -277,14 +277,24 @@ class MiraviaSdk } try { - // Try to get a simple product list to test connection - $result = $this->getProductList(['page_size' => 1]); + // Try a simpler API method first - get seller info + $request = new SimpleIopRequest('aliexpress.seller.info.query'); - if($result !== false && !isset($result->error_response)) { - return ['success' => true, 'message' => 'Connection successful']; - } else { - $error = isset($result->error_response) ? $result->error_response->msg : $this->last_error; + if(class_exists('LOG')) { + LOG::add("DEBUG SDK: Testing connection with seller info query"); + } + + $response = $this->client->execute($request, $this->access_token); + + if(class_exists('LOG')) { + LOG::add("DEBUG SDK: Seller info response: " . json_encode($response)); + } + + if(isset($response->error_response)) { + $error = $response->error_response->msg; return ['success' => false, 'error' => $error]; + } else { + return ['success' => true, 'message' => 'Connection successful']; } } catch (Exception $e) { @@ -300,6 +310,27 @@ class MiraviaSdk return !empty($this->app_key) && !empty($this->secret_key) && !empty($this->access_token); } + /** + * Debug token information + */ + public function debugTokenInfo() + { + $debug_info = [ + 'app_key' => $this->app_key, + 'has_secret' => !empty($this->secret_key), + 'has_token' => !empty($this->access_token), + 'token_length' => strlen($this->access_token), + 'token_prefix' => substr($this->access_token, 0, 20), + 'gateway_url' => 'https://api-sg.aliexpress.com/sync' + ]; + + if(class_exists('LOG')) { + LOG::add("DEBUG SDK: Token info: " . json_encode($debug_info)); + } + + return $debug_info; + } + /** * Convert Miravia product format to AliExpress API format */