WordPress at Your Fingertips
function is not described

WC_Webhook::generate_signature() public WC 2.2.0

Generate a base64-encoded HMAC-SHA256 signature of the payload body so the recipient can verify the authenticity of the webhook. Note that the signature is calculated after the body has already been encoded (JSON by default).

{} It's a method of the class: WC_Webhook{}

Hooks from the method

Return

String.

Usage

$WC_Webhook = new WC_Webhook();
$WC_Webhook->generate_signature( $payload );
$payload(string) (required)
Payload data to hash.

Changelog

Since 2.2.0 Introduced.

Code of WC_Webhook::generate_signature() WC 5.9.0

public function generate_signature( $payload ) {
	$hash_algo = apply_filters( 'woocommerce_webhook_hash_algorithm', 'sha256', $payload, $this->get_id() );

	// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
	return base64_encode( hash_hmac( $hash_algo, $payload, wp_specialchars_decode( $this->get_secret(), ENT_QUOTES ), true ) );
}