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

WooPaymentsRestController::handle_onboarding_preloadprotectedWC 1.0

Handle the onboarding preload action.

Method of the class: WooPaymentsRestController{}

No Hooks.

Returns

WP_Error|WP_REST_Response. The response or error.

Usage

// protected - for code of main (parent) or child class
$result = $this->handle_onboarding_preload( $request );
$request(WP_REST_Request) (required)
The request object.

WooPaymentsRestController::handle_onboarding_preload() code WC 10.8.1

protected function handle_onboarding_preload( WP_REST_Request $request ) {
	$location = $request->get_param( 'location' );
	if ( empty( $location ) ) {
		// Fall back to the providers country if no location is provided.
		$location = $this->payments->get_country();
	}

	try {
		$response = $this->woopayments->onboarding_preload( $location );
	} catch ( ApiException $e ) {
		return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
	}

	// If there is no success key in the response, we assume the operation was successful.
	if ( ! isset( $response['success'] ) ) {
		$response['success'] = true;
	}

	return rest_ensure_response( $response );
}