Plugin Directory

Changeset 3438504


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

minor fix on debug logs

Location:
affiliate-amazon-shortcode
Files:
2 edited

Legend:

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

    r3438492 r3438504  
    847847        $api_name = $api_version === 'creators' ? 'Creators API' : 'PA-API 5.0';
    848848       
     849        // Parse JSON per determinare tipo di errore specifico
     850        $error_data = json_decode($body, true);
     851        $error_type = $error_data['__type'] ?? '';
     852        $error_code = $error_data['Errors'][0]['Code'] ?? '';
     853       
    849854        $debug_info[] = 'Result: FAILED';
    850855        $debug_info[] = '';
     
    852857       
    853858        if ($http_code === 401) {
    854             $message = 'Authentication failed with ' . $api_name . '. ';
    855            
    856859            if ($api_version === 'creators') {
     860                $message = 'Authentication failed with ' . $api_name . '. ';
    857861                $message .= 'Make sure your Credential ID and Credential Secret are correct and from Creators API section in Associates Central.';
    858862                $debug_info[] = 'Possible causes:';
     
    861865                $debug_info[] = '  - Account not eligible for Creators API';
    862866            } else {
    863                 $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.';
     867                // PA-API 5.0 - distingui tra UnrecognizedClient e InvalidSignature
     868                if (strpos($error_type, 'UnrecognizedClient') !== false || $error_code === 'UnrecognizedClient') {
     869                    $message = 'UnrecognizedClient: The Access Key ID is invalid or not recognized.';
     870                    $debug_info[] = 'ERROR TYPE: UnrecognizedClient';
     871                    $debug_info[] = '';
     872                    $debug_info[] = 'This means:';
     873                    $debug_info[] = '  ❌ Access Key is INCORRECT or not recognized by Amazon';
     874                    $debug_info[] = '';
     875                    $debug_info[] = 'Possible causes:';
     876                    $debug_info[] = '  - Access Key contains typos';
     877                    $debug_info[] = '  - Access Key was revoked or deleted';
     878                    $debug_info[] = '  - Access Key is from wrong Amazon account';
     879                    $debug_info[] = '  - Access Key not yet active (if just created)';
     880                    $debug_info[] = '';
     881                    $debug_info[] = '✓ Good news: Your Secret Key and Region are not being checked yet.';
     882                    $debug_info[] = '  Fix the Access Key first, then retry.';
     883                   
     884                } elseif (strpos($error_type, 'InvalidSignature') !== false || $error_code === 'InvalidSignature') {
     885                    $message = 'InvalidSignature: The AWS signature is invalid.';
     886                    $debug_info[] = 'ERROR TYPE: InvalidSignature';
     887                    $debug_info[] = '';
     888                    $debug_info[] = 'This means EITHER:';
     889                    $debug_info[] = '  A) Secret Key is INCORRECT, OR';
     890                    $debug_info[] = '  B) AWS Region does not match marketplace';
     891                    $debug_info[] = '';
     892                    $debug_info[] = 'How to diagnose:';
     893                    $debug_info[] = '  1. Check AWS Region below (most common cause!)';
     894                    $debug_info[] = '  2. If region is correct → Secret Key is wrong';
     895                    $debug_info[] = '  3. If not sure → Click "Save Changes" in Settings';
     896                    $debug_info[] = '';
     897                   
     898                    // Validazione region
     899                    $marketplaces = affiamsh_get_amazon_marketplaces();
     900                    $expected_region = $marketplaces[$credentials['marketplace']] ?? 'us-east-1';
     901                    if ($credentials['region'] !== $expected_region) {
     902                        $debug_info[] = '⚠️ REGION MISMATCH DETECTED!';
     903                        $debug_info[] = '   Current:  ' . $credentials['region'] . ' ❌';
     904                        $debug_info[] = '   Expected: ' . $expected_region . ' ✓';
     905                        $debug_info[] = '   For marketplace: ' . $credentials['marketplace'];
     906                        $debug_info[] = '';
     907                        $debug_info[] = '→ ACTION: Go to Settings and click "Save Changes" to fix region!';
     908                    } else {
     909                        $debug_info[] = '✓ Region verification: PASSED';
     910                        $debug_info[] = '   Region ' . $credentials['region'] . ' is CORRECT for ' . $credentials['marketplace'];
     911                        $debug_info[] = '';
     912                        $debug_info[] = '→ CONCLUSION: Your SECRET KEY is INCORRECT!';
     913                        $debug_info[] = '   Region is correct, so the signature failed due to wrong Secret Key.';
     914                        $debug_info[] = '   Check your Secret Key in Amazon Associates Central.';
     915                    }
     916                   
     917                } else {
     918                    // Fallback generico 401
     919                    $message = 'Authentication failed with ' . $api_name . '. ';
     920                    $message .= 'Check that your Access Key and Secret Key are correct.';
     921                    $debug_info[] = 'Possible causes:';
     922                    $debug_info[] = '  - Incorrect Access Key or Secret Key';
     923                    $debug_info[] = '  - WRONG AWS REGION for marketplace';
     924                    $debug_info[] = '  - Credentials expired or revoked';
     925                }
    872926            }
    873927        } elseif ($http_code === 403) {
     
    11241178        $error_data = json_decode($error_body, true);
    11251179       
     1180        // Determina il tipo di errore specifico
     1181        $error_type = $error_data['__type'] ?? '';
     1182        $error_code = $error_data['Errors'][0]['Code'] ?? '';
     1183       
    11261184        // Messaggio discreto per utenti pubblici
    11271185        $error_message = '<div style="padding: 12px; background: #f8f9fa; border: 1px solid #dee2e6; border-radius: 4px; margin: 20px 0; color: #6c757d; font-size: 14px;">';
     
    11351193           
    11361194            if ($http_code === 401) {
    1137                 $error_message .= '<p style="margin: 0 0 5px 0;"><strong>InvalidSignature Error</strong></p>';
    1138                 $error_message .= '<p style="margin: 0 0 5px 0;">The AWS signature is invalid. Common causes:</p>';
    1139                 $error_message .= '<ul style="margin: 5px 0 10px 20px; padding: 0;">';
    1140                 $error_message .= '<li>Incorrect Access Key or Secret Key</li>';
    1141                 $error_message .= '<li><strong>Wrong AWS Region for your marketplace</strong> (see below)</li>';
    1142                 $error_message .= '<li>Credentials expired or revoked</li>';
    1143                 $error_message .= '<li>Need to regenerate in Amazon Associates</li>';
    1144                 $error_message .= '</ul>';
     1195                // Distingui tra UnrecognizedClient e InvalidSignature
     1196                if (strpos($error_type, 'UnrecognizedClient') !== false || $error_code === 'UnrecognizedClient') {
     1197                    $error_message .= '<p style="margin: 0 0 5px 0;"><strong style="color: #d63638;">UnrecognizedClient Error</strong></p>';
     1198                    $error_message .= '<p style="margin: 0 0 5px 0;">The Access Key ID is invalid or not recognized.</p>';
     1199                    $error_message .= '<ul style="margin: 5px 0 10px 20px; padding: 0;">';
     1200                    $error_message .= '<li><strong>Access Key is incorrect</strong></li>';
     1201                    $error_message .= '<li>Access Key was revoked or deleted</li>';
     1202                    $error_message .= '<li>Access Key is from wrong Amazon account</li>';
     1203                    $error_message .= '<li>Access Key not yet active (if just created)</li>';
     1204                    $error_message .= '</ul>';
     1205                    $error_message .= '<p style="margin: 5px 0 0 0; color: #0066cc;">✓ <strong>Good news:</strong> Your Secret Key and Region are not being checked yet. Fix the Access Key first.</p>';
     1206                   
     1207                } elseif (strpos($error_type, 'InvalidSignature') !== false || $error_code === 'InvalidSignature') {
     1208                    $error_message .= '<p style="margin: 0 0 5px 0;"><strong style="color: #d63638;">InvalidSignature Error</strong></p>';
     1209                    $error_message .= '<p style="margin: 0 0 5px 0;">The AWS signature failed. This means:</p>';
     1210                    $error_message .= '<ul style="margin: 5px 0 10px 20px; padding: 0;">';
     1211                    $error_message .= '<li><strong>Secret Key is incorrect</strong>, OR</li>';
     1212                    $error_message .= '<li><strong>AWS Region does not match marketplace</strong></li>';
     1213                    $error_message .= '</ul>';
     1214                    $error_message .= '<p style="margin: 5px 0 0 0; padding: 8px; background: #fff3cd; border-left: 3px solid #ffc107;"><strong>🔍 How to diagnose:</strong></p>';
     1215                    $error_message .= '<ol style="margin: 5px 0 5px 20px; padding: 0; line-height: 1.6;">';
     1216                    $error_message .= '<li><strong>First, verify AWS Region below</strong> - this is the most common cause!</li>';
     1217                    $error_message .= '<li>If region is correct for your marketplace → Secret Key is wrong</li>';
     1218                    $error_message .= '<li>If not sure → Try "Save Changes" to recalculate region</li>';
     1219                    $error_message .= '</ol>';
     1220                   
     1221                } else {
     1222                    // Fallback generico 401
     1223                    $error_message .= '<p style="margin: 0 0 5px 0;"><strong>Authentication Error</strong></p>';
     1224                    $error_message .= '<p style="margin: 0 0 5px 0;">Authentication failed. Possible causes:</p>';
     1225                    $error_message .= '<ul style="margin: 5px 0 10px 20px; padding: 0;">';
     1226                    $error_message .= '<li>Incorrect Access Key or Secret Key</li>';
     1227                    $error_message .= '<li>Wrong AWS Region for marketplace</li>';
     1228                    $error_message .= '<li>Credentials expired or revoked</li>';
     1229                    $error_message .= '</ul>';
     1230                }
    11451231            }
    11461232           
     
    11501236            $error_message .= 'Marketplace: <strong style="color: #0066cc;">' . esc_html($credentials['marketplace']) . '</strong><br>';
    11511237            $error_message .= 'AWS Region: <strong style="color: #cc0000;">' . esc_html($credentials['region']) . '</strong><br>';
     1238            $error_message .= 'Access Key: ' . esc_html(substr($credentials['access_key'], 0, 8)) . '...<br>';
    11521239            $error_message .= 'Endpoint: ' . esc_html($url) . '<br>';
     1240           
     1241            // Validazione region per marketplace
     1242            $marketplaces = affiamsh_get_amazon_marketplaces();
     1243            $expected_region = $marketplaces[$credentials['marketplace']] ?? 'us-east-1';
     1244            if ($credentials['region'] !== $expected_region) {
     1245                $error_message .= '<br><strong style="color: #d63638;">⚠️ REGION MISMATCH DETECTED!</strong><br>';
     1246                $error_message .= 'Current region: <span style="color: #d63638;">' . esc_html($credentials['region']) . '</span><br>';
     1247                $error_message .= 'Expected region: <span style="color: #28a745;">' . esc_html($expected_region) . '</span><br>';
     1248                $error_message .= '<strong>→ Go to Settings and click "Save Changes" to fix!</strong><br>';
     1249            } else {
     1250                $error_message .= '<br><span style="color: #28a745;">✓ Region is correct for ' . esc_html($credentials['marketplace']) . '</span><br>';
     1251                if (strpos($error_type, 'InvalidSignature') !== false) {
     1252                    $error_message .= '<strong style="color: #d63638;">→ This means your Secret Key is incorrect!</strong><br>';
     1253                }
     1254            }
     1255           
    11531256            $error_message .= '<br><strong style="color: #333;">Amazon Response:</strong><br>';
    11541257            $error_message .= '<span style="color: #666;">' . esc_html($error_body) . '</span>';
  • affiliate-amazon-shortcode/trunk/affiliate-amazon-shortcode.php

    r3438492 r3438504  
    847847        $api_name = $api_version === 'creators' ? 'Creators API' : 'PA-API 5.0';
    848848       
     849        // Parse JSON per determinare tipo di errore specifico
     850        $error_data = json_decode($body, true);
     851        $error_type = $error_data['__type'] ?? '';
     852        $error_code = $error_data['Errors'][0]['Code'] ?? '';
     853       
    849854        $debug_info[] = 'Result: FAILED';
    850855        $debug_info[] = '';
     
    852857       
    853858        if ($http_code === 401) {
    854             $message = 'Authentication failed with ' . $api_name . '. ';
    855            
    856859            if ($api_version === 'creators') {
     860                $message = 'Authentication failed with ' . $api_name . '. ';
    857861                $message .= 'Make sure your Credential ID and Credential Secret are correct and from Creators API section in Associates Central.';
    858862                $debug_info[] = 'Possible causes:';
     
    861865                $debug_info[] = '  - Account not eligible for Creators API';
    862866            } else {
    863                 $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.';
     867                // PA-API 5.0 - distingui tra UnrecognizedClient e InvalidSignature
     868                if (strpos($error_type, 'UnrecognizedClient') !== false || $error_code === 'UnrecognizedClient') {
     869                    $message = 'UnrecognizedClient: The Access Key ID is invalid or not recognized.';
     870                    $debug_info[] = 'ERROR TYPE: UnrecognizedClient';
     871                    $debug_info[] = '';
     872                    $debug_info[] = 'This means:';
     873                    $debug_info[] = '  ❌ Access Key is INCORRECT or not recognized by Amazon';
     874                    $debug_info[] = '';
     875                    $debug_info[] = 'Possible causes:';
     876                    $debug_info[] = '  - Access Key contains typos';
     877                    $debug_info[] = '  - Access Key was revoked or deleted';
     878                    $debug_info[] = '  - Access Key is from wrong Amazon account';
     879                    $debug_info[] = '  - Access Key not yet active (if just created)';
     880                    $debug_info[] = '';
     881                    $debug_info[] = '✓ Good news: Your Secret Key and Region are not being checked yet.';
     882                    $debug_info[] = '  Fix the Access Key first, then retry.';
     883                   
     884                } elseif (strpos($error_type, 'InvalidSignature') !== false || $error_code === 'InvalidSignature') {
     885                    $message = 'InvalidSignature: The AWS signature is invalid.';
     886                    $debug_info[] = 'ERROR TYPE: InvalidSignature';
     887                    $debug_info[] = '';
     888                    $debug_info[] = 'This means EITHER:';
     889                    $debug_info[] = '  A) Secret Key is INCORRECT, OR';
     890                    $debug_info[] = '  B) AWS Region does not match marketplace';
     891                    $debug_info[] = '';
     892                    $debug_info[] = 'How to diagnose:';
     893                    $debug_info[] = '  1. Check AWS Region below (most common cause!)';
     894                    $debug_info[] = '  2. If region is correct → Secret Key is wrong';
     895                    $debug_info[] = '  3. If not sure → Click "Save Changes" in Settings';
     896                    $debug_info[] = '';
     897                   
     898                    // Validazione region
     899                    $marketplaces = affiamsh_get_amazon_marketplaces();
     900                    $expected_region = $marketplaces[$credentials['marketplace']] ?? 'us-east-1';
     901                    if ($credentials['region'] !== $expected_region) {
     902                        $debug_info[] = '⚠️ REGION MISMATCH DETECTED!';
     903                        $debug_info[] = '   Current:  ' . $credentials['region'] . ' ❌';
     904                        $debug_info[] = '   Expected: ' . $expected_region . ' ✓';
     905                        $debug_info[] = '   For marketplace: ' . $credentials['marketplace'];
     906                        $debug_info[] = '';
     907                        $debug_info[] = '→ ACTION: Go to Settings and click "Save Changes" to fix region!';
     908                    } else {
     909                        $debug_info[] = '✓ Region verification: PASSED';
     910                        $debug_info[] = '   Region ' . $credentials['region'] . ' is CORRECT for ' . $credentials['marketplace'];
     911                        $debug_info[] = '';
     912                        $debug_info[] = '→ CONCLUSION: Your SECRET KEY is INCORRECT!';
     913                        $debug_info[] = '   Region is correct, so the signature failed due to wrong Secret Key.';
     914                        $debug_info[] = '   Check your Secret Key in Amazon Associates Central.';
     915                    }
     916                   
     917                } else {
     918                    // Fallback generico 401
     919                    $message = 'Authentication failed with ' . $api_name . '. ';
     920                    $message .= 'Check that your Access Key and Secret Key are correct.';
     921                    $debug_info[] = 'Possible causes:';
     922                    $debug_info[] = '  - Incorrect Access Key or Secret Key';
     923                    $debug_info[] = '  - WRONG AWS REGION for marketplace';
     924                    $debug_info[] = '  - Credentials expired or revoked';
     925                }
    872926            }
    873927        } elseif ($http_code === 403) {
     
    11241178        $error_data = json_decode($error_body, true);
    11251179       
     1180        // Determina il tipo di errore specifico
     1181        $error_type = $error_data['__type'] ?? '';
     1182        $error_code = $error_data['Errors'][0]['Code'] ?? '';
     1183       
    11261184        // Messaggio discreto per utenti pubblici
    11271185        $error_message = '<div style="padding: 12px; background: #f8f9fa; border: 1px solid #dee2e6; border-radius: 4px; margin: 20px 0; color: #6c757d; font-size: 14px;">';
     
    11351193           
    11361194            if ($http_code === 401) {
    1137                 $error_message .= '<p style="margin: 0 0 5px 0;"><strong>InvalidSignature Error</strong></p>';
    1138                 $error_message .= '<p style="margin: 0 0 5px 0;">The AWS signature is invalid. Common causes:</p>';
    1139                 $error_message .= '<ul style="margin: 5px 0 10px 20px; padding: 0;">';
    1140                 $error_message .= '<li>Incorrect Access Key or Secret Key</li>';
    1141                 $error_message .= '<li><strong>Wrong AWS Region for your marketplace</strong> (see below)</li>';
    1142                 $error_message .= '<li>Credentials expired or revoked</li>';
    1143                 $error_message .= '<li>Need to regenerate in Amazon Associates</li>';
    1144                 $error_message .= '</ul>';
     1195                // Distingui tra UnrecognizedClient e InvalidSignature
     1196                if (strpos($error_type, 'UnrecognizedClient') !== false || $error_code === 'UnrecognizedClient') {
     1197                    $error_message .= '<p style="margin: 0 0 5px 0;"><strong style="color: #d63638;">UnrecognizedClient Error</strong></p>';
     1198                    $error_message .= '<p style="margin: 0 0 5px 0;">The Access Key ID is invalid or not recognized.</p>';
     1199                    $error_message .= '<ul style="margin: 5px 0 10px 20px; padding: 0;">';
     1200                    $error_message .= '<li><strong>Access Key is incorrect</strong></li>';
     1201                    $error_message .= '<li>Access Key was revoked or deleted</li>';
     1202                    $error_message .= '<li>Access Key is from wrong Amazon account</li>';
     1203                    $error_message .= '<li>Access Key not yet active (if just created)</li>';
     1204                    $error_message .= '</ul>';
     1205                    $error_message .= '<p style="margin: 5px 0 0 0; color: #0066cc;">✓ <strong>Good news:</strong> Your Secret Key and Region are not being checked yet. Fix the Access Key first.</p>';
     1206                   
     1207                } elseif (strpos($error_type, 'InvalidSignature') !== false || $error_code === 'InvalidSignature') {
     1208                    $error_message .= '<p style="margin: 0 0 5px 0;"><strong style="color: #d63638;">InvalidSignature Error</strong></p>';
     1209                    $error_message .= '<p style="margin: 0 0 5px 0;">The AWS signature failed. This means:</p>';
     1210                    $error_message .= '<ul style="margin: 5px 0 10px 20px; padding: 0;">';
     1211                    $error_message .= '<li><strong>Secret Key is incorrect</strong>, OR</li>';
     1212                    $error_message .= '<li><strong>AWS Region does not match marketplace</strong></li>';
     1213                    $error_message .= '</ul>';
     1214                    $error_message .= '<p style="margin: 5px 0 0 0; padding: 8px; background: #fff3cd; border-left: 3px solid #ffc107;"><strong>🔍 How to diagnose:</strong></p>';
     1215                    $error_message .= '<ol style="margin: 5px 0 5px 20px; padding: 0; line-height: 1.6;">';
     1216                    $error_message .= '<li><strong>First, verify AWS Region below</strong> - this is the most common cause!</li>';
     1217                    $error_message .= '<li>If region is correct for your marketplace → Secret Key is wrong</li>';
     1218                    $error_message .= '<li>If not sure → Try "Save Changes" to recalculate region</li>';
     1219                    $error_message .= '</ol>';
     1220                   
     1221                } else {
     1222                    // Fallback generico 401
     1223                    $error_message .= '<p style="margin: 0 0 5px 0;"><strong>Authentication Error</strong></p>';
     1224                    $error_message .= '<p style="margin: 0 0 5px 0;">Authentication failed. Possible causes:</p>';
     1225                    $error_message .= '<ul style="margin: 5px 0 10px 20px; padding: 0;">';
     1226                    $error_message .= '<li>Incorrect Access Key or Secret Key</li>';
     1227                    $error_message .= '<li>Wrong AWS Region for marketplace</li>';
     1228                    $error_message .= '<li>Credentials expired or revoked</li>';
     1229                    $error_message .= '</ul>';
     1230                }
    11451231            }
    11461232           
     
    11501236            $error_message .= 'Marketplace: <strong style="color: #0066cc;">' . esc_html($credentials['marketplace']) . '</strong><br>';
    11511237            $error_message .= 'AWS Region: <strong style="color: #cc0000;">' . esc_html($credentials['region']) . '</strong><br>';
     1238            $error_message .= 'Access Key: ' . esc_html(substr($credentials['access_key'], 0, 8)) . '...<br>';
    11521239            $error_message .= 'Endpoint: ' . esc_html($url) . '<br>';
     1240           
     1241            // Validazione region per marketplace
     1242            $marketplaces = affiamsh_get_amazon_marketplaces();
     1243            $expected_region = $marketplaces[$credentials['marketplace']] ?? 'us-east-1';
     1244            if ($credentials['region'] !== $expected_region) {
     1245                $error_message .= '<br><strong style="color: #d63638;">⚠️ REGION MISMATCH DETECTED!</strong><br>';
     1246                $error_message .= 'Current region: <span style="color: #d63638;">' . esc_html($credentials['region']) . '</span><br>';
     1247                $error_message .= 'Expected region: <span style="color: #28a745;">' . esc_html($expected_region) . '</span><br>';
     1248                $error_message .= '<strong>→ Go to Settings and click "Save Changes" to fix!</strong><br>';
     1249            } else {
     1250                $error_message .= '<br><span style="color: #28a745;">✓ Region is correct for ' . esc_html($credentials['marketplace']) . '</span><br>';
     1251                if (strpos($error_type, 'InvalidSignature') !== false) {
     1252                    $error_message .= '<strong style="color: #d63638;">→ This means your Secret Key is incorrect!</strong><br>';
     1253                }
     1254            }
     1255           
    11531256            $error_message .= '<br><strong style="color: #333;">Amazon Response:</strong><br>';
    11541257            $error_message .= '<span style="color: #666;">' . esc_html($error_body) . '</span>';
Note: See TracChangeset for help on using the changeset viewer.