Webhook::validate( array $request, string|bool|null $password = null )

Summary

Validates an incoming request.


Parameters

$request

(array) (Required) Request data.

$password

(string|bool|null) (Optional) The password to authenticate with.

Default value: null


Return

(bool|WP_Error) True on validation or a WP_Error if the request isn't valid.


Source

File: src/BigCommerce/Webhooks/Webhook.php

	public function validate( $request, $password = null ) {
		if ( ! $password ) {
			$password = $this->get_auth_header();
		}

		if ( ! $password || $this->generate_password() !== $password ) {
			return new \WP_Error(
				static::PASSWORD_ERROR_CODE,
				__( 'Password header does not match.', 'bigcommerce' )
			);
		}

		if ( ! is_array( $request ) || ! isset( $request[ 'data' ][ 'type' ] ) || ! isset( $request[ 'data' ][ 'id' ] ) ) {
			return new \WP_Error(
				static::VALIDATION_ERROR_CODE,
				__( 'Webhook request data is invalid.', 'bigcommerce' )
			);
		}

		return true;
	}


User Contributed Notes

You must log in before being able to contribute a note or feedback.