diff --git a/woocommerce/changelog.txt b/woocommerce/changelog.txt index 335eefe75..73a1bf164 100644 --- a/woocommerce/changelog.txt +++ b/woocommerce/changelog.txt @@ -1,6 +1,7 @@ *** SkyVerge WooCommerce Plugin Framework Changelog *** 2026.nn.nn - version 6.2.2 +* Fix - Failed transaction attempt causes future attempts to fail when using Block checkout 2026.05.18 - version 6.2.1 * Fix - Protect against `ScriptHelper` fatal errors on plugin upgrades diff --git a/woocommerce/payment-gateway/class-sv-wc-payment-gateway.php b/woocommerce/payment-gateway/class-sv-wc-payment-gateway.php index ebc1a0712..99a823cd7 100755 --- a/woocommerce/payment-gateway/class-sv-wc-payment-gateway.php +++ b/woocommerce/payment-gateway/class-sv-wc-payment-gateway.php @@ -3070,17 +3070,22 @@ public function mark_order_as_failed( $order, $error_message, $response = null ) $this->add_debug_message( $error_message, 'error' ); - $user_message = ''; + // In Store API / REST context the message is returned in the process_payment() + // result and surfaced via RouteException; adding a session notice here leaks + // into the next request's cart validation (woocommerce_rest_cart_item_error 409). + if ( ! SV_WC_Helper::is_rest_api_request() ) { + $user_message = ''; + + if ( $response && $this->is_detailed_customer_decline_messages_enabled() ) { + $user_message = $response->get_user_message(); + } - if ( $response && $this->is_detailed_customer_decline_messages_enabled() ) { - $user_message = $response->get_user_message(); - } + if ( ! $user_message ) { + $user_message = esc_html__( 'An error occurred, please try again or try an alternate form of payment.', 'woocommerce-plugin-framework' ); + } - if ( ! $user_message ) { - $user_message = esc_html__( 'An error occurred, please try again or try an alternate form of payment.', 'woocommerce-plugin-framework' ); + SV_WC_Helper::wc_add_notice( $user_message, 'error' ); } - - SV_WC_Helper::wc_add_notice( $user_message, 'error' ); } @@ -3750,6 +3755,13 @@ public function add_debug_message( $message, ?string $type = 'message' ) : void return; } + // avoid adding notices on Store API / REST requests; the message is already returned in the + // response body and a session notice would leak into the next cart-validation request and + // surface as a 409 woocommerce_rest_cart_item_error. + if ( SV_WC_Helper::is_rest_api_request() ) { + return; + } + // add debug message to woocommerce->errors/messages if checkout or both is enabled, the admin/Ajax check ensures capture charge transactions aren't logged as notices to the front end if ( ( $this->debug_checkout() || ( 'error' === $type && $this->is_test_environment() ) ) && ( ! is_admin() || wp_doing_ajax() ) ) {