Plugin Directory

Changeset 2943682


Ignore:
Timestamp:
07/26/2023 01:23:42 PM (3 years ago)
Author:
eshipper
Message:

v2.15.3

Location:
eshipper-commerce
Files:
24 edited
1 copied

Legend:

Unmodified
Added
Removed
  • eshipper-commerce/tags/2.15.3/assets/eShipper.js

    r2921864 r2943682  
    120120    var errorMsg = '';
    121121
    122     if (domainUrl === 'undefined' || domainUrl == null || domainUrl === '' || !is_url_valid(domainUrl)) {
    123         errorMsg = "Please provide valid domain url";
     122    // Validate eShipper domain
     123    if (domainUrl === 'undefined' || domainUrl == null || domainUrl === '' || !is_url_valid(domainUrl) || !domainUrl.includes('eshipper.com')) {
     124        console.log('invalid domain');
     125        errorMsg = "Please provide valid eShipper domain url";
    124126        show_error_msg();
    125127        resize_activation_tb_window();
    126         jQuery('#eshipper_message p').text(errorMsg);
     128        jQuery('#eshipper_message .msg').html(errorMsg);
    127129        return false;
    128130    } else if (username == 'undefined' || username == null || username == '') {
    129         errorMsg = "Please provide valid username";
     131        errorMsg = "Please provide valid username to connect to eShipper";
    130132        show_error_msg();
    131133        resize_activation_tb_window();
    132         jQuery('#eshipper_message p').text(errorMsg);
     134        jQuery('#eshipper_message .msg').html(errorMsg);
    133135        return false;
    134136    } else if (password == 'undefined' || password == null || password == '') {
    135         errorMsg = "Please provide valid password";
     137        errorMsg = "Please provide valid password to connect to eShipper";
    136138        show_error_msg();
    137139        resize_activation_tb_window();
    138         jQuery('#eshipper_message p').text(errorMsg);
     140        jQuery('#eshipper_message .msg').html(errorMsg);
    139141        return false;
    140142    }
  • eshipper-commerce/tags/2.15.3/framework/db.php

    r2923508 r2943682  
    2929        PluginHealthHelper::createEshipperPluginHealthTable();
    3030
    31         update_option('eshipper_version', ESHIPPER_VERSION_2_15);
     31        // Shipping address table structure was updated to change 'phone_no' datatype to varchar from int
     32        pluginLifeCycle::createEshipperShippingAddressTable();
     33
     34        update_option('eshipper_version', ESHIPPER_VERSION_LATEST);
    3235    }
    3336
     
    3538        global $wpdb;
    3639        if ($wpdb->has_cap( 'utf8mb4_520' )){
    37            $this->collate = 'DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci';
     40            $this->collate = 'DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci';
    3841        } elseif ($wpdb->has_cap( 'utf8mb4' )){
    3942            $this->collate = 'DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci';
     
    4346        return $this->collate;
    4447    }
    45    
     48
    4649
    4750    /*
    4851     * Return resources
    4952     */
    50     abstract function get_resource($id);
    51    
     53    abstract function get_resource($id);
     54
    5255    /*
    5356     * Date format
  • eshipper-commerce/tags/2.15.3/framework/lib/admin-settings.js

    r2921864 r2943682  
    413413    })();
    414414
     415    if (window.location.href.includes('eshipper_health')) {
     416        jQuery('.woocommerce-save-button').addClass('es-d-none');
     417    } else if (window.location.href.includes('eshipper_services') || window.location.href.includes('eshipper_settings')) {
     418        jQuery('.woocommerce-save-button').removeClass('es-d-none');
     419    } // else do nothing
     420
     421    jQuery('#eshipper_health_tab').on('click', function (e) {
     422        jQuery('.woocommerce-save-button').addClass('es-d-none');
     423    });
     424
     425    jQuery('#eshipper_settings_tab').on('click', function (e) {
     426        jQuery('.woocommerce-save-button').removeClass('es-d-none');
     427    });
     428
     429    jQuery('#eshipper_services_tab').on('click', function (e) {
     430        jQuery('.woocommerce-save-button').removeClass('es-d-none');
     431    });
     432
     433    jQuery('#es-plugin-health-db-update').on('click', function (e) {
     434        e.preventDefault();
     435        console.log('Attempting to update database to add plugin health table');
     436
     437        jQuery.ajax({
     438            type: "post",
     439            dataType: "json",
     440            url: ajaxurl,
     441            data: {
     442                action: "plugin_health_db_update",
     443            },
     444            success: function (response) {
     445                console.log('Successfully updated database');
     446
     447                jQuery('#es-plugin-health-db-update-message').removeClass('es-d-none').html(
     448                    response.msg + " <br><br><small><code>Reloading the page in 5 seconds... <br>If the page doesn't reload automatically, click <a href='javascript:void(0)' onclick='window.location.reload();'>here</a> </code></small>"
     449                );
     450
     451                (function () {
     452                    setTimeout(function () {
     453                        window.location.reload();
     454                    }, 5000);
     455                })();
     456            },
     457            error: function (response) {
     458                console.log('Failed to update database. Error Response: ');
     459                console.log(response);
     460                jQuery('#es-plugin-health-db-update-message').removeClass('es-d-none').html(response.msg);
     461            }
     462        });
     463    });
     464
    415465    /**
    416466     * Fix health button on click - Calls woocommerce-eshipper.php -> fix_eshipper_plugin()
  • eshipper-commerce/tags/2.15.3/framework/lib/plugin_health.css

    r2921864 r2943682  
    113113}
    114114
     115.es-row + .es-row {
     116    margin-top: 15px;
     117}
     118
    115119.es-col {
    116120    position: relative;
     
    121125
    122126@media (min-width: 992px) {
     127    .es-col:only-child {
     128        width: 100%;
     129    }
    123130    .es-col {
    124131        float: left;
     
    182189}
    183190
     191.es-text-bold {
     192    font-weight: bold;
     193}
     194
     195.es-text-large {
     196    font-size: larger;
     197}
     198
     199.es-text-small {
     200    font-size: smaller;
     201    line-height: 20px;
     202}
     203
    184204.es-bg-secondary {
    185205    background-color: #31b5c1 !important;
     
    234254.es-box-success {
    235255    border: 2px solid #24ED88;
     256}
     257
     258.es-box-primary {
     259    border: 2px solid #472F92;
    236260}
    237261
  • eshipper-commerce/tags/2.15.3/framework/plugin.php

    r2923508 r2943682  
    194194            wp_enqueue_script('eshipper-require-postalcode', plugins_url('lib/require-postalcode.js', ESHIPPER_PLUGIN_FILE), ['jquery'], '1.0', true);
    195195            echo '<div id="calc_shipping_postcode_required" class="hidden woocommerce-info" style="display:none">' . __(
    196                 'Zip / Postal Code is required to calculate shipping',
    197                 'woocommerce-eshipper'
    198             ) . '</div>';
     196                    'Zip / Postal Code is required to calculate shipping',
     197                    'woocommerce-eshipper'
     198                ) . '</div>';
    199199        }
    200200
     
    269269        // DB upgrade for version 2.15.1
    270270        $version = get_option('eshipper_version', '1.0');
    271         if (version_compare($version, ESHIPPER_VERSION_2_15, '<')) {
     271        if (version_compare($version, ESHIPPER_VERSION_LATEST, '<')) {
    272272            // Get required files for db upgrade
    273273            if (!class_exists('woocommerce_eshipper_db')) {
  • eshipper-commerce/tags/2.15.3/framework/shippingmethod.php

    r2923508 r2943682  
    877877            } ?>" id="eshipper_health">
    878878
    879                 <?php $pluginHealth = PluginHealthHelper::getPluginHealth(); ?>
    880 
    881879                <div id="eshipper_health_panel_overlay">
    882880                    <div class="eshipper-preloader">
     
    886884
    887885                <div class="es-row">
    888                     <div class="es-col es_health_font_size">
    889 
    890                         <div class="es_health_check_chart">
    891                             <div class="flex-wrapper">
    892                                 <div class="single-chart">
    893                                     <svg viewBox="0 0 36 36" class="circular-chart blue" id="health-chart">
    894                                         <path class="circle-bg"
    895                                               d="M18 2.0845
     886                    <div class="es-col">
     887                        <div class="es-box es-box-primary">
     888                            <p class="es-text-primary" style="text-align: center">
     889                                <span class="es-text-bold es-text-large">eShipper Plugin Health*</span>
     890                            </p>
     891                            <p>This page visualizes various parameters to help you gauge the health of the eShipper Plugin and it's settings</p>
     892                            <p>The all new eShipper Plugin can now fix issues automatically! You can view, validate & fix most of the issues
     893                                automatically by just clicking the 'Fix' button against the issue item in the 'Health Check' table.
     894                            </p>
     895                            <p><b>Now you can also validate plugin settings!</b> When you make any changes to eShipper's settings, you can validate
     896                                them by clicking on the 'Verify' button against the related health item and wait for the result. If anything goes
     897                                wrong, use the 'Fix' button! You can also use this feature to validate any future updates to the eShipper Plugin.
     898                            </p>
     899                            <p><b>NOTE: While this page covers most of the common issues that usually occur in the plugin as observed on many
     900                                    stores like yours, it should be noted that this is not a comprehensive list and some issues are specific to your
     901                                    WordPress installation which would need manual resolution. For any such issues, please contact <em>eShipper
     902                                        Support</em>.</b>
     903                            </p>
     904                        </div>
     905                        <hr>
     906                    </div>
     907                </div>
     908
     909                <?php
     910                // Enable Plugin Health feature only on PHP v8.0
     911                $validPhpVersion = false;
     912        if (version_compare(phpversion(), '8.0', '<')) {
     913            $pluginHealth = null;
     914        } else {
     915            $validPhpVersion = true;
     916            $pluginHealth = PluginHealthHelper::getPluginHealth();
     917        }
     918        ?>
     919
     920                <?php if (empty($pluginHealth)) {
     921                    // This will be executed when the plugin health table does not exist in the db
     922                    // Show the user an option to update db, if for any reason table could not be created during install/update.
     923                    ?>
     924                    <div class="es-row">
     925                        <div class="es-col">
     926                            <div class="es-box es-box-danger">
     927                                <p>
     928                                    <span class="es-text-danger es-text-bold">Action Required: </span>
     929                                    <br>
     930                                    <?php if ($validPhpVersion) { ?>
     931                                        <span>To view this page, a database update is required. Please click the button below to run the
     932                                        update.</span>
     933                                    <?php } else { ?>
     934                                        To view this page, minimum required version of PHP is 8.0
     935                                        <br>Your site is currently running on PHP version - <span class="es-text-danger"><?= phpversion(); ?></span>
     936                                        <br>Upgrade your PHP version to experience the latest features.
     937                                    <?php } ?>
     938                                </p>
     939                                <p class="es-text-primary"><b>Don't worry if you are not able to view this page properly, this does NOT affect any
     940                                        eShipper services on your store!</b></p>
     941
     942                                <?php if ($validPhpVersion) { ?>
     943                                    <button class='es-button es-button-primary' id="es-plugin-health-db-update">Update Database</button>
     944                                    <p class="es-d-none" id="es-plugin-health-db-update-message"></p>
     945                                <?php } ?>
     946
     947                            </div>
     948                        </div>
     949                    </div>
     950                <?php } else {
     951                    // If table exists, then show the plugin health page.
     952                    // (dev note: closing tag for else is below the following div)
     953                    ?>
     954
     955                    <div class="es-row">
     956                        <div class="es-col es_health_font_size">
     957
     958                            <div class="es_health_check_chart">
     959                                <div class="flex-wrapper">
     960                                    <div class="single-chart">
     961                                        <svg viewBox="0 0 36 36" class="circular-chart blue" id="health-chart">
     962                                            <path class="circle-bg"
     963                                                  d="M18 2.0845
    896964          a 15.9155 15.9155 0 0 1 0 31.831
    897965          a 15.9155 15.9155 0 0 1 0 -31.831"
    898                                         />
    899                                         <path class="circle"
    900                                               stroke-dasharray="<?php echo $pluginHealth['percentage_health'] ?>, 100"
    901                                               d="M18 2.0845
     966                                            />
     967                                            <path class="circle"
     968                                                  stroke-dasharray="<?php echo $pluginHealth['percentage_health'] ?>, 100"
     969                                                  d="M18 2.0845
    902970          a 15.9155 15.9155 0 0 1 0 31.831
    903971          a 15.9155 15.9155 0 0 1 0 -31.831"
    904                                         />
    905                                         <text x="18" y="20.35" class="percentage"><?php echo $pluginHealth['percentage_health'] . '%' ?></text>
    906                                     </svg>
     972                                            />
     973                                            <text x="18" y="20.35" class="percentage"><?php echo $pluginHealth['percentage_health'] . '%' ?></text>
     974                                        </svg>
     975                                    </div>
    907976                                </div>
    908977                            </div>
     978
     979                            <div class="es-row">
     980                                <div class="es-col">
     981                                    <h3>eShipper Plugin Status: <span id="plugin-stats-status"><?php echo $pluginHealth['status']; ?></span>
     982                                    </h3>
     983
     984                                    <p>
     985                                        <b>Issues found: </b> <span id="plugin-stats-issue-count"><?php echo $pluginHealth['issue_count'] ?></span>
     986                                    </p>
     987
     988                                    <p>
     989                                        <b>Last updated at: </b> <span
     990                                            id="plugin-stats-updated-time"><?php echo $pluginHealth['updated_time']; ?></span>
     991                                    </p>
     992                                </div>
     993                                <div class="es-col">
     994                                    <button class='es-button es-button-primary' onclick="window.location.reload();">Recheck</button>
     995                                </div>
     996                            </div>
     997
     998                            <?php if (!empty($pluginHealth['notice'])) { ?>
     999                                <div class="es-box es-box-danger" id="health-action-notice">
     1000                                    <p>
     1001                                        <span class="es-text-danger es-text-bold">Action Required: </span>
     1002                                        <span id="health-action-message"><?php echo $pluginHealth['notice']; ?></span>
     1003                                    </p>
     1004                                </div>
     1005                            <?php } ?>
     1006                            <div class="es-box es-box-success" style="display: none;" id="fix-success-message"></div>
    9091007                        </div>
    9101008
    911                         <div class="es-row">
    912                             <div class="es-col">
    913                                 <h3>eShipper Plugin Status: <span id="plugin-stats-status"><?php echo $pluginHealth['status']; ?></span>
    914                                 </h3>
    915 
    916                                 <p>
    917                                     <b>Issues found: </b> <span id="plugin-stats-issue-count"><?php echo $pluginHealth['issue_count'] ?></span>
    918                                 </p>
    919 
    920                                 <p>
    921                                     <b>Last updated at: </b> <span id="plugin-stats-updated-time"><?php echo $pluginHealth['updated_time']; ?></span>
    922                                 </p>
    923                             </div>
    924                             <div class="es-col">
    925                                 <button class='es-button es-button-primary' onclick="window.location.reload();">Recheck</button>
    926                             </div>
    927                         </div>
    928 
    929                         <?php if (!empty($pluginHealth['notice'])) { ?>
    930                             <div class="es-box es-box-danger" id="health-action-notice">
    931                                 <p>
    932                                     <span class="es-text-danger es-text-bold">Action Required: </span>
    933                                     <span id="health-action-message"><?php echo $pluginHealth['notice']; ?></span>
    934                                 </p>
    935                             </div>
    936                         <?php } ?>
    937                         <div class="es-box es-box-success" style="display: none;" id="fix-success-message"></div>
    938                     </div>
    939 
    940                     <div class="es-col">
    941                         <table class="es_health_table">
    942                             <thead>
    943                             <tr>
    944                                 <th colspan="2">Health Check</th>
    945                                 <th style="text-align: center">Status</th>
    946                                 <th style="text-align: center">Action</th>
    947                             </tr>
    948                             </thead>
    949                             <tbody>
    950                             <?php
    951                             $validAuth = $pluginHealth['items'][PluginHealthHelper::ATTR_AUTH];
    952         foreach ($pluginHealth['items'] as $item => $health) {
    953             $name = PluginHealthHelper::getDisplayName($item);
    954 
    955             // Insert trigger for auth dialog (this will only be done for auth FIX button)
    956             $auth = $item === PluginHealthHelper::ATTR_AUTH && !$validAuth ? "onclick='show_login_popup()'" : "";
    957 
    958             // When Auth is NOT working, all other buttons except FIX button for Auth, will be disabled.
    959             $disabled = $item !== PluginHealthHelper::ATTR_AUTH && !$validAuth ? "disabled title='Please fix Authentication!'" : "";
    960 
    961             $loaderUrl = ESHIPPER_PLUGIN_URL . '/img/preloader.gif';
    962             $loader = "<div class='fix-loader-icon es-d-none' id='$item-fix-loader'>
     1009                        <div class="es-col">
     1010                            <table class="es_health_table">
     1011                                <thead>
     1012                                <tr>
     1013                                    <th colspan="2">Health Check</th>
     1014                                    <th style="text-align: center">Status</th>
     1015                                    <th style="text-align: center">Action</th>
     1016                                </tr>
     1017                                </thead>
     1018                                <tbody>
     1019                                <?php
     1020                                $validAuth = $pluginHealth['items'][PluginHealthHelper::ATTR_AUTH];
     1021                    foreach ($pluginHealth['items'] as $item => $health) {
     1022                        $name = PluginHealthHelper::getDisplayName($item);
     1023
     1024                        // Insert trigger for auth dialog (this will only be done for auth FIX button)
     1025                        $auth = $item === PluginHealthHelper::ATTR_AUTH && !$validAuth ? "onclick='show_login_popup()'" : "";
     1026
     1027                        // When Auth is NOT working, all other buttons except FIX button for Auth, will be disabled.
     1028                        $disabled = $item !== PluginHealthHelper::ATTR_AUTH && !$validAuth ? "disabled title='Please fix Authentication!'" : "";
     1029
     1030                        $loaderUrl = ESHIPPER_PLUGIN_URL . '/img/preloader.gif';
     1031                        $loader = "<div class='fix-loader-icon es-d-none' id='$item-fix-loader'>
    9631032                                                <img src='$loaderUrl' alt='Please wait...'>
    9641033                                            </div>";
    9651034
    966             // Health item status is OK
    967             if ($health) {
    968                 $icon = "<span class='es-text-success' id='$item-status'>OK</span>";
    969                 // If these items are OK, no action is required
    970                 if ($item === PluginHealthHelper::ATTR_AUTH) {
    971                     $action = "";
    972                 } else {
    973                     $action = "<button class='es-button es-button-primary fix-health-btn' $disabled $auth data-issue='$item' data-type='verify'>
     1035                        // Health item status is OK
     1036                        if ($health) {
     1037                            $icon = "<span class='es-text-success' id='$item-status'>OK</span>";
     1038                            // If these items are OK, no action is required
     1039                            if ($item === PluginHealthHelper::ATTR_AUTH) {
     1040                                $action = "";
     1041                            } else {
     1042                                $action = "<button class='es-button es-button-primary fix-health-btn' $disabled $auth data-issue='$item' data-type='verify'>
    9741043                                    <span class='btn-text'>Verify</span>
    9751044                                    $loader
    9761045                               </button>";
    977                 }
    978             } else {
    979                 $icon = "<span class='es-text-danger' id='$item-status'>X</span>";
    980 
    981                 // If these items are NOT OK, only re-install can fix the problem, hence just display 'Re-install'
    982                 if ($item === PluginHealthHelper::ATTR_BACKEND_SYNC) {
    983                     if (!$validAuth) {
    984                         $action = "";
    985                     } else {
    986                         $action = "Re-install";
    987                     }
    988                 } else {
    989                     $action = "<button class='es-button es-button-danger fix-health-btn' $disabled $auth data-issue='$item' data-type='fix'>
     1046                            }
     1047                        } else {
     1048                            $icon = "<span class='es-text-danger' id='$item-status'>X</span>";
     1049
     1050                            // If these items are NOT OK, only re-install can fix the problem, hence just display 'Re-install'
     1051                            if ($item === PluginHealthHelper::ATTR_BACKEND_SYNC) {
     1052                                if (!$validAuth) {
     1053                                    $action = "";
     1054                                } else {
     1055                                    $action = "Re-install";
     1056                                }
     1057                            } else {
     1058                                $action = "<button class='es-button es-button-danger fix-health-btn' $disabled $auth data-issue='$item' data-type='fix'>
    9901059                                <span class='btn-text'>Fix</span>
    9911060                                $loader
    9921061                                </button>";
    993                 }
    994             }
    995 
    996             echo "
     1062                            }
     1063                        }
     1064
     1065                        echo "
    9971066                                    <tr>
    9981067                                        <td colspan='2'>$name</td>
     
    10011070                                    </tr>
    10021071                                    ";
    1003         }
    1004         ?>
    1005                             </tbody>
    1006                         </table>
     1072                    }
     1073                    ?>
     1074                                </tbody>
     1075                            </table>
     1076                        </div>
     1077                    </div>
     1078
     1079                <?php } ?>
     1080
     1081                <div class="es-row" style="margin-top: 50px">
     1082                    <div class="es-col">
     1083                        <hr>
     1084                        <p>
     1085                            <small>
     1086                                * This page is only a visual representation of the eShipper plugin's health and is only meant for reporting purposes.
     1087                                <b> * If you are not able to view this page, it does NOT affect any eShipper services on your store.</b> *
     1088                                To view this page, minimum required PHP
     1089                                version is 8.0
     1090                            </small>
     1091                        </p>
    10071092                    </div>
    10081093                </div>
    1009 
    10101094            </div>
    10111095
  • eshipper-commerce/tags/2.15.3/plugin/PluginHealthHelper.php

    r2921864 r2943682  
    4646    public static function createEshipperPluginHealthTable()
    4747    {
    48         global $wpdb;
    4948        $table = self::getPluginHealthTableName();
    5049
     50        // TODO: This will be removed in the upcoming versions since this is not required because dbDelta() takes care of this action.
    5151        // Drop table if already exists
    52         if ($wpdb->get_var("SHOW TABLES LIKE '$table'") === $table) {
    53             $wpdb->query("DROP TABLE $table");
    54         }
     52//        if ($wpdb->get_var("SHOW TABLES LIKE '$table'") === $table) {
     53//            $wpdb->query("DROP TABLE $table");
     54//        }
    5555
    5656        $columns = '';
    57         foreach (self::getEnabledAttributes() as $attribute) {
    58             $columns .= $attribute . ' tinyint(1) DEFAULT 0,';
    59         }
    60 
    61         $create_plugin_health_table = " CREATE TABLE $table(
     57        foreach (self::getEnabledAttributes() as $index => $attribute) {
     58            // Add a new line for every column (as per wordpress doc here: https://codex.wordpress.org/Creating_Tables_with_Plugins#Creating_or_Updating_the_Table)
     59            // DO NOT REMOVE the formatting below:
     60            $columns .= '
     61            ' . $attribute . ' tinyint(1) DEFAULT 0,';
     62        }
     63
     64        $create_plugin_health_table = "CREATE TABLE $table(
    6265            $columns
    6366            created_time timestamp DEFAULT CURRENT_TIMESTAMP,
     
    131134
    132135    /**
    133      * @return array
     136     * @return array|null
    134137     */
    135138    public static function getPluginHealth($asyncRequest = false)
     
    137140        // Get the table name
    138141        global $wpdb;
    139         $table = self::getPluginHealthTableName();
     142
     143        // This also checks and creates the table if it doesn't exist in the db
     144        $table = self::getPluginHealthTableName(true);
    140145
    141146        // First update the plugin health
     
    148153        // Get the items & their respective status from health table
    149154        $healthItems = $wpdb->get_row("SELECT * from $table", ARRAY_A);
     155
     156        // If there are no items populated in the db, return null
     157        if (empty($healthItems)) {
     158            return null;
     159        }
    150160
    151161        // Filter out items to be displayed
     
    276286        $domainUrl = $wpdb->get_var("SELECT domain_url FROM {$wpdb->prefix}eshipper_access_tokens WHERE currently_active = 1");
    277287
     288        // If domain is empty, no further action - mark auth as false
     289//        if (empty($domainUrl)) {
     290//            return self::recordAuthStatus(false);
     291//        }
     292
     293        // Check in real time if store is connected: Upcoming version
     294//        $storeConnected = eshipperCalls::checkIfStoreIsConnected($domainUrl);
     295
    278296        return self::recordAuthStatus(!empty($domainUrl));
    279297    }
     
    508526
    509527    /**
    510      * @return string
    511      */
    512     private static function getPluginHealthTableName()
    513     {
    514         global $wpdb;
    515 
    516         return $wpdb->prefix . self::TABLE_NAME;
     528     * @param $createTableIfDoesntExist
     529     * @return string|null
     530     */
     531    private static function getPluginHealthTableName(bool $createTableIfDoesntExist = false)
     532    {
     533        global $wpdb;
     534
     535        $table = $wpdb->prefix . self::TABLE_NAME;
     536
     537        // Check if the plugin health table exists and create if it doesn't
     538        if ($createTableIfDoesntExist && $wpdb->get_var("SHOW TABLES LIKE '$table'") !== $table) {
     539            self::createEshipperPluginHealthTable();
     540        }
     541
     542        return $table;
    517543    }
    518544}
  • eshipper-commerce/tags/2.15.3/plugin/eshipperCalls.php

    r2921864 r2943682  
    205205
    206206        $httpResponseCode = $response['httpResponseCode'];
    207         $error_message = $response['response']->errors;
     207        $error_message = isset($response['response']->errors) ? $response['response']->errors : 'Something went wrong! Please contact support.';
    208208
    209209        //if the response code is 200 then create tables and what not
     
    233233        return $responseArray;
    234234    }
     235
     236    /**
     237     * Check if store is connected by invoking eShipper API
     238     * @param $domainUrl
     239     * @return bool
     240     */
     241    public static function checkIfStoreIsConnected($domainUrl)
     242    {
     243        // Get the store domain name
     244        $shopName = trim(str_replace('/shop', '', get_site_url()));
     245        $shopName = rtrim(preg_replace("#^[^:/.]*[:/]+#i", "", $shopName), '/');
     246
     247        // Call the eShipper API to check if this store is installed
     248        $response = (new curlHandler())->sendCurlRequest(
     249            json_encode(['shop' => $shopName]),
     250            "$domainUrl/ecommerce/woocommerce/is-store-installed",
     251            'POST',
     252            [
     253                'Accept: application/json',
     254                'Content-Type: application/json',
     255            ]
     256        );
     257
     258        // If the response is 200 then return true
     259        if (!empty($response['response']) && !empty($httpResponseCode = $response['httpResponseCode']) && $httpResponseCode === 200) {
     260            return true;
     261        }
     262
     263        // If response is not 200 return false
     264        return false;
     265    }
    235266}
  • eshipper-commerce/tags/2.15.3/plugin/pluginLifeCycle.php

    r2923508 r2943682  
    146146
    147147        // Drop table if already exists
    148         if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_boxing_services_master'") === $eshipper_boxing_services_master) {
    149             $wpdb->query("DROP TABLE $eshipper_boxing_services_master");
    150         }
     148//        if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_boxing_services_master'") === $eshipper_boxing_services_master) {
     149//            $wpdb->query("DROP TABLE $eshipper_boxing_services_master");
     150//        }
    151151
    152152        $create_boxing_master_table_query = " CREATE TABLE $eshipper_boxing_services_master(
     
    171171    private static function createEshipperAccessTokensTable()
    172172    {
     173        wc_get_logger()->debug('Attempting to create table - eshipper_access_tokens', ['source' => 'eshipper']);
     174
    173175        global $wpdb;
    174176        $eshipper_access_tokens = $wpdb->prefix . "eshipper_access_tokens";
    175177
    176178        // Drop table if already exists
    177         if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_access_tokens'") === $eshipper_access_tokens) {
    178             $wpdb->query("DROP TABLE $eshipper_access_tokens");
    179         }
     179        // Not required - dbDelta() takes care of that
     180//        if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_access_tokens'") === $eshipper_access_tokens) {
     181//            $wpdb->query("DROP TABLE $eshipper_access_tokens");
     182//        }
    180183
    181184        $access_tokens_query = " CREATE TABLE $eshipper_access_tokens(
     
    192195        require_once(ABSPATH . "wp-admin/includes/upgrade.php");
    193196        dbDelta($access_tokens_query);
     197
     198        wc_get_logger()->debug('Successfully to create table - eshipper_access_tokens', ['source' => 'eshipper']);
    194199    }
    195200
     
    201206    private static function createEshipperCarrierServicesTable()
    202207    {
     208        wc_get_logger()->debug('Attempting to create table - eshipper_carrier_service_master', ['source' => 'eshipper']);
     209
    203210        global $wpdb;
    204211        $eshipper_carrier_services = $wpdb->prefix . "eshipper_carrier_service_master";
    205212
    206213        // Drop table if already exists
    207         if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_carrier_services'") === $eshipper_carrier_services) {
    208             $wpdb->query("DROP TABLE $eshipper_carrier_services");
    209         }
     214//        if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_carrier_services'") === $eshipper_carrier_services) {
     215//            $wpdb->query("DROP TABLE $eshipper_carrier_services");
     216//        }
    210217
    211218        $access_tokens_query = " CREATE TABLE $eshipper_carrier_services(
     
    259266            $status = PluginHealthHelper::recordAuthStatus(true);
    260267        } catch (Exception $exception) {
    261             wc_get_logger()->debug(
     268            wc_get_logger()->error(
    262269                'Error while storing eshipper access token in DB - [ERROR] - ' . print_r($exception->getMessage(), true),
    263270                ['source' => 'eshipper']
     
    297304            $status = PluginHealthHelper::recordStoreAddressStatus(true);
    298305        } catch (Exception $exception) {
    299             wc_get_logger()->debug(
     306            wc_get_logger()->error(
    300307                'Error while copying store address from woocommerce - [ERROR] - ' . print_r($exception->getMessage(), true),
    301308                ['source' => 'eshipper']
     
    434441            $status = PluginHealthHelper::recordWebhooksStatus(true);
    435442        } catch (Exception $exception) {
    436             wc_get_logger()->debug('Error while creating webhooks. - [ERROR] - ' . print_r($exception->getMessage(), true), ['source' => 'eshipper']);
     443            wc_get_logger()->error('Error while creating webhooks. - [ERROR] - ' . print_r($exception->getMessage(), true), ['source' => 'eshipper']);
    437444
    438445            $status = PluginHealthHelper::recordWebhooksStatus(false);
     
    485492     * Function to create table in Woo-Commerce DB to store the Shipping Address
    486493     */
    487     private static function createEshipperShippingAddressTable()
     494    public static function createEshipperShippingAddressTable()
    488495    {
    489496        global $wpdb;
     
    491498
    492499        // Drop table if already exists
    493         if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_shipping_address'") === $eshipper_shipping_address) {
    494             $wpdb->query("DROP TABLE $eshipper_shipping_address");
    495         }
     500//        if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_shipping_address'") === $eshipper_shipping_address) {
     501//            $wpdb->query("DROP TABLE $eshipper_shipping_address");
     502//        }
    496503
    497504        $create_shipping_address_query = " CREATE TABLE $eshipper_shipping_address(
     
    505512            zipcode varchar(255) ,
    506513            shipping_name text ,
    507             phone_no int(14) ,
     514            phone_no varchar(20) ,
    508515            email_id varchar (255),
    509516            created_time timestamp DEFAULT CURRENT_TIMESTAMP,
     
    560567            $status = PluginHealthHelper::recordCarrierServicesStatus(true);
    561568        } catch (Exception $exception) {
    562             wc_get_logger()->debug(
     569            wc_get_logger()->error(
    563570                'Error while adding eshipper carrier services - [ERROR] - ' . print_r($exception->getMessage(), true),
    564571                ['source' => 'eshipper']
  • eshipper-commerce/tags/2.15.3/readme.txt

    r2923520 r2943682  
    55Tested up to: 6.2.2
    66Requires PHP: 7.1
    7 Stable tag: 2.15.2
     7Stable tag: 2.15.3
    88License: GPLv3
    99License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    5454
    5555== Changelog ==
     56= 2.15.3 =
     57* Critical Bug Fixes for versions 2.14.3 & v2.15.2
     58
    5659= 2.15.2 =
    5760* Critical bug fixes & better user experience
     
    8285
    8386== Upgrade Notice ==
     87= 2.15.3 =
     88Upgrade to receive critical bug fixes NOW!
     89
    8490= 2.15.2 =
    8591Recommended upgrade for critical bug fixes in versions 2.15 & 2.15.1
  • eshipper-commerce/tags/2.15.3/views/login_thickbox.php

    r2921864 r2943682  
    9191                        <div class="col-75">
    9292                            <input class="es_input_class" type="text" id="domain_url" name="domain_url" placeholder="https://domain_name.com" value="https://ww2.eshipper.com">
     93                            <small>This should be a valid eShipper domain.</small>
    9394                        </div>
    9495                    </div>
     
    99100                        <div class="col-75">
    100101                            <input class="es_input_class" type="text" id="username" name="username" placeholder="Username">
     102                            <small>Enter your eShipper username to connect the plugin to eShipper services.</small>
    101103                        </div>
    102104                    </div>
     
    109111                            <input type="hidden" name="grant_type" value="password">
    110112                            <input type="hidden" name="client_id" value="web_app">
     113                            <small>Enter your eShipper password to connect the plugin to eShipper services.</small>
    111114                        </div>
    112115                    </div>
  • eshipper-commerce/tags/2.15.3/woocommerce-eshipper.php

    r2923508 r2943682  
    44    Plugin URI: https://ww2.eshipper.com/ecommerce/
    55    Description: Extends WooCommerce with Shipping Rates from eShipper
    6     Version: 2.15.2
     6    Version: 2.15.3
    77    Author: eShipper
    88    Author URI: https://ww2.eshipper.com/
     
    2929))) {
    3030    define('ESHIPPER_VERSION', '1.4.1');
    31     define('ESHIPPER_VERSION_2_15', '2.15.2');
     31    define('ESHIPPER_VERSION_LATEST', '2.15.3');
    3232    //Plugin Path
    3333    define('ESHIPPER_PLUGIN_PATH', dirname(__FILE__));
     
    154154    add_action('wp_ajax_boxing_insert', 'boxing_insert');
    155155    add_action('wp_ajax_fix_eshipper_plugin', 'fix_eshipper_plugin');
     156    add_action('wp_ajax_plugin_health_db_update', 'plugin_health_db_update');
    156157
    157158    function fix_eshipper_plugin()
     
    254255    }
    255256
     257    function plugin_health_db_update()
     258    {
     259        $update = false;
     260        try {
     261            // Log the activity
     262            wc_get_logger()->debug('Attempting to create plugin health table', ['source' => 'eshipper']);
     263
     264            // Attempt to create plugin health table
     265            $update = PluginHealthHelper::createEshipperPluginHealthTable();
     266        } catch (Exception $e) {
     267            wc_get_logger()->error(
     268                'ERROR creating plugin health table: [CODE]: ' . $e->getCode() . ' [ERROR] - ' . print_r($e->getMessage(), true),
     269                ['source' => 'eshipper']
     270            );
     271        }
     272
     273        if ($update) {
     274            $statusCode = 200;
     275            $msg = 'Database Update is successful!';
     276
     277            wc_get_logger()->debug('Successfully created plugin health table.', ['source' => 'eshipper']);
     278
     279            // Validate Plugin health to populate current state of the plugin
     280            PluginHealthHelper::validatePluginHealth();
     281        } else {
     282            $statusCode = 412;
     283            $msg = 'Could not update database, something went wrong while processing your request. Please contact support to fix the issue.';
     284
     285            wc_get_logger()->error('Failed to create plugin health table.', ['source' => 'eshipper']);
     286        }
     287
     288        $result = [
     289            'statusCode' => $statusCode,
     290            'msg' => $msg,
     291        ];
     292
     293        // Return Error Response
     294        echo json_encode($result);
     295        die();
     296    }
     297
    256298    function eshipper_health_check_admin_notice()
    257299    {
     
    329371            'methods' => 'DELETE',
    330372            'callback' => 'uninstallEshipperPlugin',
     373            'permission_callback' => '__return_true',
    331374        ]);
    332375    });
     
    334377    function uninstallEshipperPlugin($request)
    335378    {
     379        wc_get_logger()->debug('Attempting to deactivate eShipper plugin. Store was detached from eShipper', ['source' => 'eshipper']);
    336380        $all_headers = $request->get_headers();
    337381
     
    340384            $responseArray = ['statusCode' => "401", "msg" => "Sorry, you are not authorized to do this event"];
    341385
     386            wc_get_logger()->error('Failed to deactivate eShipper plugin', ['source' => 'eshipper']);
     387
    342388            return new WP_REST_Response($responseArray, 401);
    343389        }
    344390
    345         $plugin = 'eShipper-plugin/woocommerce-eshipper.php';
    346         deactivate_plugins($plugin);
    347         $responseArray = ['statusCode' => "200", "msg" => "eShipper plugin uninstalled successfully"];
    348 
    349         return new WP_REST_Response($responseArray, 200);
     391        // Deactivate the plugin
     392        require_once(ABSPATH . 'wp-admin/includes/plugin.php');
     393        deactivate_plugins(ESHIPPER_PLUGIN_PATH);
     394
     395        // If the plugin is still active at this point then return error
     396        if (is_plugin_active(plugin_basename(ESHIPPER_PLUGIN_FILE))) {
     397            wc_get_logger()->error('Failed to deactivate eShipper plugin. Please deactivate the plugin directly from your store.', ['source' => 'eshipper']);
     398
     399            $responseArray = [
     400                'statusCode' => "412",
     401                "msg" => "Failed to deactivate eShipper plugin. Please deactivate the plugin directly from your store.",
     402            ];
     403            return new WP_REST_Response($responseArray, 412);
     404        } else {
     405            wc_get_logger()->debug('eShipper plugin deactivated successfully. Good bye!', ['source' => 'eshipper']);
     406
     407            $responseArray = [
     408                'statusCode' => "200",
     409                "msg" => "eShipper plugin deactivated successfully!",
     410            ];
     411            return new WP_REST_Response($responseArray, 200);
     412        }
    350413    }
    351414
     
    582645        $validateParameters = 1;
    583646        $requestData = [];
     647        $msg = '';
    584648        if (isset($_POST['formdata']) && is_array($_POST['formdata'])) {
    585649            foreach ($_POST['formdata'] as $k => $formdata) {
     
    589653                    break;
    590654                }
     655
     656                // Validate eShipper's domain (this check is also applied in js hence the code below is a fail safe)
     657                if ($formdata['name'] === 'domain_url' && !str_contains($formdata['value'], 'eshipper.com')) {
     658                    $validateParameters = 0;
     659                    $msg = 'Invalid Domain URL. Please enter the correct eshipper domain';
     660                    break;
     661                }
     662
    591663                $key = $formdata['name'];
    592664                $val = $formdata['value'];
     
    599671            echo json_encode([
    600672                'statusCode' => 412,
    601                 'msg' => 'The credentials you entered are incorrect. Please provide correct data.',
     673                'msg' => $msg ?? 'The credentials you entered are incorrect. Please provide correct data.',
    602674            ]);
    603675            die();
  • eshipper-commerce/trunk/assets/eShipper.js

    r2921864 r2943682  
    120120    var errorMsg = '';
    121121
    122     if (domainUrl === 'undefined' || domainUrl == null || domainUrl === '' || !is_url_valid(domainUrl)) {
    123         errorMsg = "Please provide valid domain url";
     122    // Validate eShipper domain
     123    if (domainUrl === 'undefined' || domainUrl == null || domainUrl === '' || !is_url_valid(domainUrl) || !domainUrl.includes('eshipper.com')) {
     124        console.log('invalid domain');
     125        errorMsg = "Please provide valid eShipper domain url";
    124126        show_error_msg();
    125127        resize_activation_tb_window();
    126         jQuery('#eshipper_message p').text(errorMsg);
     128        jQuery('#eshipper_message .msg').html(errorMsg);
    127129        return false;
    128130    } else if (username == 'undefined' || username == null || username == '') {
    129         errorMsg = "Please provide valid username";
     131        errorMsg = "Please provide valid username to connect to eShipper";
    130132        show_error_msg();
    131133        resize_activation_tb_window();
    132         jQuery('#eshipper_message p').text(errorMsg);
     134        jQuery('#eshipper_message .msg').html(errorMsg);
    133135        return false;
    134136    } else if (password == 'undefined' || password == null || password == '') {
    135         errorMsg = "Please provide valid password";
     137        errorMsg = "Please provide valid password to connect to eShipper";
    136138        show_error_msg();
    137139        resize_activation_tb_window();
    138         jQuery('#eshipper_message p').text(errorMsg);
     140        jQuery('#eshipper_message .msg').html(errorMsg);
    139141        return false;
    140142    }
  • eshipper-commerce/trunk/framework/db.php

    r2923508 r2943682  
    2929        PluginHealthHelper::createEshipperPluginHealthTable();
    3030
    31         update_option('eshipper_version', ESHIPPER_VERSION_2_15);
     31        // Shipping address table structure was updated to change 'phone_no' datatype to varchar from int
     32        pluginLifeCycle::createEshipperShippingAddressTable();
     33
     34        update_option('eshipper_version', ESHIPPER_VERSION_LATEST);
    3235    }
    3336
     
    3538        global $wpdb;
    3639        if ($wpdb->has_cap( 'utf8mb4_520' )){
    37            $this->collate = 'DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci';
     40            $this->collate = 'DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci';
    3841        } elseif ($wpdb->has_cap( 'utf8mb4' )){
    3942            $this->collate = 'DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci';
     
    4346        return $this->collate;
    4447    }
    45    
     48
    4649
    4750    /*
    4851     * Return resources
    4952     */
    50     abstract function get_resource($id);
    51    
     53    abstract function get_resource($id);
     54
    5255    /*
    5356     * Date format
  • eshipper-commerce/trunk/framework/lib/admin-settings.js

    r2921864 r2943682  
    413413    })();
    414414
     415    if (window.location.href.includes('eshipper_health')) {
     416        jQuery('.woocommerce-save-button').addClass('es-d-none');
     417    } else if (window.location.href.includes('eshipper_services') || window.location.href.includes('eshipper_settings')) {
     418        jQuery('.woocommerce-save-button').removeClass('es-d-none');
     419    } // else do nothing
     420
     421    jQuery('#eshipper_health_tab').on('click', function (e) {
     422        jQuery('.woocommerce-save-button').addClass('es-d-none');
     423    });
     424
     425    jQuery('#eshipper_settings_tab').on('click', function (e) {
     426        jQuery('.woocommerce-save-button').removeClass('es-d-none');
     427    });
     428
     429    jQuery('#eshipper_services_tab').on('click', function (e) {
     430        jQuery('.woocommerce-save-button').removeClass('es-d-none');
     431    });
     432
     433    jQuery('#es-plugin-health-db-update').on('click', function (e) {
     434        e.preventDefault();
     435        console.log('Attempting to update database to add plugin health table');
     436
     437        jQuery.ajax({
     438            type: "post",
     439            dataType: "json",
     440            url: ajaxurl,
     441            data: {
     442                action: "plugin_health_db_update",
     443            },
     444            success: function (response) {
     445                console.log('Successfully updated database');
     446
     447                jQuery('#es-plugin-health-db-update-message').removeClass('es-d-none').html(
     448                    response.msg + " <br><br><small><code>Reloading the page in 5 seconds... <br>If the page doesn't reload automatically, click <a href='javascript:void(0)' onclick='window.location.reload();'>here</a> </code></small>"
     449                );
     450
     451                (function () {
     452                    setTimeout(function () {
     453                        window.location.reload();
     454                    }, 5000);
     455                })();
     456            },
     457            error: function (response) {
     458                console.log('Failed to update database. Error Response: ');
     459                console.log(response);
     460                jQuery('#es-plugin-health-db-update-message').removeClass('es-d-none').html(response.msg);
     461            }
     462        });
     463    });
     464
    415465    /**
    416466     * Fix health button on click - Calls woocommerce-eshipper.php -> fix_eshipper_plugin()
  • eshipper-commerce/trunk/framework/lib/plugin_health.css

    r2921864 r2943682  
    113113}
    114114
     115.es-row + .es-row {
     116    margin-top: 15px;
     117}
     118
    115119.es-col {
    116120    position: relative;
     
    121125
    122126@media (min-width: 992px) {
     127    .es-col:only-child {
     128        width: 100%;
     129    }
    123130    .es-col {
    124131        float: left;
     
    182189}
    183190
     191.es-text-bold {
     192    font-weight: bold;
     193}
     194
     195.es-text-large {
     196    font-size: larger;
     197}
     198
     199.es-text-small {
     200    font-size: smaller;
     201    line-height: 20px;
     202}
     203
    184204.es-bg-secondary {
    185205    background-color: #31b5c1 !important;
     
    234254.es-box-success {
    235255    border: 2px solid #24ED88;
     256}
     257
     258.es-box-primary {
     259    border: 2px solid #472F92;
    236260}
    237261
  • eshipper-commerce/trunk/framework/plugin.php

    r2923508 r2943682  
    194194            wp_enqueue_script('eshipper-require-postalcode', plugins_url('lib/require-postalcode.js', ESHIPPER_PLUGIN_FILE), ['jquery'], '1.0', true);
    195195            echo '<div id="calc_shipping_postcode_required" class="hidden woocommerce-info" style="display:none">' . __(
    196                 'Zip / Postal Code is required to calculate shipping',
    197                 'woocommerce-eshipper'
    198             ) . '</div>';
     196                    'Zip / Postal Code is required to calculate shipping',
     197                    'woocommerce-eshipper'
     198                ) . '</div>';
    199199        }
    200200
     
    269269        // DB upgrade for version 2.15.1
    270270        $version = get_option('eshipper_version', '1.0');
    271         if (version_compare($version, ESHIPPER_VERSION_2_15, '<')) {
     271        if (version_compare($version, ESHIPPER_VERSION_LATEST, '<')) {
    272272            // Get required files for db upgrade
    273273            if (!class_exists('woocommerce_eshipper_db')) {
  • eshipper-commerce/trunk/framework/shippingmethod.php

    r2923508 r2943682  
    877877            } ?>" id="eshipper_health">
    878878
    879                 <?php $pluginHealth = PluginHealthHelper::getPluginHealth(); ?>
    880 
    881879                <div id="eshipper_health_panel_overlay">
    882880                    <div class="eshipper-preloader">
     
    886884
    887885                <div class="es-row">
    888                     <div class="es-col es_health_font_size">
    889 
    890                         <div class="es_health_check_chart">
    891                             <div class="flex-wrapper">
    892                                 <div class="single-chart">
    893                                     <svg viewBox="0 0 36 36" class="circular-chart blue" id="health-chart">
    894                                         <path class="circle-bg"
    895                                               d="M18 2.0845
     886                    <div class="es-col">
     887                        <div class="es-box es-box-primary">
     888                            <p class="es-text-primary" style="text-align: center">
     889                                <span class="es-text-bold es-text-large">eShipper Plugin Health*</span>
     890                            </p>
     891                            <p>This page visualizes various parameters to help you gauge the health of the eShipper Plugin and it's settings</p>
     892                            <p>The all new eShipper Plugin can now fix issues automatically! You can view, validate & fix most of the issues
     893                                automatically by just clicking the 'Fix' button against the issue item in the 'Health Check' table.
     894                            </p>
     895                            <p><b>Now you can also validate plugin settings!</b> When you make any changes to eShipper's settings, you can validate
     896                                them by clicking on the 'Verify' button against the related health item and wait for the result. If anything goes
     897                                wrong, use the 'Fix' button! You can also use this feature to validate any future updates to the eShipper Plugin.
     898                            </p>
     899                            <p><b>NOTE: While this page covers most of the common issues that usually occur in the plugin as observed on many
     900                                    stores like yours, it should be noted that this is not a comprehensive list and some issues are specific to your
     901                                    WordPress installation which would need manual resolution. For any such issues, please contact <em>eShipper
     902                                        Support</em>.</b>
     903                            </p>
     904                        </div>
     905                        <hr>
     906                    </div>
     907                </div>
     908
     909                <?php
     910                // Enable Plugin Health feature only on PHP v8.0
     911                $validPhpVersion = false;
     912        if (version_compare(phpversion(), '8.0', '<')) {
     913            $pluginHealth = null;
     914        } else {
     915            $validPhpVersion = true;
     916            $pluginHealth = PluginHealthHelper::getPluginHealth();
     917        }
     918        ?>
     919
     920                <?php if (empty($pluginHealth)) {
     921                    // This will be executed when the plugin health table does not exist in the db
     922                    // Show the user an option to update db, if for any reason table could not be created during install/update.
     923                    ?>
     924                    <div class="es-row">
     925                        <div class="es-col">
     926                            <div class="es-box es-box-danger">
     927                                <p>
     928                                    <span class="es-text-danger es-text-bold">Action Required: </span>
     929                                    <br>
     930                                    <?php if ($validPhpVersion) { ?>
     931                                        <span>To view this page, a database update is required. Please click the button below to run the
     932                                        update.</span>
     933                                    <?php } else { ?>
     934                                        To view this page, minimum required version of PHP is 8.0
     935                                        <br>Your site is currently running on PHP version - <span class="es-text-danger"><?= phpversion(); ?></span>
     936                                        <br>Upgrade your PHP version to experience the latest features.
     937                                    <?php } ?>
     938                                </p>
     939                                <p class="es-text-primary"><b>Don't worry if you are not able to view this page properly, this does NOT affect any
     940                                        eShipper services on your store!</b></p>
     941
     942                                <?php if ($validPhpVersion) { ?>
     943                                    <button class='es-button es-button-primary' id="es-plugin-health-db-update">Update Database</button>
     944                                    <p class="es-d-none" id="es-plugin-health-db-update-message"></p>
     945                                <?php } ?>
     946
     947                            </div>
     948                        </div>
     949                    </div>
     950                <?php } else {
     951                    // If table exists, then show the plugin health page.
     952                    // (dev note: closing tag for else is below the following div)
     953                    ?>
     954
     955                    <div class="es-row">
     956                        <div class="es-col es_health_font_size">
     957
     958                            <div class="es_health_check_chart">
     959                                <div class="flex-wrapper">
     960                                    <div class="single-chart">
     961                                        <svg viewBox="0 0 36 36" class="circular-chart blue" id="health-chart">
     962                                            <path class="circle-bg"
     963                                                  d="M18 2.0845
    896964          a 15.9155 15.9155 0 0 1 0 31.831
    897965          a 15.9155 15.9155 0 0 1 0 -31.831"
    898                                         />
    899                                         <path class="circle"
    900                                               stroke-dasharray="<?php echo $pluginHealth['percentage_health'] ?>, 100"
    901                                               d="M18 2.0845
     966                                            />
     967                                            <path class="circle"
     968                                                  stroke-dasharray="<?php echo $pluginHealth['percentage_health'] ?>, 100"
     969                                                  d="M18 2.0845
    902970          a 15.9155 15.9155 0 0 1 0 31.831
    903971          a 15.9155 15.9155 0 0 1 0 -31.831"
    904                                         />
    905                                         <text x="18" y="20.35" class="percentage"><?php echo $pluginHealth['percentage_health'] . '%' ?></text>
    906                                     </svg>
     972                                            />
     973                                            <text x="18" y="20.35" class="percentage"><?php echo $pluginHealth['percentage_health'] . '%' ?></text>
     974                                        </svg>
     975                                    </div>
    907976                                </div>
    908977                            </div>
     978
     979                            <div class="es-row">
     980                                <div class="es-col">
     981                                    <h3>eShipper Plugin Status: <span id="plugin-stats-status"><?php echo $pluginHealth['status']; ?></span>
     982                                    </h3>
     983
     984                                    <p>
     985                                        <b>Issues found: </b> <span id="plugin-stats-issue-count"><?php echo $pluginHealth['issue_count'] ?></span>
     986                                    </p>
     987
     988                                    <p>
     989                                        <b>Last updated at: </b> <span
     990                                            id="plugin-stats-updated-time"><?php echo $pluginHealth['updated_time']; ?></span>
     991                                    </p>
     992                                </div>
     993                                <div class="es-col">
     994                                    <button class='es-button es-button-primary' onclick="window.location.reload();">Recheck</button>
     995                                </div>
     996                            </div>
     997
     998                            <?php if (!empty($pluginHealth['notice'])) { ?>
     999                                <div class="es-box es-box-danger" id="health-action-notice">
     1000                                    <p>
     1001                                        <span class="es-text-danger es-text-bold">Action Required: </span>
     1002                                        <span id="health-action-message"><?php echo $pluginHealth['notice']; ?></span>
     1003                                    </p>
     1004                                </div>
     1005                            <?php } ?>
     1006                            <div class="es-box es-box-success" style="display: none;" id="fix-success-message"></div>
    9091007                        </div>
    9101008
    911                         <div class="es-row">
    912                             <div class="es-col">
    913                                 <h3>eShipper Plugin Status: <span id="plugin-stats-status"><?php echo $pluginHealth['status']; ?></span>
    914                                 </h3>
    915 
    916                                 <p>
    917                                     <b>Issues found: </b> <span id="plugin-stats-issue-count"><?php echo $pluginHealth['issue_count'] ?></span>
    918                                 </p>
    919 
    920                                 <p>
    921                                     <b>Last updated at: </b> <span id="plugin-stats-updated-time"><?php echo $pluginHealth['updated_time']; ?></span>
    922                                 </p>
    923                             </div>
    924                             <div class="es-col">
    925                                 <button class='es-button es-button-primary' onclick="window.location.reload();">Recheck</button>
    926                             </div>
    927                         </div>
    928 
    929                         <?php if (!empty($pluginHealth['notice'])) { ?>
    930                             <div class="es-box es-box-danger" id="health-action-notice">
    931                                 <p>
    932                                     <span class="es-text-danger es-text-bold">Action Required: </span>
    933                                     <span id="health-action-message"><?php echo $pluginHealth['notice']; ?></span>
    934                                 </p>
    935                             </div>
    936                         <?php } ?>
    937                         <div class="es-box es-box-success" style="display: none;" id="fix-success-message"></div>
    938                     </div>
    939 
    940                     <div class="es-col">
    941                         <table class="es_health_table">
    942                             <thead>
    943                             <tr>
    944                                 <th colspan="2">Health Check</th>
    945                                 <th style="text-align: center">Status</th>
    946                                 <th style="text-align: center">Action</th>
    947                             </tr>
    948                             </thead>
    949                             <tbody>
    950                             <?php
    951                             $validAuth = $pluginHealth['items'][PluginHealthHelper::ATTR_AUTH];
    952         foreach ($pluginHealth['items'] as $item => $health) {
    953             $name = PluginHealthHelper::getDisplayName($item);
    954 
    955             // Insert trigger for auth dialog (this will only be done for auth FIX button)
    956             $auth = $item === PluginHealthHelper::ATTR_AUTH && !$validAuth ? "onclick='show_login_popup()'" : "";
    957 
    958             // When Auth is NOT working, all other buttons except FIX button for Auth, will be disabled.
    959             $disabled = $item !== PluginHealthHelper::ATTR_AUTH && !$validAuth ? "disabled title='Please fix Authentication!'" : "";
    960 
    961             $loaderUrl = ESHIPPER_PLUGIN_URL . '/img/preloader.gif';
    962             $loader = "<div class='fix-loader-icon es-d-none' id='$item-fix-loader'>
     1009                        <div class="es-col">
     1010                            <table class="es_health_table">
     1011                                <thead>
     1012                                <tr>
     1013                                    <th colspan="2">Health Check</th>
     1014                                    <th style="text-align: center">Status</th>
     1015                                    <th style="text-align: center">Action</th>
     1016                                </tr>
     1017                                </thead>
     1018                                <tbody>
     1019                                <?php
     1020                                $validAuth = $pluginHealth['items'][PluginHealthHelper::ATTR_AUTH];
     1021                    foreach ($pluginHealth['items'] as $item => $health) {
     1022                        $name = PluginHealthHelper::getDisplayName($item);
     1023
     1024                        // Insert trigger for auth dialog (this will only be done for auth FIX button)
     1025                        $auth = $item === PluginHealthHelper::ATTR_AUTH && !$validAuth ? "onclick='show_login_popup()'" : "";
     1026
     1027                        // When Auth is NOT working, all other buttons except FIX button for Auth, will be disabled.
     1028                        $disabled = $item !== PluginHealthHelper::ATTR_AUTH && !$validAuth ? "disabled title='Please fix Authentication!'" : "";
     1029
     1030                        $loaderUrl = ESHIPPER_PLUGIN_URL . '/img/preloader.gif';
     1031                        $loader = "<div class='fix-loader-icon es-d-none' id='$item-fix-loader'>
    9631032                                                <img src='$loaderUrl' alt='Please wait...'>
    9641033                                            </div>";
    9651034
    966             // Health item status is OK
    967             if ($health) {
    968                 $icon = "<span class='es-text-success' id='$item-status'>OK</span>";
    969                 // If these items are OK, no action is required
    970                 if ($item === PluginHealthHelper::ATTR_AUTH) {
    971                     $action = "";
    972                 } else {
    973                     $action = "<button class='es-button es-button-primary fix-health-btn' $disabled $auth data-issue='$item' data-type='verify'>
     1035                        // Health item status is OK
     1036                        if ($health) {
     1037                            $icon = "<span class='es-text-success' id='$item-status'>OK</span>";
     1038                            // If these items are OK, no action is required
     1039                            if ($item === PluginHealthHelper::ATTR_AUTH) {
     1040                                $action = "";
     1041                            } else {
     1042                                $action = "<button class='es-button es-button-primary fix-health-btn' $disabled $auth data-issue='$item' data-type='verify'>
    9741043                                    <span class='btn-text'>Verify</span>
    9751044                                    $loader
    9761045                               </button>";
    977                 }
    978             } else {
    979                 $icon = "<span class='es-text-danger' id='$item-status'>X</span>";
    980 
    981                 // If these items are NOT OK, only re-install can fix the problem, hence just display 'Re-install'
    982                 if ($item === PluginHealthHelper::ATTR_BACKEND_SYNC) {
    983                     if (!$validAuth) {
    984                         $action = "";
    985                     } else {
    986                         $action = "Re-install";
    987                     }
    988                 } else {
    989                     $action = "<button class='es-button es-button-danger fix-health-btn' $disabled $auth data-issue='$item' data-type='fix'>
     1046                            }
     1047                        } else {
     1048                            $icon = "<span class='es-text-danger' id='$item-status'>X</span>";
     1049
     1050                            // If these items are NOT OK, only re-install can fix the problem, hence just display 'Re-install'
     1051                            if ($item === PluginHealthHelper::ATTR_BACKEND_SYNC) {
     1052                                if (!$validAuth) {
     1053                                    $action = "";
     1054                                } else {
     1055                                    $action = "Re-install";
     1056                                }
     1057                            } else {
     1058                                $action = "<button class='es-button es-button-danger fix-health-btn' $disabled $auth data-issue='$item' data-type='fix'>
    9901059                                <span class='btn-text'>Fix</span>
    9911060                                $loader
    9921061                                </button>";
    993                 }
    994             }
    995 
    996             echo "
     1062                            }
     1063                        }
     1064
     1065                        echo "
    9971066                                    <tr>
    9981067                                        <td colspan='2'>$name</td>
     
    10011070                                    </tr>
    10021071                                    ";
    1003         }
    1004         ?>
    1005                             </tbody>
    1006                         </table>
     1072                    }
     1073                    ?>
     1074                                </tbody>
     1075                            </table>
     1076                        </div>
     1077                    </div>
     1078
     1079                <?php } ?>
     1080
     1081                <div class="es-row" style="margin-top: 50px">
     1082                    <div class="es-col">
     1083                        <hr>
     1084                        <p>
     1085                            <small>
     1086                                * This page is only a visual representation of the eShipper plugin's health and is only meant for reporting purposes.
     1087                                <b> * If you are not able to view this page, it does NOT affect any eShipper services on your store.</b> *
     1088                                To view this page, minimum required PHP
     1089                                version is 8.0
     1090                            </small>
     1091                        </p>
    10071092                    </div>
    10081093                </div>
    1009 
    10101094            </div>
    10111095
  • eshipper-commerce/trunk/plugin/PluginHealthHelper.php

    r2921864 r2943682  
    4646    public static function createEshipperPluginHealthTable()
    4747    {
    48         global $wpdb;
    4948        $table = self::getPluginHealthTableName();
    5049
     50        // TODO: This will be removed in the upcoming versions since this is not required because dbDelta() takes care of this action.
    5151        // Drop table if already exists
    52         if ($wpdb->get_var("SHOW TABLES LIKE '$table'") === $table) {
    53             $wpdb->query("DROP TABLE $table");
    54         }
     52//        if ($wpdb->get_var("SHOW TABLES LIKE '$table'") === $table) {
     53//            $wpdb->query("DROP TABLE $table");
     54//        }
    5555
    5656        $columns = '';
    57         foreach (self::getEnabledAttributes() as $attribute) {
    58             $columns .= $attribute . ' tinyint(1) DEFAULT 0,';
    59         }
    60 
    61         $create_plugin_health_table = " CREATE TABLE $table(
     57        foreach (self::getEnabledAttributes() as $index => $attribute) {
     58            // Add a new line for every column (as per wordpress doc here: https://codex.wordpress.org/Creating_Tables_with_Plugins#Creating_or_Updating_the_Table)
     59            // DO NOT REMOVE the formatting below:
     60            $columns .= '
     61            ' . $attribute . ' tinyint(1) DEFAULT 0,';
     62        }
     63
     64        $create_plugin_health_table = "CREATE TABLE $table(
    6265            $columns
    6366            created_time timestamp DEFAULT CURRENT_TIMESTAMP,
     
    131134
    132135    /**
    133      * @return array
     136     * @return array|null
    134137     */
    135138    public static function getPluginHealth($asyncRequest = false)
     
    137140        // Get the table name
    138141        global $wpdb;
    139         $table = self::getPluginHealthTableName();
     142
     143        // This also checks and creates the table if it doesn't exist in the db
     144        $table = self::getPluginHealthTableName(true);
    140145
    141146        // First update the plugin health
     
    148153        // Get the items & their respective status from health table
    149154        $healthItems = $wpdb->get_row("SELECT * from $table", ARRAY_A);
     155
     156        // If there are no items populated in the db, return null
     157        if (empty($healthItems)) {
     158            return null;
     159        }
    150160
    151161        // Filter out items to be displayed
     
    276286        $domainUrl = $wpdb->get_var("SELECT domain_url FROM {$wpdb->prefix}eshipper_access_tokens WHERE currently_active = 1");
    277287
     288        // If domain is empty, no further action - mark auth as false
     289//        if (empty($domainUrl)) {
     290//            return self::recordAuthStatus(false);
     291//        }
     292
     293        // Check in real time if store is connected: Upcoming version
     294//        $storeConnected = eshipperCalls::checkIfStoreIsConnected($domainUrl);
     295
    278296        return self::recordAuthStatus(!empty($domainUrl));
    279297    }
     
    508526
    509527    /**
    510      * @return string
    511      */
    512     private static function getPluginHealthTableName()
    513     {
    514         global $wpdb;
    515 
    516         return $wpdb->prefix . self::TABLE_NAME;
     528     * @param $createTableIfDoesntExist
     529     * @return string|null
     530     */
     531    private static function getPluginHealthTableName(bool $createTableIfDoesntExist = false)
     532    {
     533        global $wpdb;
     534
     535        $table = $wpdb->prefix . self::TABLE_NAME;
     536
     537        // Check if the plugin health table exists and create if it doesn't
     538        if ($createTableIfDoesntExist && $wpdb->get_var("SHOW TABLES LIKE '$table'") !== $table) {
     539            self::createEshipperPluginHealthTable();
     540        }
     541
     542        return $table;
    517543    }
    518544}
  • eshipper-commerce/trunk/plugin/eshipperCalls.php

    r2921864 r2943682  
    205205
    206206        $httpResponseCode = $response['httpResponseCode'];
    207         $error_message = $response['response']->errors;
     207        $error_message = isset($response['response']->errors) ? $response['response']->errors : 'Something went wrong! Please contact support.';
    208208
    209209        //if the response code is 200 then create tables and what not
     
    233233        return $responseArray;
    234234    }
     235
     236    /**
     237     * Check if store is connected by invoking eShipper API
     238     * @param $domainUrl
     239     * @return bool
     240     */
     241    public static function checkIfStoreIsConnected($domainUrl)
     242    {
     243        // Get the store domain name
     244        $shopName = trim(str_replace('/shop', '', get_site_url()));
     245        $shopName = rtrim(preg_replace("#^[^:/.]*[:/]+#i", "", $shopName), '/');
     246
     247        // Call the eShipper API to check if this store is installed
     248        $response = (new curlHandler())->sendCurlRequest(
     249            json_encode(['shop' => $shopName]),
     250            "$domainUrl/ecommerce/woocommerce/is-store-installed",
     251            'POST',
     252            [
     253                'Accept: application/json',
     254                'Content-Type: application/json',
     255            ]
     256        );
     257
     258        // If the response is 200 then return true
     259        if (!empty($response['response']) && !empty($httpResponseCode = $response['httpResponseCode']) && $httpResponseCode === 200) {
     260            return true;
     261        }
     262
     263        // If response is not 200 return false
     264        return false;
     265    }
    235266}
  • eshipper-commerce/trunk/plugin/pluginLifeCycle.php

    r2923508 r2943682  
    146146
    147147        // Drop table if already exists
    148         if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_boxing_services_master'") === $eshipper_boxing_services_master) {
    149             $wpdb->query("DROP TABLE $eshipper_boxing_services_master");
    150         }
     148//        if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_boxing_services_master'") === $eshipper_boxing_services_master) {
     149//            $wpdb->query("DROP TABLE $eshipper_boxing_services_master");
     150//        }
    151151
    152152        $create_boxing_master_table_query = " CREATE TABLE $eshipper_boxing_services_master(
     
    171171    private static function createEshipperAccessTokensTable()
    172172    {
     173        wc_get_logger()->debug('Attempting to create table - eshipper_access_tokens', ['source' => 'eshipper']);
     174
    173175        global $wpdb;
    174176        $eshipper_access_tokens = $wpdb->prefix . "eshipper_access_tokens";
    175177
    176178        // Drop table if already exists
    177         if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_access_tokens'") === $eshipper_access_tokens) {
    178             $wpdb->query("DROP TABLE $eshipper_access_tokens");
    179         }
     179        // Not required - dbDelta() takes care of that
     180//        if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_access_tokens'") === $eshipper_access_tokens) {
     181//            $wpdb->query("DROP TABLE $eshipper_access_tokens");
     182//        }
    180183
    181184        $access_tokens_query = " CREATE TABLE $eshipper_access_tokens(
     
    192195        require_once(ABSPATH . "wp-admin/includes/upgrade.php");
    193196        dbDelta($access_tokens_query);
     197
     198        wc_get_logger()->debug('Successfully to create table - eshipper_access_tokens', ['source' => 'eshipper']);
    194199    }
    195200
     
    201206    private static function createEshipperCarrierServicesTable()
    202207    {
     208        wc_get_logger()->debug('Attempting to create table - eshipper_carrier_service_master', ['source' => 'eshipper']);
     209
    203210        global $wpdb;
    204211        $eshipper_carrier_services = $wpdb->prefix . "eshipper_carrier_service_master";
    205212
    206213        // Drop table if already exists
    207         if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_carrier_services'") === $eshipper_carrier_services) {
    208             $wpdb->query("DROP TABLE $eshipper_carrier_services");
    209         }
     214//        if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_carrier_services'") === $eshipper_carrier_services) {
     215//            $wpdb->query("DROP TABLE $eshipper_carrier_services");
     216//        }
    210217
    211218        $access_tokens_query = " CREATE TABLE $eshipper_carrier_services(
     
    259266            $status = PluginHealthHelper::recordAuthStatus(true);
    260267        } catch (Exception $exception) {
    261             wc_get_logger()->debug(
     268            wc_get_logger()->error(
    262269                'Error while storing eshipper access token in DB - [ERROR] - ' . print_r($exception->getMessage(), true),
    263270                ['source' => 'eshipper']
     
    297304            $status = PluginHealthHelper::recordStoreAddressStatus(true);
    298305        } catch (Exception $exception) {
    299             wc_get_logger()->debug(
     306            wc_get_logger()->error(
    300307                'Error while copying store address from woocommerce - [ERROR] - ' . print_r($exception->getMessage(), true),
    301308                ['source' => 'eshipper']
     
    434441            $status = PluginHealthHelper::recordWebhooksStatus(true);
    435442        } catch (Exception $exception) {
    436             wc_get_logger()->debug('Error while creating webhooks. - [ERROR] - ' . print_r($exception->getMessage(), true), ['source' => 'eshipper']);
     443            wc_get_logger()->error('Error while creating webhooks. - [ERROR] - ' . print_r($exception->getMessage(), true), ['source' => 'eshipper']);
    437444
    438445            $status = PluginHealthHelper::recordWebhooksStatus(false);
     
    485492     * Function to create table in Woo-Commerce DB to store the Shipping Address
    486493     */
    487     private static function createEshipperShippingAddressTable()
     494    public static function createEshipperShippingAddressTable()
    488495    {
    489496        global $wpdb;
     
    491498
    492499        // Drop table if already exists
    493         if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_shipping_address'") === $eshipper_shipping_address) {
    494             $wpdb->query("DROP TABLE $eshipper_shipping_address");
    495         }
     500//        if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_shipping_address'") === $eshipper_shipping_address) {
     501//            $wpdb->query("DROP TABLE $eshipper_shipping_address");
     502//        }
    496503
    497504        $create_shipping_address_query = " CREATE TABLE $eshipper_shipping_address(
     
    505512            zipcode varchar(255) ,
    506513            shipping_name text ,
    507             phone_no int(14) ,
     514            phone_no varchar(20) ,
    508515            email_id varchar (255),
    509516            created_time timestamp DEFAULT CURRENT_TIMESTAMP,
     
    560567            $status = PluginHealthHelper::recordCarrierServicesStatus(true);
    561568        } catch (Exception $exception) {
    562             wc_get_logger()->debug(
     569            wc_get_logger()->error(
    563570                'Error while adding eshipper carrier services - [ERROR] - ' . print_r($exception->getMessage(), true),
    564571                ['source' => 'eshipper']
  • eshipper-commerce/trunk/readme.txt

    r2923520 r2943682  
    55Tested up to: 6.2.2
    66Requires PHP: 7.1
    7 Stable tag: 2.15.2
     7Stable tag: 2.15.3
    88License: GPLv3
    99License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    5454
    5555== Changelog ==
     56= 2.15.3 =
     57* Critical Bug Fixes for versions 2.14.3 & v2.15.2
     58
    5659= 2.15.2 =
    5760* Critical bug fixes & better user experience
     
    8285
    8386== Upgrade Notice ==
     87= 2.15.3 =
     88Upgrade to receive critical bug fixes NOW!
     89
    8490= 2.15.2 =
    8591Recommended upgrade for critical bug fixes in versions 2.15 & 2.15.1
  • eshipper-commerce/trunk/views/login_thickbox.php

    r2921864 r2943682  
    9191                        <div class="col-75">
    9292                            <input class="es_input_class" type="text" id="domain_url" name="domain_url" placeholder="https://domain_name.com" value="https://ww2.eshipper.com">
     93                            <small>This should be a valid eShipper domain.</small>
    9394                        </div>
    9495                    </div>
     
    99100                        <div class="col-75">
    100101                            <input class="es_input_class" type="text" id="username" name="username" placeholder="Username">
     102                            <small>Enter your eShipper username to connect the plugin to eShipper services.</small>
    101103                        </div>
    102104                    </div>
     
    109111                            <input type="hidden" name="grant_type" value="password">
    110112                            <input type="hidden" name="client_id" value="web_app">
     113                            <small>Enter your eShipper password to connect the plugin to eShipper services.</small>
    111114                        </div>
    112115                    </div>
  • eshipper-commerce/trunk/woocommerce-eshipper.php

    r2923508 r2943682  
    44    Plugin URI: https://ww2.eshipper.com/ecommerce/
    55    Description: Extends WooCommerce with Shipping Rates from eShipper
    6     Version: 2.15.2
     6    Version: 2.15.3
    77    Author: eShipper
    88    Author URI: https://ww2.eshipper.com/
     
    2929))) {
    3030    define('ESHIPPER_VERSION', '1.4.1');
    31     define('ESHIPPER_VERSION_2_15', '2.15.2');
     31    define('ESHIPPER_VERSION_LATEST', '2.15.3');
    3232    //Plugin Path
    3333    define('ESHIPPER_PLUGIN_PATH', dirname(__FILE__));
     
    154154    add_action('wp_ajax_boxing_insert', 'boxing_insert');
    155155    add_action('wp_ajax_fix_eshipper_plugin', 'fix_eshipper_plugin');
     156    add_action('wp_ajax_plugin_health_db_update', 'plugin_health_db_update');
    156157
    157158    function fix_eshipper_plugin()
     
    254255    }
    255256
     257    function plugin_health_db_update()
     258    {
     259        $update = false;
     260        try {
     261            // Log the activity
     262            wc_get_logger()->debug('Attempting to create plugin health table', ['source' => 'eshipper']);
     263
     264            // Attempt to create plugin health table
     265            $update = PluginHealthHelper::createEshipperPluginHealthTable();
     266        } catch (Exception $e) {
     267            wc_get_logger()->error(
     268                'ERROR creating plugin health table: [CODE]: ' . $e->getCode() . ' [ERROR] - ' . print_r($e->getMessage(), true),
     269                ['source' => 'eshipper']
     270            );
     271        }
     272
     273        if ($update) {
     274            $statusCode = 200;
     275            $msg = 'Database Update is successful!';
     276
     277            wc_get_logger()->debug('Successfully created plugin health table.', ['source' => 'eshipper']);
     278
     279            // Validate Plugin health to populate current state of the plugin
     280            PluginHealthHelper::validatePluginHealth();
     281        } else {
     282            $statusCode = 412;
     283            $msg = 'Could not update database, something went wrong while processing your request. Please contact support to fix the issue.';
     284
     285            wc_get_logger()->error('Failed to create plugin health table.', ['source' => 'eshipper']);
     286        }
     287
     288        $result = [
     289            'statusCode' => $statusCode,
     290            'msg' => $msg,
     291        ];
     292
     293        // Return Error Response
     294        echo json_encode($result);
     295        die();
     296    }
     297
    256298    function eshipper_health_check_admin_notice()
    257299    {
     
    329371            'methods' => 'DELETE',
    330372            'callback' => 'uninstallEshipperPlugin',
     373            'permission_callback' => '__return_true',
    331374        ]);
    332375    });
     
    334377    function uninstallEshipperPlugin($request)
    335378    {
     379        wc_get_logger()->debug('Attempting to deactivate eShipper plugin. Store was detached from eShipper', ['source' => 'eshipper']);
    336380        $all_headers = $request->get_headers();
    337381
     
    340384            $responseArray = ['statusCode' => "401", "msg" => "Sorry, you are not authorized to do this event"];
    341385
     386            wc_get_logger()->error('Failed to deactivate eShipper plugin', ['source' => 'eshipper']);
     387
    342388            return new WP_REST_Response($responseArray, 401);
    343389        }
    344390
    345         $plugin = 'eShipper-plugin/woocommerce-eshipper.php';
    346         deactivate_plugins($plugin);
    347         $responseArray = ['statusCode' => "200", "msg" => "eShipper plugin uninstalled successfully"];
    348 
    349         return new WP_REST_Response($responseArray, 200);
     391        // Deactivate the plugin
     392        require_once(ABSPATH . 'wp-admin/includes/plugin.php');
     393        deactivate_plugins(ESHIPPER_PLUGIN_PATH);
     394
     395        // If the plugin is still active at this point then return error
     396        if (is_plugin_active(plugin_basename(ESHIPPER_PLUGIN_FILE))) {
     397            wc_get_logger()->error('Failed to deactivate eShipper plugin. Please deactivate the plugin directly from your store.', ['source' => 'eshipper']);
     398
     399            $responseArray = [
     400                'statusCode' => "412",
     401                "msg" => "Failed to deactivate eShipper plugin. Please deactivate the plugin directly from your store.",
     402            ];
     403            return new WP_REST_Response($responseArray, 412);
     404        } else {
     405            wc_get_logger()->debug('eShipper plugin deactivated successfully. Good bye!', ['source' => 'eshipper']);
     406
     407            $responseArray = [
     408                'statusCode' => "200",
     409                "msg" => "eShipper plugin deactivated successfully!",
     410            ];
     411            return new WP_REST_Response($responseArray, 200);
     412        }
    350413    }
    351414
     
    582645        $validateParameters = 1;
    583646        $requestData = [];
     647        $msg = '';
    584648        if (isset($_POST['formdata']) && is_array($_POST['formdata'])) {
    585649            foreach ($_POST['formdata'] as $k => $formdata) {
     
    589653                    break;
    590654                }
     655
     656                // Validate eShipper's domain (this check is also applied in js hence the code below is a fail safe)
     657                if ($formdata['name'] === 'domain_url' && !str_contains($formdata['value'], 'eshipper.com')) {
     658                    $validateParameters = 0;
     659                    $msg = 'Invalid Domain URL. Please enter the correct eshipper domain';
     660                    break;
     661                }
     662
    591663                $key = $formdata['name'];
    592664                $val = $formdata['value'];
     
    599671            echo json_encode([
    600672                'statusCode' => 412,
    601                 'msg' => 'The credentials you entered are incorrect. Please provide correct data.',
     673                'msg' => $msg ?? 'The credentials you entered are incorrect. Please provide correct data.',
    602674            ]);
    603675            die();
Note: See TracChangeset for help on using the changeset viewer.