Automattic\WooCommerce\Internal\Admin\Settings\PaymentsProviders

Visa::is_visa_in_sandbox_modeprivateWC 1.0

Check if the Visa payment gateway is in test/sandbox mode.

There are two different environments: test/sandbox and production.

Method of the class: Visa{}

No Hooks.

Returns

?true|false. 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_visa_in_sandbox_mode( $payment_gateway ): ?bool;
$payment_gateway(WC_Payment_Gateway) (required)
The payment gateway object.

Visa::is_visa_in_sandbox_mode() code WC 10.8.1

private function is_visa_in_sandbox_mode( WC_Payment_Gateway $payment_gateway ): ?bool {
	try {
		if ( is_callable( array( $payment_gateway, 'get_config_settings' ) ) &&
			defined( 'VISA_ACCEPTANCE_ENVIRONMENT_TEST' ) &&
			defined( 'VISA_ACCEPTANCE_ENVIRONMENT_PRODUCTION' ) ) {
			$settings = $payment_gateway->get_config_settings();

			if ( is_array( $settings ) && isset( $settings['environment'] ) ) {
				if ( \VISA_ACCEPTANCE_ENVIRONMENT_TEST === $settings['environment'] ) {
					return true;
				}
				if ( \VISA_ACCEPTANCE_ENVIRONMENT_PRODUCTION === $settings['environment'] ) {
					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 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;
}