Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing transaction error when viewing orders placed in mismatched test mode #7972

Merged
merged 6 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/fix-7967-disputed-order-notice-test-mode-check
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 5 additions & 2 deletions client/order/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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;
}
Expand All @@ -184,7 +187,7 @@ jQuery( function ( $ ) {
<>
{ testMode && <TestModeNotice /> }

{ chargeId && (
{ chargeId && orderTestModeMatch && (
<DisputedOrderNoticeHandler
chargeId={ chargeId }
onDisableOrderRefund={ disableWooOrderRefundButton }
Expand Down
18 changes: 18 additions & 0 deletions includes/admin/class-wc-payments-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,23 @@ public function enqueue_payments_scripts() {

if ( $order && WC_Payment_Gateway_WCPay::GATEWAY_ID === $order->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',
Expand All @@ -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(
Expand Down
Loading