diff --git a/changelog/fix-7967-disputed-order-notice-test-mode-check b/changelog/fix-7967-disputed-order-notice-test-mode-check new file mode 100644 index 00000000000..43f8af2c81b --- /dev/null +++ b/changelog/fix-7967-disputed-order-notice-test-mode-check @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Fix network error that occurs when viewing an test mode order with test mode disabled, and vice versa. diff --git a/client/order/index.js b/client/order/index.js index 1bfdfeee7ad..16ec2b60183 100644 --- a/client/order/index.js +++ b/client/order/index.js @@ -61,6 +61,9 @@ jQuery( function ( $ ) { const manualRefundsTip = getConfig( 'manualRefundsTip' ) ?? ''; const chargeId = getConfig( 'chargeId' ); const testMode = getConfig( 'testMode' ); + // Order and site are both in test mode, or both in live mode. + // '1' = true, '' = false, null = the order was created before the test mode meta was added, so we assume it matches. + const orderTestModeMatch = getConfig( 'orderTestModeMatch' ) !== ''; maybeShowOrderNotices(); @@ -175,7 +178,7 @@ jQuery( function ( $ ) { '#wcpay-order-payment-details-container' ); - // If the container doesn't exist (WC < 7.9), or the charge ID isn't present, don't render the notice. + // If the container doesn't exist (WC < 7.9) don't render notices. if ( ! container ) { return; } @@ -184,7 +187,7 @@ jQuery( function ( $ ) { <> { testMode && } - { chargeId && ( + { chargeId && orderTestModeMatch && ( get_payment_method() ) { $refund_amount = $order->get_remaining_refund_amount(); + + // Check if the order's test mode meta matches the site's current test mode state. + // E.g. order and site are both in test mode, or both in live mode. + $order_mode = $order->get_meta( WC_Payments_Order_Service::WCPAY_MODE_META_KEY ); + if ( '' === $order_mode ) { + // If the order doesn't have a mode set, assume it was created before the order mode meta was added (< 6.9 PR#7651) and return null. + $order_test_mode_match = null; + } else { + $order_test_mode_match = ( + \WCPay\Constants\Order_Mode::PRODUCTION === $order_mode && + WC_Payments::mode()->is_live() + ) || ( + \WCPay\Constants\Order_Mode::TEST === $order_mode && + WC_Payments::mode()->is_test() + ); + } + wp_localize_script( 'WCPAY_ADMIN_ORDER_ACTIONS', 'wcpay_order_config', @@ -736,6 +753,7 @@ public function enqueue_payments_scripts() { 'chargeId' => $this->order_service->get_charge_id_for_order( $order ), 'hasOpenAuthorization' => $this->order_service->has_open_authorization( $order ), 'testMode' => \WCPay\Constants\Order_Mode::TEST === $order->get_meta( WC_Payments_Order_Service::WCPAY_MODE_META_KEY ), + 'orderTestModeMatch' => $order_test_mode_match, ] ); wp_localize_script(