bitpay / bitpay-checkout-for-woocommerce

BitPay Checkout for WooCommerce
MIT License
14 stars 22 forks source link

Settings page error on clean install (version 5.3.2) #79

Closed shaunek-hero closed 3 months ago

shaunek-hero commented 4 months ago

I installed the plugin in our prod environment for the first time and immediately noticed a fatal error with the plugin when I tried to visit the settings page for the first time.

From the user's perspective the Woocommerce > Settings > Payment > BitPay Checkout for WooCommerce 5.3.2 page doesn't load the content (the Wordpress admin loads partially, just not the settings fields). Looking into chrome dev tools I could see that there was a 500 error and when I inspected the error log I see this:

2024-02-26T19:01:20+00:00 CRITICAL Uncaught TypeError: strtoupper(): Argument #1 ($string) must be of type string, null given in /home/myuser/public_html/wp-content/plugins/bitpay-checkout-for-woocommerce/build/BitPayLib/class-bitpaypaymentsettings.php:91
Stack trace:
#0 /home/myuser/public_html/wp-content/plugins/bitpay-checkout-for-woocommerce/build/BitPayLib/class-bitpaypaymentsettings.php(91): strtoupper()
#1 /home/myuser/public_html/wp-content/plugins/bitpay-checkout-for-woocommerce/build/BitPayLib/class-bitpaypluginsetup.php(64): BitPayVendor\BitPayLib\BitPayPaymentSettings->check_token()
#2 /home/myuser/public_html/wp-includes/class-wp-hook.php(324): BitPayVendor\BitPayLib\BitPayPluginSetup->bitpay_checkout_check_token()
#3 /home/myuser/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()
#4 /home/myuser/public_html/wp-includes/plugin.php(517): WP_Hook->do_action()
#5 /home/myuser/public_html/wp-admin/admin-header.php(303): do_action()
#6 /home/myuser/public_html/wp-admin/admin.php(239): require_once('/home/myuser...')
#7 {main}
  thrown in /home/myuser/public_html/wp-content/plugins/bitpay-checkout-for-woocommerce/build/BitPayLib/class-bitpaypaymentsettings.php on line 91

As a temporary workaround I commented out lines 91 & 92 of class-bitpaypaymentsettings.php which is the inside part of this if-statement:

        $bitpay_checkout_endpoint = $this->get_bitpay_gateway_setting('bitpay_checkout_endpoint');
        if (!$bitpay_checkout_token) {
            $message = 'There is no token set for your ' . \strtoupper($bitpay_checkout_endpoint) . ' environment. BitPay will not function if this is not set.';
            \WC_Admin_Settings::add_error($message);
        }

Then I was able to load the settings page and save my settings. Afterwards I uncommented those lines and the page continued to work okay.

So this problem is really only for fresh installs where a user has never saved the settings for this plugin before. I checked the master branch and I believe this is still an issue there as well. This bug isn't urgent for me since I figured out a workaround, but I'm reporting it so that your other user's can have a better experience.

p-maguire commented 4 months ago

@shaunek-hero Thanks for reporting this issue! We've created a Story to fix it after replicating it on our end.

p-maguire commented 4 months ago

@shaunek-hero We've attempted to replicate this issue on a few clean installs, and have been unsuccessful. Upon installation of the plugin, the default value of test should be added to 'bitpay_checkout_endpoint'. Are you able to provide us with the following information so we could attempt to replicate the issue locally?

shaunek-hero commented 4 months ago

Wordpress 6.4.3 Woocommerce 8.4.0 PHP 8.2.15

If it helps I have replicated it again on a test site using a webhosting provider, Cloudways. I am highly doubtful this is Cloudways-specific, but just mentioning these EXACT steps in case you have more trouble replicating locally. Here are the steps I took:

  1. I used Cloudways to create a new "app" - I selected to have it install Woocommerce for me. As of today it offered to install Woocommerce 7.8.2 on WP 6.2.2. Not this is different versions from what I indicated above because above I documented the versions I first experienced this problem with.
  2. Logged into the WP Admin and began setting up Woocommerce by adding one test product and selecting a theme. I doubt this step is necessary, I'm just telling you exactly what I did.
  3. I used the Add Plugin functionality, I searched for "BitPay" and found the plugin listing from the plugin repository and I installed it and activated it. The plugin version installed was 5.3.2. No errors were apparent from the UI so far.
  4. I navigated to Woocommerce > Settings > Payments > Bitpay and the same error I described in my original post happened. I checked the fatal-error log file and found the exact same error message.
  5. I ran a SQL query to find out what was saved in wp_options and here is the result (screenshot below). Not that there is not entry for woocommerce_bitpay_checkout_gateway_settings

Screenshot 2024-02-28 at 11 07 14

I'm not sure what you are doing that is different but if there is any chance that you are reusing a database somehow, I recommend avoiding that. Use a brand new environment where you install just WP+Woo+your plugin.

Hope that helps.

p-maguire commented 4 months ago

@shaunek-hero I've been able to replicate this now, it looks like this issue occurs when you try to access the plugin settings before enabling the payment method itself, inside of the WooCommerce settings. Thanks for the additional information, it was really helpful!