Plugin Directory

Changeset 3478498


Ignore:
Timestamp:
03/09/2026 07:50:13 PM (3 weeks ago)
Author:
sendbox
Message:

Version 5.5.3: Add Diagnose and Reset buttons, show actual connection errors

Location:
sendbox-shipping
Files:
17 deleted
8 edited
12 copied

Legend:

Unmodified
Added
Removed
  • sendbox-shipping/tags/5.5.3/README.txt

    r3478438 r3478498  
    55Requires at least: 6.0
    66Tested up to: 6.9
    7 Stable tag: 5.5.2
     7Stable tag: 5.5.3
    88Requires PHP: 7.4
    99License: GPLv2 or later
  • sendbox-shipping/tags/5.5.3/assets/js/admin-settings.js

    r3478438 r3478498  
    115115        }
    116116
     117        // Diagnose button
     118        var diagnoseBtn = document.querySelector(".wooss-diagnose-plugin");
     119        if (diagnoseBtn) {
     120            diagnoseBtn.addEventListener("click", function (e) {
     121                e.preventDefault();
     122                diagnoseBtn.disabled = true;
     123                diagnoseBtn.textContent = "Checking...";
     124
     125                var formData = new FormData();
     126                formData.append("action", "wooss_diagnose");
     127                formData.append("security", wooss_ajax.nonce);
     128
     129                fetch(wooss_ajax.ajax_url, { method: "POST", body: formData })
     130                    .then(function (res) { return res.json(); })
     131                    .then(function (response) {
     132                        diagnoseBtn.disabled = false;
     133                        diagnoseBtn.textContent = "Diagnose";
     134
     135                        if (response.success) {
     136                            var d = response.data;
     137                            var msg = "--- Sendbox Shipping Diagnostics ---\n\n"
     138                                + "Plugin Version: " + d.plugin_version + "\n"
     139                                + "Connection Status: " + d.connection_status + "\n"
     140                                + "Token: " + d.token + "\n"
     141                                + "Token Status: " + d.token_status + "\n"
     142                                + "Outbound Request: " + d.outbound_request + "\n"
     143                                + "Origin Country: " + d.origin_country + "\n"
     144                                + "Origin State: " + d.origin_state + "\n"
     145                                + "Origin City: " + d.origin_city + "\n"
     146                                + "PHP: " + d.php_version + "\n"
     147                                + "WordPress: " + d.wp_version + "\n"
     148                                + "WooCommerce: " + d.wc_version;
     149                            alert(msg);
     150                        } else {
     151                            showError("Diagnosis failed.");
     152                        }
     153                    })
     154                    .catch(function () {
     155                        diagnoseBtn.disabled = false;
     156                        diagnoseBtn.textContent = "Diagnose";
     157                        showError("Network error.");
     158                    });
     159            });
     160        }
     161
    117162        // Reset plugin button
    118163        var resetBtn = document.querySelector(".wooss-reset-plugin");
  • sendbox-shipping/tags/5.5.3/src/Admin/Ajax.php

    r3478438 r3478498  
    2727
    2828        $client = new Client();
    29         if ( ! $client->validate_token( $token ) ) {
     29        $result = $client->validate_token( $token );
     30        if ( is_wp_error( $result ) ) {
     31            wp_send_json_error( array(
     32                'message' => sprintf(
     33                    __( 'Could not connect to Sendbox: %s', 'wooss' ),
     34                    $result->get_error_message()
     35                ),
     36            ) );
     37        }
     38        if ( true !== $result ) {
    3039            wp_send_json_error( array( 'message' => __( 'Invalid access token.', 'wooss' ) ) );
    3140        }
     
    212221    }
    213222
     223    public function diagnose() {
     224        check_ajax_referer( 'wooss-ajax-nonce', 'security' );
     225
     226        if ( ! current_user_can( 'manage_woocommerce' ) ) {
     227            wp_send_json_error( array( 'message' => __( 'Permission denied.', 'wooss' ) ), 403 );
     228        }
     229
     230        $sendbox_data      = get_option( 'sendbox_data', array() );
     231        $connection_status  = get_option( 'wooss_connection_status', false );
     232        $has_token          = ! empty( $sendbox_data['sendbox_auth_token'] );
     233        $token_preview      = $has_token ? substr( $sendbox_data['sendbox_auth_token'], 0, 8 ) . '...' : 'empty';
     234
     235        // Test outbound connection to Sendbox API.
     236        $outbound_test = wp_remote_get( 'https://live.sendbox.co/oauth/profile', array(
     237            'timeout' => 15,
     238            'headers' => array( 'Content-Type' => 'application/json' ),
     239        ) );
     240
     241        if ( is_wp_error( $outbound_test ) ) {
     242            $outbound_status = 'BLOCKED - ' . $outbound_test->get_error_message();
     243        } else {
     244            $outbound_status = 'OK - HTTP ' . wp_remote_retrieve_response_code( $outbound_test );
     245        }
     246
     247        // Test token validity.
     248        $token_status = 'no token';
     249        if ( $has_token ) {
     250            $client       = new Client();
     251            $token_valid  = $client->validate_token( $sendbox_data['sendbox_auth_token'] );
     252            $token_status = $token_valid ? 'valid' : 'invalid';
     253        }
     254
     255        $results = array(
     256            'plugin_version'    => defined( 'WOOSS_VERSION' ) ? WOOSS_VERSION : 'unknown',
     257            'connection_status' => $connection_status ? 'connected' : 'disconnected',
     258            'token'             => $token_preview,
     259            'token_status'      => $token_status,
     260            'outbound_request'  => $outbound_status,
     261            'origin_country'    => isset( $sendbox_data['wooss_country'] ) ? $sendbox_data['wooss_country'] : 'not set',
     262            'origin_state'      => isset( $sendbox_data['wooss_state_name'] ) ? $sendbox_data['wooss_state_name'] : 'not set',
     263            'origin_city'       => isset( $sendbox_data['wooss_city'] ) ? $sendbox_data['wooss_city'] : 'not set',
     264            'php_version'       => phpversion(),
     265            'wp_version'        => get_bloginfo( 'version' ),
     266            'wc_version'        => defined( 'WC_VERSION' ) ? WC_VERSION : 'not active',
     267        );
     268
     269        wp_send_json_success( $results );
     270    }
     271
    214272    public function reset_plugin() {
    215273        check_ajax_referer( 'wooss-ajax-nonce', 'security' );
  • sendbox-shipping/tags/5.5.3/src/Admin/SettingsPage.php

    r3478438 r3478498  
    153153                    <?php esc_html_e( 'Sync changes', 'wooss' ); ?>
    154154                </button>
     155                <button type="button" class="button wooss-diagnose-plugin" style="margin-left:10px;">
     156                    <?php esc_html_e( 'Diagnose', 'wooss' ); ?>
     157                </button>
    155158                <button type="button" class="button wooss-reset-plugin" style="margin-left:10px;color:#d63638;">
    156159                    <?php esc_html_e( 'Reset Plugin', 'wooss' ); ?>
  • sendbox-shipping/tags/5.5.3/src/Api/Client.php

    r3478358 r3478498  
    5757
    5858        if ( is_wp_error( $response ) ) {
    59             return false;
     59            return new \WP_Error( 'connection_failed', $response->get_error_message() );
    6060        }
    6161
    62         return wp_remote_retrieve_response_code( $response ) === 200;
     62        $code = wp_remote_retrieve_response_code( $response );
     63        if ( 200 !== $code ) {
     64            $body = json_decode( wp_remote_retrieve_body( $response ) );
     65            $detail = isset( $body->message ) ? $body->message : ( isset( $body->error ) ? $body->error : '' );
     66            return new \WP_Error( 'invalid_token', sprintf( 'Sendbox returned HTTP %d. %s', $code, $detail ) );
     67        }
     68
     69        return true;
    6370    }
    6471
  • sendbox-shipping/tags/5.5.3/src/Plugin.php

    r3478438 r3478498  
    7272        add_action( 'wp_ajax_request_states', array( $ajax, 'request_states' ) );
    7373        add_action( 'wp_ajax_wooss_reset_plugin', array( $ajax, 'reset_plugin' ) );
     74        add_action( 'wp_ajax_wooss_diagnose', array( $ajax, 'diagnose' ) );
    7475    }
    7576
  • sendbox-shipping/tags/5.5.3/wooss.php

    r3478438 r3478498  
    44 * Plugin URI:        https://sendbox.co/
    55 * Description:       WooCommerce shipping integration with Sendbox — ship from your store to anywhere in the world.
    6  * Version:           5.5.2
     6 * Version:           5.5.3
    77 * Author:            Sendbox
    88 * Author URI:        https://sendbox.co/
     
    2323}
    2424
    25 define( 'WOOSS_VERSION', '5.5.2' );
     25define( 'WOOSS_VERSION', '5.5.3' );
    2626define( 'WOOSS_PLUGIN_FILE', __FILE__ );
    2727define( 'WOOSS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
  • sendbox-shipping/trunk/README.txt

    r3478438 r3478498  
    55Requires at least: 6.0
    66Tested up to: 6.9
    7 Stable tag: 5.5.2
     7Stable tag: 5.5.3
    88Requires PHP: 7.4
    99License: GPLv2 or later
  • sendbox-shipping/trunk/assets/js/admin-settings.js

    r3478438 r3478498  
    115115        }
    116116
     117        // Diagnose button
     118        var diagnoseBtn = document.querySelector(".wooss-diagnose-plugin");
     119        if (diagnoseBtn) {
     120            diagnoseBtn.addEventListener("click", function (e) {
     121                e.preventDefault();
     122                diagnoseBtn.disabled = true;
     123                diagnoseBtn.textContent = "Checking...";
     124
     125                var formData = new FormData();
     126                formData.append("action", "wooss_diagnose");
     127                formData.append("security", wooss_ajax.nonce);
     128
     129                fetch(wooss_ajax.ajax_url, { method: "POST", body: formData })
     130                    .then(function (res) { return res.json(); })
     131                    .then(function (response) {
     132                        diagnoseBtn.disabled = false;
     133                        diagnoseBtn.textContent = "Diagnose";
     134
     135                        if (response.success) {
     136                            var d = response.data;
     137                            var msg = "--- Sendbox Shipping Diagnostics ---\n\n"
     138                                + "Plugin Version: " + d.plugin_version + "\n"
     139                                + "Connection Status: " + d.connection_status + "\n"
     140                                + "Token: " + d.token + "\n"
     141                                + "Token Status: " + d.token_status + "\n"
     142                                + "Outbound Request: " + d.outbound_request + "\n"
     143                                + "Origin Country: " + d.origin_country + "\n"
     144                                + "Origin State: " + d.origin_state + "\n"
     145                                + "Origin City: " + d.origin_city + "\n"
     146                                + "PHP: " + d.php_version + "\n"
     147                                + "WordPress: " + d.wp_version + "\n"
     148                                + "WooCommerce: " + d.wc_version;
     149                            alert(msg);
     150                        } else {
     151                            showError("Diagnosis failed.");
     152                        }
     153                    })
     154                    .catch(function () {
     155                        diagnoseBtn.disabled = false;
     156                        diagnoseBtn.textContent = "Diagnose";
     157                        showError("Network error.");
     158                    });
     159            });
     160        }
     161
    117162        // Reset plugin button
    118163        var resetBtn = document.querySelector(".wooss-reset-plugin");
  • sendbox-shipping/trunk/src/Admin/Ajax.php

    r3478438 r3478498  
    2727
    2828        $client = new Client();
    29         if ( ! $client->validate_token( $token ) ) {
     29        $result = $client->validate_token( $token );
     30        if ( is_wp_error( $result ) ) {
     31            wp_send_json_error( array(
     32                'message' => sprintf(
     33                    __( 'Could not connect to Sendbox: %s', 'wooss' ),
     34                    $result->get_error_message()
     35                ),
     36            ) );
     37        }
     38        if ( true !== $result ) {
    3039            wp_send_json_error( array( 'message' => __( 'Invalid access token.', 'wooss' ) ) );
    3140        }
     
    212221    }
    213222
     223    public function diagnose() {
     224        check_ajax_referer( 'wooss-ajax-nonce', 'security' );
     225
     226        if ( ! current_user_can( 'manage_woocommerce' ) ) {
     227            wp_send_json_error( array( 'message' => __( 'Permission denied.', 'wooss' ) ), 403 );
     228        }
     229
     230        $sendbox_data      = get_option( 'sendbox_data', array() );
     231        $connection_status  = get_option( 'wooss_connection_status', false );
     232        $has_token          = ! empty( $sendbox_data['sendbox_auth_token'] );
     233        $token_preview      = $has_token ? substr( $sendbox_data['sendbox_auth_token'], 0, 8 ) . '...' : 'empty';
     234
     235        // Test outbound connection to Sendbox API.
     236        $outbound_test = wp_remote_get( 'https://live.sendbox.co/oauth/profile', array(
     237            'timeout' => 15,
     238            'headers' => array( 'Content-Type' => 'application/json' ),
     239        ) );
     240
     241        if ( is_wp_error( $outbound_test ) ) {
     242            $outbound_status = 'BLOCKED - ' . $outbound_test->get_error_message();
     243        } else {
     244            $outbound_status = 'OK - HTTP ' . wp_remote_retrieve_response_code( $outbound_test );
     245        }
     246
     247        // Test token validity.
     248        $token_status = 'no token';
     249        if ( $has_token ) {
     250            $client       = new Client();
     251            $token_valid  = $client->validate_token( $sendbox_data['sendbox_auth_token'] );
     252            $token_status = $token_valid ? 'valid' : 'invalid';
     253        }
     254
     255        $results = array(
     256            'plugin_version'    => defined( 'WOOSS_VERSION' ) ? WOOSS_VERSION : 'unknown',
     257            'connection_status' => $connection_status ? 'connected' : 'disconnected',
     258            'token'             => $token_preview,
     259            'token_status'      => $token_status,
     260            'outbound_request'  => $outbound_status,
     261            'origin_country'    => isset( $sendbox_data['wooss_country'] ) ? $sendbox_data['wooss_country'] : 'not set',
     262            'origin_state'      => isset( $sendbox_data['wooss_state_name'] ) ? $sendbox_data['wooss_state_name'] : 'not set',
     263            'origin_city'       => isset( $sendbox_data['wooss_city'] ) ? $sendbox_data['wooss_city'] : 'not set',
     264            'php_version'       => phpversion(),
     265            'wp_version'        => get_bloginfo( 'version' ),
     266            'wc_version'        => defined( 'WC_VERSION' ) ? WC_VERSION : 'not active',
     267        );
     268
     269        wp_send_json_success( $results );
     270    }
     271
    214272    public function reset_plugin() {
    215273        check_ajax_referer( 'wooss-ajax-nonce', 'security' );
  • sendbox-shipping/trunk/src/Admin/SettingsPage.php

    r3478438 r3478498  
    153153                    <?php esc_html_e( 'Sync changes', 'wooss' ); ?>
    154154                </button>
     155                <button type="button" class="button wooss-diagnose-plugin" style="margin-left:10px;">
     156                    <?php esc_html_e( 'Diagnose', 'wooss' ); ?>
     157                </button>
    155158                <button type="button" class="button wooss-reset-plugin" style="margin-left:10px;color:#d63638;">
    156159                    <?php esc_html_e( 'Reset Plugin', 'wooss' ); ?>
  • sendbox-shipping/trunk/src/Api/Client.php

    r3478358 r3478498  
    5757
    5858        if ( is_wp_error( $response ) ) {
    59             return false;
     59            return new \WP_Error( 'connection_failed', $response->get_error_message() );
    6060        }
    6161
    62         return wp_remote_retrieve_response_code( $response ) === 200;
     62        $code = wp_remote_retrieve_response_code( $response );
     63        if ( 200 !== $code ) {
     64            $body = json_decode( wp_remote_retrieve_body( $response ) );
     65            $detail = isset( $body->message ) ? $body->message : ( isset( $body->error ) ? $body->error : '' );
     66            return new \WP_Error( 'invalid_token', sprintf( 'Sendbox returned HTTP %d. %s', $code, $detail ) );
     67        }
     68
     69        return true;
    6370    }
    6471
  • sendbox-shipping/trunk/src/Plugin.php

    r3478438 r3478498  
    7272        add_action( 'wp_ajax_request_states', array( $ajax, 'request_states' ) );
    7373        add_action( 'wp_ajax_wooss_reset_plugin', array( $ajax, 'reset_plugin' ) );
     74        add_action( 'wp_ajax_wooss_diagnose', array( $ajax, 'diagnose' ) );
    7475    }
    7576
  • sendbox-shipping/trunk/wooss.php

    r3478438 r3478498  
    44 * Plugin URI:        https://sendbox.co/
    55 * Description:       WooCommerce shipping integration with Sendbox — ship from your store to anywhere in the world.
    6  * Version:           5.5.2
     6 * Version:           5.5.3
    77 * Author:            Sendbox
    88 * Author URI:        https://sendbox.co/
     
    2323}
    2424
    25 define( 'WOOSS_VERSION', '5.5.2' );
     25define( 'WOOSS_VERSION', '5.5.3' );
    2626define( 'WOOSS_PLUGIN_FILE', __FILE__ );
    2727define( 'WOOSS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
Note: See TracChangeset for help on using the changeset viewer.