Home > Net >  Can't make a custom Signature validator class [Laravel 8 Spatie Webhook Client]
Can't make a custom Signature validator class [Laravel 8 Spatie Webhook Client]

Time:09-21

I am a beginner and I'm trying to make a custom signature validator class and following the Spatie documentation I made the file CustomSignatureValidator.php which implements Spatie\WebhookClient\SignatureValidator\SignatureValidator but I'm getting the following error:

App/Handler/CustomSignatureValidator is not a valid signature validation class. A valid signature validator is a class that implements Spatie\WebhookClient\SignatureValidator\SignatureValidator

This is how it looks like:

 <?php
    
    namespace App\Handler\CustomSignatureValidator;
    
    use Illuminate\Http\Request;
    use Spatie\WebhookClient\Exceptions\WebhookFailed;
    use Spatie\WebhookClient\WebhookConfig;
    use Spatie\WebhookClient\SignatureValidator\SignatureValidator;
    
    class CustomSignatureValidator implements SignatureValidator
    {
        public function isValid(Request $request, WebhookConfig $config): bool
        {
            return true;
        }
    }

I've also tried using

use Spatie\WebhookClient\SignatureValidator\SignatureValidator as SignatureValidator;

But i am also getting the same error.

If you could tell me what am i doing wrong i would really appreciate it.

CodePudding user response:

I think you've got one too many CustomSignatureValidator. Your namespace is App\Handler\CustomSignatureValidator, which means your class will be App\Handler\CustomSignatureValidator\CustomSignatureValidator.

I'm guessing the error isn't because your class is not implementing the right interface, but that it can't be found by the autoloader.

Try removing CustomSignatureValidator from your namespace, which will cause your class to become App\Handler\CustomSignatureValidator, which Laravel should be able to find.

  • Related