Automattic\WooCommerce\Internal\Admin\Settings\PaymentsProviders
PaymentGateway::is_in_test_mode
Try to determine if the payment gateway is in test mode.
This is a best-effort attempt, as there is no standard way to determine this. Trust the true value, but don't consider a false value as definitive.
Метод класса: PaymentGateway{}
Хуков нет.
Возвращает
true|false. True if the payment gateway is in test mode, false otherwise.
Использование
$PaymentGateway = new PaymentGateway(); $PaymentGateway->is_in_test_mode( $payment_gateway ): bool;
- $payment_gateway(WC_Payment_Gateway) (обязательный)
- The payment gateway object.
Код PaymentGateway::is_in_test_mode() PaymentGateway::is in test mode WC 10.4.3
public function is_in_test_mode( WC_Payment_Gateway $payment_gateway ): bool {
try {
// Try various gateway methods to check if the payment gateway is in test mode.
if ( is_callable( array( $payment_gateway, 'is_test_mode' ) ) ) {
return wc_string_to_bool( $payment_gateway->is_test_mode() );
}
if ( is_callable( array( $payment_gateway, 'is_in_test_mode' ) ) ) {
return wc_string_to_bool( $payment_gateway->is_in_test_mode() );
}
// Try various gateway public properties to check if the payment gateway is in test mode.
if ( isset( $payment_gateway->testmode ) ) {
return wc_string_to_bool( $payment_gateway->testmode );
}
if ( isset( $payment_gateway->test_mode ) ) {
return wc_string_to_bool( $payment_gateway->test_mode );
}
// Try various gateway option entries to check if the payment gateway is in test mode.
if ( is_callable( array( $payment_gateway, 'get_option' ) ) ) {
$test_mode = filter_var( $payment_gateway->get_option( 'test_mode', 'not_found' ), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE );
if ( ! is_null( $test_mode ) ) {
return $test_mode;
}
$test_mode = filter_var( $payment_gateway->get_option( 'testmode', 'not_found' ), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE );
if ( ! is_null( $test_mode ) ) {
return $test_mode;
}
$mode = strtolower( (string) $payment_gateway->get_option( 'mode', 'not_found' ) );
if ( in_array( $mode, array( 'test', 'sandbox', 'dev' ), true ) ) {
return true;
} elseif ( in_array( $mode, array( 'live', 'production', 'prod' ), true ) ) {
return false;
}
}
} catch ( Throwable $e ) {
// Do nothing but log so we can investigate.
SafeGlobalFunctionProxy::wc_get_logger()->debug(
'Failed to determine if gateway is in test mode: ' . $e->getMessage(),
array(
'gateway' => $payment_gateway->id,
'source' => 'settings-payments',
'exception' => $e,
)
);
}
return false;
}