Automattic\WooCommerce\StoreApi\Routes\V1

Checkout::get_response()publicWC 1.0

Get the route response based on the type of request.

Method of the class: Checkout{}

No Hooks.

Return

\WP_REST_Response.

Usage

$Checkout = new Checkout();
$Checkout->get_response( $request );
$request(\WP_REST_Request) (required)
Request object.

Checkout::get_response() code WC 9.3.1

public function get_response( \WP_REST_Request $request ) {
	$this->load_cart_session( $request );

	$response    = null;
	$nonce_check = $this->requires_nonce( $request ) ? $this->check_nonce( $request ) : null;

	if ( is_wp_error( $nonce_check ) ) {
		$response = $nonce_check;
	}

	if ( ! $response ) {
		try {
			$response = $this->get_response_by_request_method( $request );
		} catch ( InvalidCartException $error ) {
			$response = $this->get_route_error_response_from_object( $error->getError(), $error->getCode(), $error->getAdditionalData() );
		} catch ( RouteException $error ) {
			$response = $this->get_route_error_response( $error->getErrorCode(), $error->getMessage(), $error->getCode(), $error->getAdditionalData() );
		} catch ( \Exception $error ) {
			$response = $this->get_route_error_response( 'woocommerce_rest_unknown_server_error', $error->getMessage(), 500 );
		}
	}

	if ( is_wp_error( $response ) ) {
		$response = $this->error_to_response( $response );

		// If we encountered an exception, free up stock.
		if ( $this->order ) {
			wc_release_stock_for_order( $this->order );
		}
	}

	return $this->add_response_headers( $response );
}