Automattic\WooCommerce\Internal\Admin\Settings\PaymentsProviders

PayPal::is_paypal_in_sandbox_modeprivateWC 1.0

Check if the PayPal payment gateway is in sandbox mode.

For PayPal, there are two different environments: sandbox and production.

Метод класса: PayPal{}

Хуков нет.

Возвращает

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

Использование

// private - только в коде основоного (родительского) класса
$result = $this->is_paypal_in_sandbox_mode( $payment_gateway ): ?bool;
$payment_gateway(WC_Payment_Gateway) (обязательный)
The payment gateway object.

Код PayPal::is_paypal_in_sandbox_mode() WC 10.5.0

private function is_paypal_in_sandbox_mode( WC_Payment_Gateway $payment_gateway ): ?bool {
	if ( class_exists( '\WooCommerce\PayPalCommerce\PPCP' ) &&
		is_callable( '\WooCommerce\PayPalCommerce\PPCP::container' ) ) {
		try {
			$container = \WooCommerce\PayPalCommerce\PPCP::container();

			if ( $container->has( 'settings.connection-state' ) ) {
				$state = $container->get( 'settings.connection-state' );

				return $state->is_sandbox();
			}

			// Backwards compatibility with pre 3.0.0 (deprecated).
			if ( $container->has( 'onboarding.environment' ) &&
				defined( '\WooCommerce\PayPalCommerce\Onboarding\Environment::SANDBOX' ) ) {
				$environment         = $container->get( 'onboarding.environment' );
				$current_environment = $environment->current_environment();

				return \WooCommerce\PayPalCommerce\Onboarding\Environment::SANDBOX === $current_environment;
			}
		} 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;
}