WC_Gateway_Paypal_Request::send_wpcom_proxy_requestprivateWC 1.0

Send a request to the API proxy.

Method of the class: WC_Gateway_Paypal_Request{}

No Hooks.

Returns

Array|null. The API response body, or null 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.

WC_Gateway_Paypal_Request::send_wpcom_proxy_request() code WC 10.4.3

private function send_wpcom_proxy_request( $method, $endpoint, $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' => WC_Gateway_Paypal_Constants::WPCOM_PROXY_REQUEST_TIMEOUT,
		),
		'GET' === $method ? null : wp_json_encode( $request_body ),
		'wpcom'
	);

	return $response;
}