Automattic\WooCommerce\Internal\Admin\Settings\PaymentsProviders

PayPal::is_paypal_onboardedprivateWC 1.0

Check if the PayPal payment gateway is onboarded.

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

Хуков нет.

Возвращает

?true|false. True if the payment gateway is onboarded, false otherwise. Null if we failed to determine the onboarding status.

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

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

Код PayPal::is_paypal_onboarded() WC 10.4.3

private function is_paypal_onboarded( 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_connected();
			}

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

				return $state->current_state() >= \WooCommerce\PayPalCommerce\Onboarding\State::STATE_ONBOARDED;
			}
		} catch ( \Throwable $e ) {
			// Do nothing but log so we can investigate.
			SafeGlobalFunctionProxy::wc_get_logger()->debug(
				'Failed to determine if gateway is onboarded: ' . $e->getMessage(),
				array(
					'gateway'   => $payment_gateway->id,
					'source'    => 'settings-payments',
					'exception' => $e,
				)
			);
		}
	}

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