woocommerce / woocommerce-square

Square POS and Payments Integration
https://woo.com/products/square
Other
10 stars 1 forks source link

If cURL is not installed on the server, WooCommerce Square gives a fatal, instead of failing gracefully. #165

Open slash1andy opened 5 days ago

slash1andy commented 5 days ago

Describe the bug

To reproduce

  1. Install the Square plugin on a server without cURL and go through the onboarding.
  2. Upon completion of onboarding, receive fatal error below.

Fatal error: Uncaught Error: Undefined constant "Unirest\CURLAUTH_BASIC" in /var/www/html/wp-content/plugins/woocommerce-square/vendor/apimatic/unirest-php/src/Configuration.php:54 Stack trace: #0 /var/www/html/wp-content/plugins/woocommerce-square/vendor/square/square/src/SquareClient.php(162): Unirest\Configuration::init(Object(Square\SquareClient)) #1 /var/www/html/wp-content/plugins/woocommerce-square/includes/API.php(71): Square\SquareClient->__construct(Array) #2 /var/www/html/wp-content/plugins/woocommerce-square/includes/Plugin.php(689): WooCommerce\Square\API->__construct('EAAAljYyrWz7dhj...', false) #3 /var/www/html/wp-content/plugins/woocommerce-square/includes/Settings.php(791): WooCommerce\Square\Plugin->get_api('EAAAljYyrWz7dhj...', false) #4 /var/www/html/wp-content/plugins/woocommerce-square/includes/Gateway.php(1051): WooCommerce\Square\Settings->get_locations() #5 /var/www/html/wp-includes/class-wp-hook.php(324): WooCommerce\Square\Gateway->filter_available_gateways(Array) #6 /var/www/html/wp-includes/plugin.php(205): WP_Hook->apply_filters(Array, Array) #7 /var/www/html/wp-content/plugins/woocommerce/includes/class-wc-payment-gateways.php(333): apply_filters('woocommerce_ava...', Array) #8 /var/www/html/wp-content/plugins/woocommerce/src/Admin/Features/OnboardingTasks/Tasks/Payments.php(89): WC_Payment_Gateways->get_available_payment_gateways() #9 /var/www/html/wp-content/plugins/woocommerce/src/Admin/Features/OnboardingTasks/Tasks/Payments.php(67): Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\Payments::has_gateways() #10 /var/www/html/wp-content/plugins/woocommerce/src/Admin/Features/OnboardingTasks/Tasks/WooCommercePayments.php(106): Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\Payments->is_complete() #11 /var/www/html/wp-content/plugins/woocommerce/src/Admin/Features/OnboardingTasks/TaskList.php(305): Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\WooCommercePayments->can_view() #12 [internal function]: Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskList->Automattic\WooCommerce\Admin\Features\OnboardingTasks\{closure}(Object(Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\WooCommercePayments)) #13 /var/www/html/wp-content/plugins/woocommerce/src/Admin/Features/OnboardingTasks/TaskList.php(306): array_filter(Array, Object(Closure)) #14 /var/www/html/wp-content/plugins/woocommerce/src/Admin/Features/OnboardingTasks/TaskList.php(240): Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskList->get_viewable_tasks() #15 /var/www/html/wp-content/plugins/woocommerce/src/Admin/Features/OnboardingTasks/TaskLists.php(412): Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskList->is_complete() #16 /var/www/html/wp-content/plugins/woocommerce/src/Admin/Features/OnboardingTasks/TaskLists.php(434): Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists::setup_tasks_remaining() #17 /var/www/html/wp-includes/class-wp-hook.php(324): Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists::menu_task_count('') #18 /var/www/html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) #19 /var/www/html/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #20 /var/www/html/wp-admin/includes/menu.php(161): do_action('admin_menu', '') #21 /var/www/html/wp-admin/menu.php(422): require_once('/var/www/html/w...') #22 /var/www/html/wp-admin/admin.php(158): require('/var/www/html/w...') #23 /var/www/html/wp-admin/index.php(10): require_once('/var/www/html/w...') #24 {main} thrown in /var/www/html/wp-content/plugins/woocommerce-square/vendor/apimatic/unirest-php/src/Configuration.php on line 54

Expected behavior

If cURL is not installed, failing with a banner notice letting them know or similar would be preferred. If this plugin is installed on a server without cURL, it will bring the site down after completing onboarding.

Environment (please complete the following information):

Additional details

This happened on Studio, but we assume this will be replicable on any host without cURL.

dkotter commented 5 days ago

Note that cURL is required as the underlying Square PHP SDK uses that. We have an existing check in place for that, along with a few other dependencies, and this will render an admin notice:

cURL admin notice

In testing though, these admin notices never show in the new onboarding flow so a user is never made aware of this requirement.

I tested the previous version of Square (4.6.3) and while that admin notice shows, we still allow a user to try and connect, which will then throw the same fatal error. So this isn't an entirely new issue but can definitely be handled more gracefully.

I can see two approaches here:

  1. Ensure these admin notices can be seen in the onboarding flow. These can be normal admin notices or we could try and capture those and render them in a way that fits the design of the onboarding a bit better. This would then match previous functionality
  2. Even better though would be to show the notice and stop the connection from happening, both in the onboarding flow and in the main settings page

Note that we should ensure that the above works for all required dependencies, not just cURL