WC_Helper_API::create_request_signature()private staticWC 1.0

Create signature for a request.

Method of the class: WC_Helper_API{}

No Hooks.

Return

String. The signature.

Usage

$result = WC_Helper_API::create_request_signature( $access_token_secret, $url, $method, $body ): string;
$access_token_secret(string) (required)
The access token secret.
$url(string) (required)
The URL to add the access token and signature to.
$method(string) (required)
The request method.
$body(array)
The body of the request.
Default: null

WC_Helper_API::create_request_signature() code WC 9.7.1

private static function create_request_signature( string $access_token_secret, string $url, string $method, $body = null ): string {

	$request_uri  = wp_parse_url( $url, PHP_URL_PATH );
	$query_string = wp_parse_url( $url, PHP_URL_QUERY );

	if ( is_string( $query_string ) ) {
		$request_uri .= '?' . $query_string;
	}

	$data = array(
		'host'        => wp_parse_url( $url, PHP_URL_HOST ),
		'request_uri' => $request_uri,
		'method'      => $method,
	);

	if ( ! empty( $body ) ) {
		$data['body'] = $body;
	}

	return hash_hmac( 'sha256', wp_json_encode( $data ), $access_token_secret );
}