Automattic\WooCommerce\Internal\Admin\Settings\PaymentsProviders

PaymentGateway::needs_setuppublicWC 1.0

Check if the payment gateway needs setup.

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

Хуков нет.

Возвращает

true|false. True if the payment gateway needs setup, false otherwise.

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

$PaymentGateway = new PaymentGateway();
$PaymentGateway->needs_setup( $payment_gateway ): bool;
$payment_gateway(WC_Payment_Gateway) (обязательный)
The payment gateway object.

Код PaymentGateway::needs_setup() WC 10.4.3

public function needs_setup( WC_Payment_Gateway $payment_gateway ): bool {
	try {
		$needs_setup = wc_string_to_bool( $payment_gateway->needs_setup() );
		// If we get a true value, it means the gateway needs setup.
		if ( $needs_setup ) {
			return true;
		}
	} catch ( Throwable $e ) {
		// Do nothing but log so we can investigate.
		SafeGlobalFunctionProxy::wc_get_logger()->debug(
			'Failed to determine if gateway needs setup: ' . $e->getMessage(),
			array(
				'gateway'   => $payment_gateway->id,
				'source'    => 'settings-payments',
				'exception' => $e,
			)
		);
	}

	// If we get a false value, it might mean that it doesn't need setup,
	// but it can also mean that the gateway does not provide the information and just falls back to the default.
	// Check if there is a connected account, as that is the most common indicator of a setup.
	if ( ! $this->is_account_connected( $payment_gateway ) ) {
		return true;
	}

	// If we reach here, just assume that the gateway does not need setup.
	return false;
}