Automattic\WooCommerce\Internal\Admin\Settings\PaymentsProviders

Mastercard::is_mastercard_in_sandbox_mode │ private │ WC 1.0

Check if the Mastercard Merchant Cloud payment gateway is in sandbox mode.

Method of the class: Mastercard{}

No Hooks.

Returns

?bool. True if the payment gateway is in sandbox mode, false otherwise. Null if the environment could not be determined.

Usage

// private - for code of main (parent) class only
$result = $this->is_mastercard_in_sandbox_mode( $payment_gateway ): ?bool;
$payment_gateway(WC_Payment_Gateway) (required)
The payment gateway object.

Mastercard::is_mastercard_in_sandbox_mode() code WC 11.1.2

private function is_mastercard_in_sandbox_mode( WC_Payment_Gateway $payment_gateway ): ?bool {
	try {
		// The gateway stores sandbox mode as a checkbox option ('yes'|'no'), read through the
		// gateway's own get_option() so we follow whatever precedence the extension uses
		// internally, including its form field default.
		$sandbox = $payment_gateway->get_option( 'sandbox' );
		if ( ! is_scalar( $sandbox ) || '' === trim( (string) $sandbox ) ) {
			return null;
		}

		return \wc_string_to_bool( (string) $sandbox );
	} catch ( Throwable $e ) {
		// Do nothing but log so we can investigate.
		SafeGlobalFunctionProxy::wc_get_logger()->debug(
			'Failed to determine if gateway is in sandbox mode: ' . $e->getMessage(),
			array(
				'gateway'   => $payment_gateway->id,
				'source'    => 'settings-payments',
				'exception' => $e,
			)
		);
	}

	// Let the caller know that we couldn't determine the environment.
	return null;
}