Automattic\WooCommerce\Gateways\PayPal

Request::send_wpcom_proxy_requestprivateWC 1.0

Send a request to the API proxy.

Method of the class: Request{}

No Hooks.

Returns

Array|\WP_Error. The API response body, or WP_Error if the request fails.

Usage

// private - for code of main (parent) class only
$result = $this->send_wpcom_proxy_request( $method, $endpoint, $request_body );
$method(string) (required)
The HTTP method to use.
$endpoint(string) (required)
The endpoint to request.
$request_body(array) (required)
The request body.

Request::send_wpcom_proxy_request() code WC 10.8.1

private function send_wpcom_proxy_request( string $method, string $endpoint, array $request_body ) {
	$site_id = \Jetpack_Options::get_option( 'id' );
	if ( ! $site_id ) {
		\WC_Gateway_Paypal::log( sprintf( 'Site ID not found. Cannot send request to %s.', $endpoint ) );
		throw new Exception( 'Site ID not found. Cannot send proxy request.' );
	}

	if ( 'GET' === $method ) {
		$endpoint .= '?' . http_build_query( $request_body );
	}

	$response = Jetpack_Connection_Client::wpcom_json_api_request_as_blog(
		sprintf( '/sites/%d/%s/%s', $site_id, self::WPCOM_PROXY_REST_BASE, $endpoint ),
		self::WPCOM_PROXY_ENDPOINT_API_VERSION,
		array(
			'headers' => array(
				'Content-Type' => 'application/json',
				'User-Agent'   => 'TransactGateway/woocommerce/' . WC()->version,
			),
			'method'  => $method,
			'timeout' => PayPalConstants::WPCOM_PROXY_REQUEST_TIMEOUT,
		),
		'GET' === $method ? null : wp_json_encode( $request_body ),
		'wpcom'
	);

	return $response;
}