Plugin Directory

Changeset 3438492


Ignore:
Timestamp:
01/13/2026 10:39:02 AM (3 months ago)
Author:
onodev77
Message:

minor fix

Location:
affiliate-amazon-shortcode
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • affiliate-amazon-shortcode/tags/1.8/affiliate-amazon-shortcode.php

    r3438441 r3438492  
    575575           
    576576            if ($test_result['success']) {
    577                 echo '<div class="notice notice-success" style="margin-top: 15px;">';
     577                echo '<div class="notice notice-success" style="margin-top: 15px; padding: 15px;">';
    578578                echo '<p><strong>✅ API Connection Successful!</strong></p>';
    579579                echo '<p>Your credentials are working correctly.</p>';
    580580                echo '<p>Found ' . esc_html($test_result['item_count']) . ' products for test keyword "laptop".</p>';
     581                if (!empty($test_result['details'])) {
     582                    echo '<details style="margin-top: 10px;"><summary style="cursor: pointer; color: #666;">Show Debug Info</summary>';
     583                    echo '<pre style="background: #f5f5f5; padding: 10px; border-radius: 3px; overflow-x: auto; font-size: 11px; margin-top: 8px;">' . esc_html($test_result['details']) . '</pre>';
     584                    echo '</details>';
     585                }
    581586                echo '</div>';
    582587            } else {
    583                 echo '<div class="notice notice-error" style="margin-top: 15px;">';
     588                echo '<div class="notice notice-error" style="margin-top: 15px; padding: 15px;">';
    584589                echo '<p><strong>❌ API Connection Failed</strong></p>';
    585590                echo '<p>' . esc_html($test_result['message']) . '</p>';
    586591                if (!empty($test_result['details'])) {
    587                     echo '<details><summary>Error Details</summary>';
    588                     echo '<pre>' . esc_html($test_result['details']) . '</pre>';
     592                    echo '<details open style="margin-top: 10px;"><summary style="cursor: pointer; color: #d63638; font-weight: 600;">Debug Information (Important!)</summary>';
     593                    echo '<pre style="background: #fff; padding: 12px; border: 1px solid #ddd; border-radius: 3px; overflow-x: auto; font-size: 11px; margin-top: 8px; line-height: 1.5;">' . esc_html($test_result['details']) . '</pre>';
    589594                    echo '</details>';
    590595                }
     
    693698            'success' => false,
    694699            'message' => 'No credentials configured',
    695             'details' => ''
     700            'details' => 'Please configure your API credentials in the settings above.'
    696701        ];
    697702    }
    698703   
    699704    $api_version = $credentials['api_version'] ?? 'creators';
     705   
     706    // Array per debug info
     707    $debug_info = [];
     708    $debug_info[] = '=== TEST API CONNECTION DEBUG INFO ===';
     709    $debug_info[] = 'API Version: ' . $api_version;
     710    $debug_info[] = 'Marketplace: ' . ($credentials['marketplace'] ?? 'N/A');
    700711   
    701712    // Test per Creators API (OAuth 2.0 Cognito)
    702713    if ($api_version === 'creators') {
     714        $debug_info[] = 'Version: ' . ($credentials['version'] ?? '2.2');
     715        $debug_info[] = 'Partner Tag: ' . ($credentials['partner_tag'] ?? 'N/A');
     716        $debug_info[] = '';
     717        $debug_info[] = '--- Step 1: OAuth Token Request ---';
     718       
    703719        // Step 1: Ottieni OAuth token
    704720        $access_token = affiamsh_get_oauth_token(
     
    709725       
    710726        if ($access_token === false) {
     727            $debug_info[] = 'Result: FAILED';
     728            $debug_info[] = 'Cognito Endpoint: https://api.amazon.com/auth/o2/token';
     729            $debug_info[] = 'Credential ID: ' . substr($credentials['credential_id'], 0, 8) . '...';
     730           
    711731            return [
    712732                'success' => false,
    713733                'message' => 'OAuth authentication failed. Could not obtain access token from Cognito.',
    714                 'details' => 'Check your Credential ID and Credential Secret. Version: ' . ($credentials['version'] ?? '2.2')
     734                'details' => implode("\n", $debug_info) . "\n\nCheck your Credential ID and Credential Secret in Creators API section."
    715735            ];
    716736        }
     737       
     738        $debug_info[] = 'Result: SUCCESS';
     739        $debug_info[] = 'Token obtained: ' . substr($access_token, 0, 20) . '...';
     740        $debug_info[] = '';
     741        $debug_info[] = '--- Step 2: Creators API Request ---';
    717742       
    718743        // Step 2: Test con richiesta API Creators
     
    730755        $url = add_query_arg(['marketplace' => $credentials['marketplace']], $url);
    731756       
     757        $debug_info[] = 'Endpoint: ' . $url;
     758        $debug_info[] = 'Method: POST';
     759        $debug_info[] = 'Headers:';
     760        $debug_info[] = '  - Authorization: Bearer [token], Version ' . ($credentials['version'] ?? '2.2');
     761        $debug_info[] = '  - Content-Type: application/json';
     762        $debug_info[] = '  - x-marketplace: ' . $credentials['marketplace'];
     763       
    732764        // Headers Creators API con Version
    733765        $headers = [
     
    746778    } else {
    747779        // Test per PA-API 5.0 (AWS Signature)
     780        $debug_info[] = 'AWS Region: ' . ($credentials['region'] ?? 'N/A');
     781        $debug_info[] = 'Partner Tag: ' . ($credentials['partner_tag'] ?? 'N/A');
     782        $debug_info[] = 'Access Key: ' . substr($credentials['access_key'], 0, 8) . '...';
     783        $debug_info[] = '';
     784        $debug_info[] = '--- PA-API 5.0 Request ---';
     785       
    748786        $payload = json_encode([
    749787            'Keywords' => 'laptop',
     
    759797        $uriPath = "/paapi5/searchitems";
    760798        $url = 'https://' . $host . $uriPath;
     799       
     800        $debug_info[] = 'Endpoint: ' . $url;
     801        $debug_info[] = 'Host: ' . $host;
     802        $debug_info[] = 'Method: POST';
     803        $debug_info[] = 'Signing with AWS Signature Version 4';
    761804       
    762805        $awsv4 = new Affiamsh_AwsV4($credentials['access_key'], $credentials['secret_key']);
     
    781824    }
    782825   
     826    $debug_info[] = '';
     827    $debug_info[] = '--- Response ---';
     828   
    783829    // Verifica risposta (comune per entrambe le API)
    784830    if (is_wp_error($response)) {
     831        $debug_info[] = 'Result: CONNECTION ERROR';
     832        $debug_info[] = 'Error: ' . $response->get_error_message();
     833       
    785834        return [
    786835            'success' => false,
    787836            'message' => 'Connection error: ' . $response->get_error_message(),
    788             'details' => ''
     837            'details' => implode("\n", $debug_info)
    789838        ];
    790839    }
     
    793842    $body = wp_remote_retrieve_body($response);
    794843   
     844    $debug_info[] = 'HTTP Status: ' . $http_code;
     845   
    795846    if ($http_code !== 200) {
    796847        $api_name = $api_version === 'creators' ? 'Creators API' : 'PA-API 5.0';
    797848       
     849        $debug_info[] = 'Result: FAILED';
     850        $debug_info[] = '';
     851        $debug_info[] = '--- Error Details ---';
     852       
    798853        if ($http_code === 401) {
    799854            $message = 'Authentication failed with ' . $api_name . '. ';
     855           
    800856            if ($api_version === 'creators') {
    801857                $message .= 'Make sure your Credential ID and Credential Secret are correct and from Creators API section in Associates Central.';
     858                $debug_info[] = 'Possible causes:';
     859                $debug_info[] = '  - Incorrect Credential ID or Credential Secret';
     860                $debug_info[] = '  - Credentials not from Creators API section';
     861                $debug_info[] = '  - Account not eligible for Creators API';
    802862            } else {
    803863                $message .= 'Check that your Access Key and Secret Key are correct.';
     864                $debug_info[] = 'Possible causes:';
     865                $debug_info[] = '  - Incorrect Access Key or Secret Key';
     866                $debug_info[] = '  - WRONG AWS REGION for marketplace (check region above!)';
     867                $debug_info[] = '  - Credentials expired or revoked';
     868                $debug_info[] = '';
     869                $debug_info[] = '⚠️ IMPORTANT: For ' . $credentials['marketplace'];
     870                $debug_info[] = '   Expected region: ' . $credentials['region'];
     871                $debug_info[] = '   If this is wrong, save settings to recalculate.';
    804872            }
     873        } elseif ($http_code === 403) {
     874            $message = $api_name . ' returned HTTP 403 (Forbidden)';
     875            $debug_info[] = 'Possible causes:';
     876            $debug_info[] = '  - Account not eligible (need 10 sales for Creators API)';
     877            $debug_info[] = '  - Subscription expired';
     878            $debug_info[] = '  - IP address blocked';
     879        } elseif ($http_code === 429) {
     880            $message = $api_name . ' returned HTTP 429 (Too Many Requests)';
     881            $debug_info[] = 'You are being rate-limited. Wait a few minutes and try again.';
    805882        } else {
    806883            $message = $api_name . ' returned HTTP ' . $http_code;
    807884        }
     885       
     886        $debug_info[] = '';
     887        $debug_info[] = '--- Amazon Response ---';
     888        $debug_info[] = $body;
    808889       
    809890        return [
    810891            'success' => false,
    811892            'message' => $message,
    812             'details' => $body
     893            'details' => implode("\n", $debug_info)
    813894        ];
    814895    }
     
    817898    $data = json_decode($body, true);
    818899    $items = $data['searchResult']['items'] ?? $data['SearchResult']['Items'] ?? [];
     900   
     901    $debug_info[] = 'Result: SUCCESS';
     902    $debug_info[] = 'Items found: ' . count($items);
    819903   
    820904    return [
     
    822906        'message' => 'Connection successful!',
    823907        'item_count' => count($items),
    824         'details' => ''
     908        'details' => implode("\n", $debug_info)
    825909    ];
    826910}
  • affiliate-amazon-shortcode/trunk/affiliate-amazon-shortcode.php

    r3438441 r3438492  
    575575           
    576576            if ($test_result['success']) {
    577                 echo '<div class="notice notice-success" style="margin-top: 15px;">';
     577                echo '<div class="notice notice-success" style="margin-top: 15px; padding: 15px;">';
    578578                echo '<p><strong>✅ API Connection Successful!</strong></p>';
    579579                echo '<p>Your credentials are working correctly.</p>';
    580580                echo '<p>Found ' . esc_html($test_result['item_count']) . ' products for test keyword "laptop".</p>';
     581                if (!empty($test_result['details'])) {
     582                    echo '<details style="margin-top: 10px;"><summary style="cursor: pointer; color: #666;">Show Debug Info</summary>';
     583                    echo '<pre style="background: #f5f5f5; padding: 10px; border-radius: 3px; overflow-x: auto; font-size: 11px; margin-top: 8px;">' . esc_html($test_result['details']) . '</pre>';
     584                    echo '</details>';
     585                }
    581586                echo '</div>';
    582587            } else {
    583                 echo '<div class="notice notice-error" style="margin-top: 15px;">';
     588                echo '<div class="notice notice-error" style="margin-top: 15px; padding: 15px;">';
    584589                echo '<p><strong>❌ API Connection Failed</strong></p>';
    585590                echo '<p>' . esc_html($test_result['message']) . '</p>';
    586591                if (!empty($test_result['details'])) {
    587                     echo '<details><summary>Error Details</summary>';
    588                     echo '<pre>' . esc_html($test_result['details']) . '</pre>';
     592                    echo '<details open style="margin-top: 10px;"><summary style="cursor: pointer; color: #d63638; font-weight: 600;">Debug Information (Important!)</summary>';
     593                    echo '<pre style="background: #fff; padding: 12px; border: 1px solid #ddd; border-radius: 3px; overflow-x: auto; font-size: 11px; margin-top: 8px; line-height: 1.5;">' . esc_html($test_result['details']) . '</pre>';
    589594                    echo '</details>';
    590595                }
     
    693698            'success' => false,
    694699            'message' => 'No credentials configured',
    695             'details' => ''
     700            'details' => 'Please configure your API credentials in the settings above.'
    696701        ];
    697702    }
    698703   
    699704    $api_version = $credentials['api_version'] ?? 'creators';
     705   
     706    // Array per debug info
     707    $debug_info = [];
     708    $debug_info[] = '=== TEST API CONNECTION DEBUG INFO ===';
     709    $debug_info[] = 'API Version: ' . $api_version;
     710    $debug_info[] = 'Marketplace: ' . ($credentials['marketplace'] ?? 'N/A');
    700711   
    701712    // Test per Creators API (OAuth 2.0 Cognito)
    702713    if ($api_version === 'creators') {
     714        $debug_info[] = 'Version: ' . ($credentials['version'] ?? '2.2');
     715        $debug_info[] = 'Partner Tag: ' . ($credentials['partner_tag'] ?? 'N/A');
     716        $debug_info[] = '';
     717        $debug_info[] = '--- Step 1: OAuth Token Request ---';
     718       
    703719        // Step 1: Ottieni OAuth token
    704720        $access_token = affiamsh_get_oauth_token(
     
    709725       
    710726        if ($access_token === false) {
     727            $debug_info[] = 'Result: FAILED';
     728            $debug_info[] = 'Cognito Endpoint: https://api.amazon.com/auth/o2/token';
     729            $debug_info[] = 'Credential ID: ' . substr($credentials['credential_id'], 0, 8) . '...';
     730           
    711731            return [
    712732                'success' => false,
    713733                'message' => 'OAuth authentication failed. Could not obtain access token from Cognito.',
    714                 'details' => 'Check your Credential ID and Credential Secret. Version: ' . ($credentials['version'] ?? '2.2')
     734                'details' => implode("\n", $debug_info) . "\n\nCheck your Credential ID and Credential Secret in Creators API section."
    715735            ];
    716736        }
     737       
     738        $debug_info[] = 'Result: SUCCESS';
     739        $debug_info[] = 'Token obtained: ' . substr($access_token, 0, 20) . '...';
     740        $debug_info[] = '';
     741        $debug_info[] = '--- Step 2: Creators API Request ---';
    717742       
    718743        // Step 2: Test con richiesta API Creators
     
    730755        $url = add_query_arg(['marketplace' => $credentials['marketplace']], $url);
    731756       
     757        $debug_info[] = 'Endpoint: ' . $url;
     758        $debug_info[] = 'Method: POST';
     759        $debug_info[] = 'Headers:';
     760        $debug_info[] = '  - Authorization: Bearer [token], Version ' . ($credentials['version'] ?? '2.2');
     761        $debug_info[] = '  - Content-Type: application/json';
     762        $debug_info[] = '  - x-marketplace: ' . $credentials['marketplace'];
     763       
    732764        // Headers Creators API con Version
    733765        $headers = [
     
    746778    } else {
    747779        // Test per PA-API 5.0 (AWS Signature)
     780        $debug_info[] = 'AWS Region: ' . ($credentials['region'] ?? 'N/A');
     781        $debug_info[] = 'Partner Tag: ' . ($credentials['partner_tag'] ?? 'N/A');
     782        $debug_info[] = 'Access Key: ' . substr($credentials['access_key'], 0, 8) . '...';
     783        $debug_info[] = '';
     784        $debug_info[] = '--- PA-API 5.0 Request ---';
     785       
    748786        $payload = json_encode([
    749787            'Keywords' => 'laptop',
     
    759797        $uriPath = "/paapi5/searchitems";
    760798        $url = 'https://' . $host . $uriPath;
     799       
     800        $debug_info[] = 'Endpoint: ' . $url;
     801        $debug_info[] = 'Host: ' . $host;
     802        $debug_info[] = 'Method: POST';
     803        $debug_info[] = 'Signing with AWS Signature Version 4';
    761804       
    762805        $awsv4 = new Affiamsh_AwsV4($credentials['access_key'], $credentials['secret_key']);
     
    781824    }
    782825   
     826    $debug_info[] = '';
     827    $debug_info[] = '--- Response ---';
     828   
    783829    // Verifica risposta (comune per entrambe le API)
    784830    if (is_wp_error($response)) {
     831        $debug_info[] = 'Result: CONNECTION ERROR';
     832        $debug_info[] = 'Error: ' . $response->get_error_message();
     833       
    785834        return [
    786835            'success' => false,
    787836            'message' => 'Connection error: ' . $response->get_error_message(),
    788             'details' => ''
     837            'details' => implode("\n", $debug_info)
    789838        ];
    790839    }
     
    793842    $body = wp_remote_retrieve_body($response);
    794843   
     844    $debug_info[] = 'HTTP Status: ' . $http_code;
     845   
    795846    if ($http_code !== 200) {
    796847        $api_name = $api_version === 'creators' ? 'Creators API' : 'PA-API 5.0';
    797848       
     849        $debug_info[] = 'Result: FAILED';
     850        $debug_info[] = '';
     851        $debug_info[] = '--- Error Details ---';
     852       
    798853        if ($http_code === 401) {
    799854            $message = 'Authentication failed with ' . $api_name . '. ';
     855           
    800856            if ($api_version === 'creators') {
    801857                $message .= 'Make sure your Credential ID and Credential Secret are correct and from Creators API section in Associates Central.';
     858                $debug_info[] = 'Possible causes:';
     859                $debug_info[] = '  - Incorrect Credential ID or Credential Secret';
     860                $debug_info[] = '  - Credentials not from Creators API section';
     861                $debug_info[] = '  - Account not eligible for Creators API';
    802862            } else {
    803863                $message .= 'Check that your Access Key and Secret Key are correct.';
     864                $debug_info[] = 'Possible causes:';
     865                $debug_info[] = '  - Incorrect Access Key or Secret Key';
     866                $debug_info[] = '  - WRONG AWS REGION for marketplace (check region above!)';
     867                $debug_info[] = '  - Credentials expired or revoked';
     868                $debug_info[] = '';
     869                $debug_info[] = '⚠️ IMPORTANT: For ' . $credentials['marketplace'];
     870                $debug_info[] = '   Expected region: ' . $credentials['region'];
     871                $debug_info[] = '   If this is wrong, save settings to recalculate.';
    804872            }
     873        } elseif ($http_code === 403) {
     874            $message = $api_name . ' returned HTTP 403 (Forbidden)';
     875            $debug_info[] = 'Possible causes:';
     876            $debug_info[] = '  - Account not eligible (need 10 sales for Creators API)';
     877            $debug_info[] = '  - Subscription expired';
     878            $debug_info[] = '  - IP address blocked';
     879        } elseif ($http_code === 429) {
     880            $message = $api_name . ' returned HTTP 429 (Too Many Requests)';
     881            $debug_info[] = 'You are being rate-limited. Wait a few minutes and try again.';
    805882        } else {
    806883            $message = $api_name . ' returned HTTP ' . $http_code;
    807884        }
     885       
     886        $debug_info[] = '';
     887        $debug_info[] = '--- Amazon Response ---';
     888        $debug_info[] = $body;
    808889       
    809890        return [
    810891            'success' => false,
    811892            'message' => $message,
    812             'details' => $body
     893            'details' => implode("\n", $debug_info)
    813894        ];
    814895    }
     
    817898    $data = json_decode($body, true);
    818899    $items = $data['searchResult']['items'] ?? $data['SearchResult']['Items'] ?? [];
     900   
     901    $debug_info[] = 'Result: SUCCESS';
     902    $debug_info[] = 'Items found: ' . count($items);
    819903   
    820904    return [
     
    822906        'message' => 'Connection successful!',
    823907        'item_count' => count($items),
    824         'details' => ''
     908        'details' => implode("\n", $debug_info)
    825909    ];
    826910}
Note: See TracChangeset for help on using the changeset viewer.