Skip to content

Commit f570657

Browse files
committed
Calculate test mode match in PHP
1 parent d8da2fc commit f570657

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

client/order/index.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ jQuery( function ( $ ) {
6060
const disableManualRefunds = getConfig( 'disableManualRefunds' ) ?? false;
6161
const manualRefundsTip = getConfig( 'manualRefundsTip' ) ?? '';
6262
const chargeId = getConfig( 'chargeId' );
63-
const orderTestMode = getConfig( 'testMode' );
63+
const testMode = getConfig( 'testMode' );
64+
// Order and site are both in test mode, or both in live mode.
65+
// '1' = true, '' = false, null = the order was created before the test mode meta was added, so we assume it matches.
66+
const orderTestModeMatch = getConfig( 'orderTestModeMatch' ) !== '';
6467

6568
maybeShowOrderNotices();
6669

@@ -175,20 +178,16 @@ jQuery( function ( $ ) {
175178
'#wcpay-order-payment-details-container'
176179
);
177180

178-
// Check if the order's test mode meta matches the site's current test mode setting.
179-
// E.g. order and site are both in test mode, or both in live mode.
180-
const isOrderTestModeMatch = orderTestMode === wcpaySettings.testMode;
181-
182-
// If the container doesn't exist (WC < 7.9) don't render the notice.
181+
// If the container doesn't exist (WC < 7.9) don't render notices.
183182
if ( ! container ) {
184183
return;
185184
}
186185

187186
ReactDOM.render(
188187
<>
189-
{ orderTestMode && <TestModeNotice /> }
188+
{ testMode && <TestModeNotice /> }
190189

191-
{ isOrderTestModeMatch && chargeId && (
190+
{ chargeId && orderTestModeMatch && (
192191
<DisputedOrderNoticeHandler
193192
chargeId={ chargeId }
194193
onDisableOrderRefund={ disableWooOrderRefundButton }

includes/admin/class-wc-payments-admin.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,23 @@ public function enqueue_payments_scripts() {
723723

724724
if ( $order && WC_Payment_Gateway_WCPay::GATEWAY_ID === $order->get_payment_method() ) {
725725
$refund_amount = $order->get_remaining_refund_amount();
726+
727+
// Check if the order's test mode meta matches the site's current test mode state.
728+
// E.g. order and site are both in test mode, or both in live mode.
729+
$order_mode = $order->get_meta( WC_Payments_Order_Service::WCPAY_MODE_META_KEY );
730+
if ( '' === $order_mode ) {
731+
// If the order doesn't have a mode set, assume it was created before the order mode meta was added and return null.
732+
$order_test_mode_match = null;
733+
} else {
734+
$order_test_mode_match = (
735+
\WCPay\Constants\Order_Mode::PRODUCTION === $order_mode &&
736+
WC_Payments::mode()->is_live()
737+
) || (
738+
\WCPay\Constants\Order_Mode::TEST === $order_mode &&
739+
WC_Payments::mode()->is_test()
740+
);
741+
}
742+
726743
wp_localize_script(
727744
'WCPAY_ADMIN_ORDER_ACTIONS',
728745
'wcpay_order_config',
@@ -736,6 +753,7 @@ public function enqueue_payments_scripts() {
736753
'chargeId' => $this->order_service->get_charge_id_for_order( $order ),
737754
'hasOpenAuthorization' => $this->order_service->has_open_authorization( $order ),
738755
'testMode' => \WCPay\Constants\Order_Mode::TEST === $order->get_meta( WC_Payments_Order_Service::WCPAY_MODE_META_KEY ),
756+
'orderTestModeMatch' => $order_test_mode_match,
739757
]
740758
);
741759
wp_localize_script(

0 commit comments

Comments
 (0)