Automattic\WooCommerce\Gateways\PayPal

TransactAccountManager::do_onboardingpublicWC 10.5.0

Onboard the merchant with the Transact platform.

Method of the class: TransactAccountManager{}

No Hooks.

Returns

null. Nothing (null).

Usage

$TransactAccountManager = new TransactAccountManager();
$TransactAccountManager->do_onboarding(): void;

Changelog

Since 10.5.0 Introduced.

TransactAccountManager::do_onboarding() code WC 10.9.4

public function do_onboarding(): void {
	// Check that we have a PayPal email. This is required for processing payments --
	// used as the payee email. Only begin onboarding if this minimum requirement is met.
	if ( empty( $this->gateway->email ) ) {
		return;
	}

	// Register with Jetpack if not already connected.
	$jetpack_connection_manager = $this->gateway->get_jetpack_connection_manager();
	if ( ! $jetpack_connection_manager ) {
		\WC_Gateway_Paypal::log( 'Jetpack connection manager not found.', 'error' );
		return;
	}

	if ( ! $jetpack_connection_manager->is_connected() ) {
		$result = $jetpack_connection_manager->try_registration();
		if ( is_wp_error( $result ) ) {
			\WC_Gateway_Paypal::log( 'Jetpack registration failed: ' . $result->get_error_message(), 'error' );
			return;
		}
	}

	// Fetch (cached) or create the Transact merchant and provider accounts.
	$merchant_account_data = $this->get_transact_account_data( 'merchant' );
	if ( empty( $merchant_account_data ) ) {
		$merchant_account = $this->create_merchant_account();
		if ( empty( $merchant_account ) ) {
			\WC_Gateway_Paypal::log( 'Transact merchant onboarding failed.', 'error' );
			return;
		}

		// Cache the merchant account data.
		$this->update_transact_account_cache(
			$this->get_cache_key( 'merchant' ),
			$merchant_account
		);
	}

	$provider_account_data = $this->get_transact_account_data( 'provider' );
	if ( empty( $provider_account_data ) ) {
		$provider_account = $this->create_provider_account();
		if ( ! $provider_account ) {
			\WC_Gateway_Paypal::log( 'Transact provider onboarding failed.', 'error' );
			return;
		}

		// Cache the provider account data.
		$this->update_transact_account_cache(
			$this->get_cache_key( 'provider' ),
			$provider_account
		);
	}

	// Set an extra flag to indicate that we've completed onboarding,
	// so we can do inexpensive early returns for checkers like
	// WC_Gateway_Paypal::should_use_orders_v2().
	$this->gateway->set_transact_onboarding_complete();
}