Automattic\WooCommerce\Internal\Admin\Settings\PaymentsProviders\WooPayments

WooPaymentsController::handle_returns_from_wpcompublicWC 1.0

Handle returns from WordPress.com after the user has accepted or declined the WPCOM connection.

Method of the class: WooPaymentsController{}

No Hooks.

Returns

null. Nothing (null).

Usage

$WooPaymentsController = new WooPaymentsController();
$WooPaymentsController->handle_returns_from_wpcom(): void;

WooPaymentsController::handle_returns_from_wpcom() code WC 11.0.0

public function handle_returns_from_wpcom(): void {
	// Handle the return from WPCOM after the user has accepted or declined the WordPress.com connection.
	// phpcs:ignore WordPress.Security.NonceVerification.Recommended
	if ( ! empty( $_GET[ WooPaymentsService::WPCOM_CONNECTION_RETURN_PARAM ] ) ) {
		// We are only interested in connection flows that are initiated from NOX session entry points.
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		if ( empty( $_GET['source'] ) ) {
			return;
		}
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		$source = sanitize_text_field( wp_unslash( $_GET['source'] ) );
		if ( ! in_array( $source, array( WooPaymentsService::SESSION_ENTRY_DEFAULT, WooPaymentsService::SESSION_ENTRY_LYS ), true ) ) {
			return;
		}

		$location = $this->payments->get_country();

		// Determine the connection state by querying the WPCOM connection onboarding step status.
		$wpcom_connected = WooPaymentsService::ONBOARDING_STEP_STATUS_COMPLETED === $this->woopayments->get_onboarding_step_status( WooPaymentsService::ONBOARDING_STEP_WPCOM_CONNECTION, $location );

		// Track the connection attempt result.
		$event_props = array(
			'step_id' => WooPaymentsService::ONBOARDING_STEP_WPCOM_CONNECTION,
			'source'  => $source,
		);
		$this->woopayments->record_event(
			$wpcom_connected ? 'wpcom_connection_success' : 'wpcom_connection_failure',
			$location,
			$event_props
		);

		// On successful connection, mark the onboarding step as completed, if not already.
		if ( $wpcom_connected ) {
			$this->woopayments->mark_onboarding_step_completed( WooPaymentsService::ONBOARDING_STEP_WPCOM_CONNECTION, $location );
		}
	}
}