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

WooPaymentsService::reset_onboardingpublicWC 1.0

Reset onboarding.

Method of the class: WooPaymentsService{}

No Hooks.

Returns

Array. The response from the WooPayments API.

Usage

$WooPaymentsService = new WooPaymentsService();
$WooPaymentsService->reset_onboarding( $location, $from, ?string $source ): array;
$location(string) (required)
The location for which we are onboarding. This is an ISO 3166-1 alpha-2 country code.
$from(string)
Where in the UI the request is coming from. If not provided, it will identify the origin as the WC Admin Payments settings.
Default: ''
?string $source
.
Default: self::SESSION_ENTRY_DEFAULT

WooPaymentsService::reset_onboarding() code WC 10.8.1

public function reset_onboarding( string $location, string $from = '', ?string $source = self::SESSION_ENTRY_DEFAULT ): array {
	$this->check_if_onboarding_action_is_acceptable();

	// Ensure the payment gateways logic is initialized in case actions need to be taken on payment gateway changes.
	WC()->payment_gateways();

	$event_props = array();
	$source      = $this->validate_onboarding_source( $source );

	// Lock the onboarding to prevent concurrent actions.
	$this->set_onboarding_lock();

	try {
		// Before resetting the onboarding, record its details for tracking purposes.
		$event_props = array(
			'has_account'  => $this->has_account(),
			'account_mode' => $this->has_account() ? ( $this->has_live_account() ? 'live' : 'test' ) : 'none',
			'test_account' => $this->has_test_account(),
			'source'       => $source,
		);

		if ( $this->has_account() ) {
			// Call the WooPayments API to reset onboarding.
			$response = $this->proxy->call_static(
				Utils::class,
				'rest_endpoint_post_request',
				'/wc/v3/payments/onboarding/reset',
				array(
					'from'   => ! empty( $from ) ? esc_attr( $from ) : self::FROM_PAYMENT_SETTINGS,
					'source' => $source,
				)
			);
		} else {
			// If there is no account to reset, we can just use a success response.
			$response = array(
				'success' => true,
			);
		}
	} catch ( Exception $e ) {
		// Catch any exceptions to allow for proper error handling and onboarding unlock.
		$response = new WP_Error(
			'woocommerce_woopayments_onboarding_client_api_exception',
			esc_html__( 'An unexpected error happened while resetting onboarding.', 'woocommerce' ),
			array(
				'code'    => $e->getCode(),
				'message' => $e->getMessage(),
				'trace'   => $e->getTrace(),
			)
		);
	}

	// Unlock the onboarding after the API call finished or errored.
	$this->clear_onboarding_lock();

	// Clean up any NOX-specific onboarding data, regardless of the API response.
	$this->proxy->call_function( 'delete_option', self::NOX_PROFILE_OPTION_KEY );

	// Make sure the onboarding mode is reset.
	if ( class_exists( 'WC_Payments_Onboarding_Service' ) && defined( 'WC_Payments_Onboarding_Service::TEST_MODE_OPTION' ) ) {
		$this->proxy->call_function( 'update_option', Constants::get_constant( 'WC_Payments_Onboarding_Service::TEST_MODE_OPTION' ), 'no' );
	}

	if ( is_wp_error( $response ) ) {
		throw new ApiException(
			'woocommerce_woopayments_onboarding_client_api_error',
			esc_html( $response->get_error_message() ),
			(int) WP_Http::FAILED_DEPENDENCY,
			map_deep( (array) $response->get_error_data(), 'esc_html' )
		);
	}

	if ( ! is_array( $response ) || empty( $response['success'] ) ) {
		throw new ApiException(
			'woocommerce_woopayments_onboarding_client_api_error',
			esc_html__( 'Failed to reset onboarding.', 'woocommerce' ),
			(int) WP_Http::FAILED_DEPENDENCY
		);
	}

	// Record an event for the onboarding reset.
	$this->record_event(
		self::EVENT_PREFIX . 'onboarding_reset',
		$location,
		$event_props
	);

	return $response;
}