Automattic\WooCommerce\Internal\Admin\Agentic

AgenticWebhookManager::customize_webhook_http_argspublicWC 1.0

Customize webhook HTTP arguments for Agentic topics.

Method of the class: AgenticWebhookManager{}

No Hooks.

Returns

Array. Modified HTTP arguments.

Usage

$AgenticWebhookManager = new AgenticWebhookManager();
$AgenticWebhookManager->customize_webhook_http_args( $http_args, $arg, $webhook_id );
$http_args(array) (required)
HTTP arguments.
$arg(mixed) (required)
First hook argument.
$webhook_id(int) (required)
Webhook ID.

AgenticWebhookManager::customize_webhook_http_args() code WC 10.5.0

public function customize_webhook_http_args( $http_args, $arg, $webhook_id ) {
	$webhook = wc_get_webhook( $webhook_id );
	if ( ! $webhook ) {
		return $http_args;
	}

	$topic = $webhook->get_topic();

	// Check if this is one of our Agentic topics.
	if ( self::WEBHOOK_TOPIC !== $topic ) {
		return $http_args;
	}

	// Compute HMAC signature per ACP webhook spec using WooCommerce's built-in method.
	// The signature must be computed over the raw request body.
	if ( isset( $http_args['body'] ) && ! empty( $webhook->get_secret() ) ) {
		// Use WooCommerce's signature generation to ensure consistency.
		$signature = $webhook->generate_signature( $http_args['body'] );

		// Add Merchant-Signature header per ACP webhook specification.
		$http_args['headers']['Merchant-Signature'] = $signature;
	}

	return $http_args;
}