Automattic\WooCommerce\Internal\Admin\Settings\PaymentProviders

PayPal::is_paypal_onboardedprivateWC 1.0

Check if the PayPal payment gateway is onboarded.

Method of the class: PayPal{}

No Hooks.

Returns

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

Usage

// private - for code of main (parent) class only
$result = $this->is_paypal_onboarded(): ?bool;

PayPal::is_paypal_onboarded() code WC 9.9.4

private function is_paypal_onboarded(): ?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 ( \Exception $e ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
			// Ignore any exceptions.
		}
	}

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