woocommerce / woocommerce-gateway-stripe

The official Stripe Payment Gateway for WooCommerce
https://wordpress.org/plugins/woocommerce-gateway-stripe/
228 stars 201 forks source link

Critical error when cancelling an order while authorize and capture is enabled #3371

Closed thomasjvu closed 2 weeks ago

thomasjvu commented 3 weeks ago

Describe the bug When the "issue an authorization on checkout, and capture later" option is enabled in WooCommerce > Settings > Payments > Stripe > Settings and the merchant attempts to cancel a pre-authorized order, a critical error will occur.

See the Critical Error ``` 2024-08-21T14:57:18+00:00 Critical Uncaught Error: Attempt to modify property "data" on null in /srv/htdocs/wp-content/plugins/woocommerce-gateway-stripe/includes/abstracts/abstract-wc-stripe-payment-gateway.php:1128 Additional context { "error": { "type": 1, "file": "/srv/htdocs/wp-content/plugins/woocommerce-gateway-stripe/includes/abstracts/abstract-wc-stripe-payment-gateway.php", "line": 1128 }, "backtrace": [ "", "#0 /srv/htdocs/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-order-handler.php(346): WC_Stripe_Payment_Gateway->process_refund(201)", "#1 /wordpress/core/6.6.1/wp-includes/class-wp-hook.php(326): WC_Stripe_Order_Handler->cancel_payment(201)", "#2 /wordpress/core/6.6.1/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)", "#3 /wordpress/core/6.6.1/wp-includes/plugin.php(517): WP_Hook->do_action(Array)", "#4 /wordpress/plugins/woocommerce/9.2.1/includes/class-wc-order.php(411): do_action('woocommerce_ord...', 201, Object(Automattic\WooCommerce\Admin\Overrides\Order), Array)", "#5 /wordpress/plugins/woocommerce/9.2.1/includes/class-wc-order.php(253): WC_Order->status_transition()", "#6 /wordpress/plugins/woocommerce/9.2.1/includes/admin/meta-boxes/class-wc-meta-box-order-data.php(768): WC_Order->save()", "#7 /wordpress/core/6.6.1/wp-includes/class-wp-hook.php(326): WC_Meta_Box_Order_Data::save(201)", "#8 /wordpress/core/6.6.1/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)", "#9 /wordpress/core/6.6.1/wp-includes/plugin.php(517): WP_Hook->do_action(Array)", "#10 /wordpress/plugins/woocommerce/9.2.1/src/Internal/Admin/Orders/Edit.php(313): do_action('woocommerce_pro...', 201, Object(Automattic\WooCommerce\Admin\Overrides\Order))", "#11 /wordpress/plugins/woocommerce/9.2.1/src/Internal/Admin/Orders/Edit.php(153): Automattic\WooCommerce\Internal\Admin\Orders\Edit->handle_order_update()", "#12 /wordpress/plugins/woocommerce/9.2.1/src/Internal/Admin/Orders/PageController.php(350): Automattic\WooCommerce\Internal\Admin\Orders\Edit->setup(Object(Automattic\WooCommerce\Admin\Overrides\Order))", "#13 /wordpress/plugins/woocommerce/9.2.1/src/Internal/Admin/Orders/PageController.php(366): Automattic\WooCommerce\Internal\Admin\Orders\PageController->prepare_order_edit_form()", "#14 /wordpress/plugins/woocommerce/9.2.1/src/Internal/Admin/Orders/PageController.php(167): Automattic\WooCommerce\Internal\Admin\Orders\PageController->setup_action_edit_order()", "#15 [internal function]: Automattic\WooCommerce\Internal\Admin\Orders\PageController->handle_load_page_action('')", "#16 /wordpress/plugins/woocommerce/9.2.1/src/Internal/Traits/AccessiblePrivateMethods.php(158): call_user_func_array(Array, Array)", "#17 /wordpress/core/6.6.1/wp-includes/class-wp-hook.php(324): Automattic\WooCommerce\Internal\Admin\Orders\PageController->__call('handle_load_pag...', Array)", "#18 /wordpress/core/6.6.1/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array)", "#19 /wordpress/core/6.6.1/wp-includes/plugin.php(517): WP_Hook->do_action(Array)", "#20 /wordpress/core/6.6.1/wp-admin/admin.php(237): do_action('load-woocommerc...')", "#21 {main}", "thrown" ] } ```

To Reproduce

  1. Go to WooCommerce > Settings > Payments > Stripe > Settings
  2. Enable the "issue an authorization on checkout, and capture later" option
  3. Create a test order and checkout with Stripe.
  4. Go into the order from the admin page and change from On Hold to Cancelled.
  5. A critical error should appear on the site.

Expected behavior Upon going back to the order, you'll see that it has moved to the cancelled status. Authorize & charge orders should be able to be cancelled without encountering that critical error. The functionality works as expected in Stripe v8.4.0.

Screenshots

https://github.com/user-attachments/assets/f20226e8-4119-49b3-bbdf-12fa93353dea

Environment (please complete the following information):

System Status Report ``` ### WordPress Environment ### WordPress address (URL): [Redacted] Site address (URL): [Redacted] WC Version: 9.2.1 Legacy REST API Package Version: The Legacy REST API plugin is not installed on this site. Action Scheduler Version: ✔ 3.8.1 Log Directory Writable: ✔ WP Version: 6.6.1 WP Multisite: – WP Memory Limit: 512 MB WP Debug Mode: – WP Cron: ✔ Language: en_US External object cache: ✔ ### Server Environment ### Server Info: nginx PHP Version: 8.2.22 PHP Post Max Size: 2 GB PHP Time Limit: 1200 PHP Max Input Vars: 6144 cURL Version: 8.7.1 OpenSSL/3.0.13 SUHOSIN Installed: – MySQL Version: 10.6.18-MariaDB-log Max Upload Size: 2 GB Default Timezone is UTC: ✔ fsockopen/cURL: ✔ SoapClient: ✔ DOMDocument: ✔ GZip: ✔ Multibyte String: ✔ Remote Post: ✔ Remote Get: ✔ ### Database ### [REDACTED] ### Post Type Counts ### attachment: 2 page: 8 post: 1 product: 3 product_variation: 7 revision: 8 shop_order_placehold: 51 wp_font_face: 33 wp_font_family: 12 wp_global_styles: 1 wp_navigation: 1 ### Security ### Secure connection (HTTPS): ✔ Hide errors from visitors: ✔ ### Active Plugins (2) ### WooCommerce Stripe Gateway: by WooCommerce – 8.6.1 WooCommerce: by Automattic – 9.2.1 ### Inactive Plugins (11) ### Akismet Anti-spam: Spam Protection: by Automattic - Anti-spam Team – 5.3.3 Jetpack: by Automattic – 13.8-a.3 Jetpack Protect: by Automattic - Jetpack Security team – 3.0.0 Pressable OnePress Login: by Pressable – 1.3.2 Woo Back In Stock Notifications: by Woo – 1.7.2 (update to version 2.0.1 is available) WooCommerce.com Update Manager: by Automattic – 1.0.3 WooCommerce Gateway Affirm: by WooCommerce – 2.4.1 WooCommerce Shipment Tracking: by WooCommerce – 2.5.0 WooCommerce Subscriptions: by WooCommerce – 6.5.0 WooPayments: by WooCommerce – 8.1.0 WP Mail Logging: by WP Mail Logging Team – 1.12.0 ### Dropin Plugins () ### advanced-cache.php: advanced-cache.php object-cache.php: Memcached ### Settings ### Legacy API Enabled: – Force SSL: – Currency: USD ($) Currency Position: left Thousand Separator: , Decimal Separator: . Number of Decimals: 2 Taxonomies: Product Types: external (external) grouped (grouped) simple (simple) subscription (subscription) variable (variable) variable subscription (variable-subscription) Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog) exclude-from-search (exclude-from-search) featured (featured) outofstock (outofstock) rated-1 (rated-1) rated-2 (rated-2) rated-3 (rated-3) rated-4 (rated-4) rated-5 (rated-5) Connected to WooCommerce.com: ✔ Enforce Approved Product Download Directories: ✔ HPOS feature enabled: ✔ Order datastore: Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore HPOS data sync enabled: – ### Logging ### Enabled: ✔ Handler: Automattic\WooCommerce\Internal\Admin\Logging\LogHandlerFileV2 Retention period: 30 days Level threshold: – Log directory size: 1 MB ### WC Pages ### Shop base: #5 - /shop/ Cart: #6 - /cart/ - Contains the woocommerce/cart block Checkout: #7 - /checkout/ - Contains the woocommerce/checkout block My account: #8 - /my-account/ Terms and conditions: ❌ Page not set ### Theme ### Name: Twenty Twenty-Four Version: 1.2 Author URL: https://wordpress.org Child Theme: ❌ – If you are modifying WooCommerce on a parent theme that you did not build personally we recommend using a child theme. See: How to create a child theme WooCommerce Support: ❌ Not declared ### Templates ### Overrides: /wordpress/plugins/woocommerce/9.2.1/templates/block-notices/error.php /wordpress/plugins/woocommerce/9.2.1/templates/block-notices/notice.php /wordpress/plugins/woocommerce/9.2.1/templates/block-notices/success.php ### Admin ### Enabled Features: activity-panels analytics product-block-editor coupons core-profiler customize-store customer-effort-score-tracks import-products-task experimental-fashion-sample-products shipping-smart-defaults shipping-setting-tour homescreen marketing mobile-app-banner navigation onboarding onboarding-tasks pattern-toolkit-full-composability product-custom-fields remote-inbox-notifications remote-free-extensions payment-gateway-suggestions printful shipping-label-banner subscriptions store-alerts transient-notices woo-mobile-welcome wc-pay-promotion wc-pay-welcome-page launch-your-store Disabled Features: experimental-blocks minified-js product-pre-publish-modal settings async-product-editor-category-field product-editor-template-system Daily Cron: ✔ Next scheduled: 2024-08-22 13:41:13 +00:00 Options: ✔ Notes: 71 Onboarding: skipped ### Action Scheduler ### Complete: 129 Oldest: 2024-07-22 13:25:19 +0000 Newest: 2024-08-21 15:00:02 +0000 Failed: 9 Oldest: 2024-07-16 14:04:33 +0000 Newest: 2024-08-21 14:51:46 +0000 Pending: 2 Oldest: 2024-08-22 14:51:46 +0000 Newest: 2024-10-19 17:46:58 +0000 ### Status report information ### Generated at: 2024-08-21 15:05:58 +00:00 ```

Additional context Downgrading to v8.4.0 of Stripe resolves the issue.

carolframen commented 3 weeks ago

Also reported on this thread: https://wordpress.org/support/topic/php-fatal-error-on-switch-order-to-cancelled-status/ I was able to replicate the issue on my website too