Changeset 3438492
- Timestamp:
- 01/13/2026 10:39:02 AM (3 months ago)
- Location:
- affiliate-amazon-shortcode
- Files:
-
- 2 edited
-
tags/1.8/affiliate-amazon-shortcode.php (modified) (10 diffs)
-
trunk/affiliate-amazon-shortcode.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
affiliate-amazon-shortcode/tags/1.8/affiliate-amazon-shortcode.php
r3438441 r3438492 575 575 576 576 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;">'; 578 578 echo '<p><strong>✅ API Connection Successful!</strong></p>'; 579 579 echo '<p>Your credentials are working correctly.</p>'; 580 580 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 } 581 586 echo '</div>'; 582 587 } 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;">'; 584 589 echo '<p><strong>❌ API Connection Failed</strong></p>'; 585 590 echo '<p>' . esc_html($test_result['message']) . '</p>'; 586 591 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>'; 589 594 echo '</details>'; 590 595 } … … 693 698 'success' => false, 694 699 'message' => 'No credentials configured', 695 'details' => ' '700 'details' => 'Please configure your API credentials in the settings above.' 696 701 ]; 697 702 } 698 703 699 704 $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'); 700 711 701 712 // Test per Creators API (OAuth 2.0 Cognito) 702 713 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 703 719 // Step 1: Ottieni OAuth token 704 720 $access_token = affiamsh_get_oauth_token( … … 709 725 710 726 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 711 731 return [ 712 732 'success' => false, 713 733 '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." 715 735 ]; 716 736 } 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 ---'; 717 742 718 743 // Step 2: Test con richiesta API Creators … … 730 755 $url = add_query_arg(['marketplace' => $credentials['marketplace']], $url); 731 756 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 732 764 // Headers Creators API con Version 733 765 $headers = [ … … 746 778 } else { 747 779 // 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 748 786 $payload = json_encode([ 749 787 'Keywords' => 'laptop', … … 759 797 $uriPath = "/paapi5/searchitems"; 760 798 $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'; 761 804 762 805 $awsv4 = new Affiamsh_AwsV4($credentials['access_key'], $credentials['secret_key']); … … 781 824 } 782 825 826 $debug_info[] = ''; 827 $debug_info[] = '--- Response ---'; 828 783 829 // Verifica risposta (comune per entrambe le API) 784 830 if (is_wp_error($response)) { 831 $debug_info[] = 'Result: CONNECTION ERROR'; 832 $debug_info[] = 'Error: ' . $response->get_error_message(); 833 785 834 return [ 786 835 'success' => false, 787 836 'message' => 'Connection error: ' . $response->get_error_message(), 788 'details' => ''837 'details' => implode("\n", $debug_info) 789 838 ]; 790 839 } … … 793 842 $body = wp_remote_retrieve_body($response); 794 843 844 $debug_info[] = 'HTTP Status: ' . $http_code; 845 795 846 if ($http_code !== 200) { 796 847 $api_name = $api_version === 'creators' ? 'Creators API' : 'PA-API 5.0'; 797 848 849 $debug_info[] = 'Result: FAILED'; 850 $debug_info[] = ''; 851 $debug_info[] = '--- Error Details ---'; 852 798 853 if ($http_code === 401) { 799 854 $message = 'Authentication failed with ' . $api_name . '. '; 855 800 856 if ($api_version === 'creators') { 801 857 $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'; 802 862 } else { 803 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.'; 804 872 } 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.'; 805 882 } else { 806 883 $message = $api_name . ' returned HTTP ' . $http_code; 807 884 } 885 886 $debug_info[] = ''; 887 $debug_info[] = '--- Amazon Response ---'; 888 $debug_info[] = $body; 808 889 809 890 return [ 810 891 'success' => false, 811 892 'message' => $message, 812 'details' => $body893 'details' => implode("\n", $debug_info) 813 894 ]; 814 895 } … … 817 898 $data = json_decode($body, true); 818 899 $items = $data['searchResult']['items'] ?? $data['SearchResult']['Items'] ?? []; 900 901 $debug_info[] = 'Result: SUCCESS'; 902 $debug_info[] = 'Items found: ' . count($items); 819 903 820 904 return [ … … 822 906 'message' => 'Connection successful!', 823 907 'item_count' => count($items), 824 'details' => ''908 'details' => implode("\n", $debug_info) 825 909 ]; 826 910 } -
affiliate-amazon-shortcode/trunk/affiliate-amazon-shortcode.php
r3438441 r3438492 575 575 576 576 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;">'; 578 578 echo '<p><strong>✅ API Connection Successful!</strong></p>'; 579 579 echo '<p>Your credentials are working correctly.</p>'; 580 580 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 } 581 586 echo '</div>'; 582 587 } 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;">'; 584 589 echo '<p><strong>❌ API Connection Failed</strong></p>'; 585 590 echo '<p>' . esc_html($test_result['message']) . '</p>'; 586 591 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>'; 589 594 echo '</details>'; 590 595 } … … 693 698 'success' => false, 694 699 'message' => 'No credentials configured', 695 'details' => ' '700 'details' => 'Please configure your API credentials in the settings above.' 696 701 ]; 697 702 } 698 703 699 704 $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'); 700 711 701 712 // Test per Creators API (OAuth 2.0 Cognito) 702 713 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 703 719 // Step 1: Ottieni OAuth token 704 720 $access_token = affiamsh_get_oauth_token( … … 709 725 710 726 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 711 731 return [ 712 732 'success' => false, 713 733 '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." 715 735 ]; 716 736 } 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 ---'; 717 742 718 743 // Step 2: Test con richiesta API Creators … … 730 755 $url = add_query_arg(['marketplace' => $credentials['marketplace']], $url); 731 756 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 732 764 // Headers Creators API con Version 733 765 $headers = [ … … 746 778 } else { 747 779 // 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 748 786 $payload = json_encode([ 749 787 'Keywords' => 'laptop', … … 759 797 $uriPath = "/paapi5/searchitems"; 760 798 $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'; 761 804 762 805 $awsv4 = new Affiamsh_AwsV4($credentials['access_key'], $credentials['secret_key']); … … 781 824 } 782 825 826 $debug_info[] = ''; 827 $debug_info[] = '--- Response ---'; 828 783 829 // Verifica risposta (comune per entrambe le API) 784 830 if (is_wp_error($response)) { 831 $debug_info[] = 'Result: CONNECTION ERROR'; 832 $debug_info[] = 'Error: ' . $response->get_error_message(); 833 785 834 return [ 786 835 'success' => false, 787 836 'message' => 'Connection error: ' . $response->get_error_message(), 788 'details' => ''837 'details' => implode("\n", $debug_info) 789 838 ]; 790 839 } … … 793 842 $body = wp_remote_retrieve_body($response); 794 843 844 $debug_info[] = 'HTTP Status: ' . $http_code; 845 795 846 if ($http_code !== 200) { 796 847 $api_name = $api_version === 'creators' ? 'Creators API' : 'PA-API 5.0'; 797 848 849 $debug_info[] = 'Result: FAILED'; 850 $debug_info[] = ''; 851 $debug_info[] = '--- Error Details ---'; 852 798 853 if ($http_code === 401) { 799 854 $message = 'Authentication failed with ' . $api_name . '. '; 855 800 856 if ($api_version === 'creators') { 801 857 $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'; 802 862 } else { 803 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.'; 804 872 } 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.'; 805 882 } else { 806 883 $message = $api_name . ' returned HTTP ' . $http_code; 807 884 } 885 886 $debug_info[] = ''; 887 $debug_info[] = '--- Amazon Response ---'; 888 $debug_info[] = $body; 808 889 809 890 return [ 810 891 'success' => false, 811 892 'message' => $message, 812 'details' => $body893 'details' => implode("\n", $debug_info) 813 894 ]; 814 895 } … … 817 898 $data = json_decode($body, true); 818 899 $items = $data['searchResult']['items'] ?? $data['SearchResult']['Items'] ?? []; 900 901 $debug_info[] = 'Result: SUCCESS'; 902 $debug_info[] = 'Items found: ' . count($items); 819 903 820 904 return [ … … 822 906 'message' => 'Connection successful!', 823 907 'item_count' => count($items), 824 'details' => ''908 'details' => implode("\n", $debug_info) 825 909 ]; 826 910 }
Note: See TracChangeset
for help on using the changeset viewer.