Automattic\WooCommerce\Internal\Admin\Settings\PaymentProviders

PaymentGateway::is_in_test_modepublicWC 1.0

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.

Method of the class: PaymentGateway{}

No Hooks.

Returns

true|false. True if the payment gateway is in test mode, false otherwise.

Usage

$PaymentGateway = new PaymentGateway();
$PaymentGateway->is_in_test_mode( $payment_gateway ): bool;
$payment_gateway(WC_Payment_Gateway) (required)
The payment gateway object.

PaymentGateway::is_in_test_mode() code WC 9.9.3

public function is_in_test_mode( WC_Payment_Gateway $payment_gateway ): bool {
	// Try various gateway methods to check if the payment gateway is in test mode.
	if ( is_callable( array( $payment_gateway, 'is_test_mode' ) ) ) {
		return filter_var( $payment_gateway->is_test_mode(), FILTER_VALIDATE_BOOLEAN );
	}
	if ( is_callable( array( $payment_gateway, 'is_in_test_mode' ) ) ) {
		return filter_var( $payment_gateway->is_in_test_mode(), FILTER_VALIDATE_BOOLEAN );
	}

	// 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;
		}
	}

	return false;
}