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

WooPaymentsService::mark_onboarding_step_failedprivateWC 1.0

Mark an onboarding step as failed.

This is for internal use only as a failed step status should not be the result of a user action.

Method of the class: WooPaymentsService{}

No Hooks.

Returns

true|false. Whether the onboarding step was marked as failed.

Usage

// private - for code of main (parent) class only
$result = $this->mark_onboarding_step_failed( $step_id, $location, $error ): bool;
$step_id(string) (required)
The ID of the onboarding step.
$location(string) (required)
The location for which we are onboarding. This is an ISO 3166-1 alpha-2 country code.
$error(array)
An error to be stored for the step to provide context to API consumers. The error should be an associative array with the following keys:
  • 'code': A string representing the error code.
  • 'message': A string representing the error message.
  • 'context': Optional. An array of additional data related to the error.
    Default: array()

WooPaymentsService::mark_onboarding_step_failed() code WC 10.7.0

private function mark_onboarding_step_failed( string $step_id, string $location, array $error = array() ): bool {
	// There is no need to do onboarding checks because setting a step as failed should be possible at any time.

	// Record the error for the step, even if it is empty.
	// This will ensure we only store the most recent error.
	$this->save_nox_profile_onboarding_step_data_entry( $step_id, $location, 'error', $this->sanitize_onboarding_step_error( $error ) );

	$statuses = (array) $this->get_nox_profile_onboarding_step_entry( $step_id, $location, 'statuses' );

	// Mark the step as failed and record the timestamp.
	$statuses[ self::ONBOARDING_STEP_STATUS_FAILED ] = $this->proxy->call_function( 'time' );

	// Make sure we clear the blocked status if it was set since blocked and failed should be mutually exclusive.
	unset( $statuses[ self::ONBOARDING_STEP_STATUS_BLOCKED ] );

	// Store the updated step data.
	$result = $this->save_nox_profile_onboarding_step_entry( $step_id, $location, 'statuses', $statuses );

	if ( $result ) {
		// Record an event for the step being failed.
		$this->record_event(
			self::EVENT_PREFIX . 'onboarding_step_failed',
			$location,
			array(
				'step_id'    => $step_id,
				'error_code' => ! empty( $error['code'] ) ? $error['code'] : '',
			)
		);
	}

	return $result;
}