Giter VIP home page Giter VIP logo

laravel-webhook-client's Introduction

Receive webhooks in Laravel apps

Latest Version on Packagist GitHub Workflow Status Total Downloads

A webhook is a way for an app to provide information to another app about a specific event. The way the two apps communicate is with a simple HTTP request.

This package allows you to receive webhooks in a Laravel app. It has support for verifying signed calls, storing payloads and processing the payloads in a queued job.

If you need to send webhooks, take a look at our laravel-webhook-server package.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

composer require spatie/laravel-webhook-client

Configuring the package

You can publish the config file with:

php artisan vendor:publish --provider="Spatie\WebhookClient\WebhookClientServiceProvider" --tag="webhook-client-config"

This is the contents of the file that will be published at config/webhook-client.php:

<?php

return [
    'configs' => [
        [
            /*
             * This package supports multiple webhook receiving endpoints. If you only have
             * one endpoint receiving webhooks, you can use 'default'.
             */
            'name' => 'default',

            /*
             * We expect that every webhook call will be signed using a secret. This secret
             * is used to verify that the payload has not been tampered with.
             */
            'signing_secret' => env('WEBHOOK_CLIENT_SECRET'),

            /*
             * The name of the header containing the signature.
             */
            'signature_header_name' => 'Signature',

            /*
             *  This class will verify that the content of the signature header is valid.
             *
             * It should implement \Spatie\WebhookClient\SignatureValidator\SignatureValidator
             */
            'signature_validator' => \Spatie\WebhookClient\SignatureValidator\DefaultSignatureValidator::class,

            /*
             * This class determines if the webhook call should be stored and processed.
             */
            'webhook_profile' => \Spatie\WebhookClient\WebhookProfile\ProcessEverythingWebhookProfile::class,

            /*
             * This class determines the response on a valid webhook call.
             */
            'webhook_response' => \Spatie\WebhookClient\WebhookResponse\DefaultRespondsTo::class,

            /*
             * The classname of the model to be used to store webhook calls. The class should
             * be equal or extend Spatie\WebhookClient\Models\WebhookCall.
             */
            'webhook_model' => \Spatie\WebhookClient\Models\WebhookCall::class,

            /*
             * In this array, you can pass the headers that should be stored on
             * the webhook call model when a webhook comes in.
             *
             * To store all headers, set this value to `*`.
             */
            'store_headers' => [

            ],

            /*
             * The class name of the job that will process the webhook request.
             *
             * This should be set to a class that extends \Spatie\WebhookClient\Jobs\ProcessWebhookJob.
             */
            'process_webhook_job' => '',
        ],
    ],

    /*
     * The number of days after which models should be deleted.
     *
     * Set to null if no models should be deleted.
     */
    'delete_after_days' => 30,
];

In the signing_secret key of the config file, you should add a valid webhook secret. This value should be provided by the app that will send you webhooks.

This package will try to store and respond to the webhook as fast as possible. Processing the payload of the request is done via a queued job. It's recommended to not use the sync driver but a real queue driver. You should specify the job that will handle processing webhook requests in the process_webhook_job of the config file. A valid job is any class that extends Spatie\WebhookClient\Jobs\ProcessWebhookJob and has a handle method.

Preparing the database

By default, all webhook calls will get saved in the database.

To create the table that holds the webhook calls, you must publish the migration with:

php artisan vendor:publish --provider="Spatie\WebhookClient\WebhookClientServiceProvider" --tag="webhook-client-migrations"

After the migration has been published, you can create the webhook_calls table by running the migrations:

php artisan migrate

Taking care of routing

Finally, let's take care of the routing. At the app that sends webhooks, you probably configure an URL where you want your webhook requests to be sent. In the routes file of your app, you must pass that route to Route::webhooks. Here's an example:

Route::webhooks('webhook-receiving-url');

Behind the scenes, by default this will register a POST route to a controller provided by this package. Because the app that sends webhooks to you has no way of getting a csrf-token, you must add that route to the except array of the VerifyCsrfToken middleware:

protected $except = [
    'webhook-receiving-url',
];

Usage

With the installation out of the way, let's take a look at how this package handles webhooks. First, it will verify if the signature of the request is valid. If it is not, we'll throw an exception and fire off the InvalidSignatureEvent event. Requests with invalid signatures will not be stored in the database.

Next, the request will be passed to a webhook profile. A webhook profile is a class that determines if a request should be stored and processed by your app. It allows you to filter out webhook requests that are of interest to your app. You can easily create your own webhook profile.

If the webhook profile determines that request should be stored and processed, we'll first store it in the webhook_calls table. After that, we'll pass that newly created WebhookCall model to a queued job. Most webhook sending apps expect you to respond very quickly. Offloading the real processing work allows for speedy responses. You can specify which job should process the webhook in the process_webhook_job in the webhook-client config file. Should an exception be thrown while queueing the job, the package will store that exception in the exception attribute on the WebhookCall model.

After the job has been dispatched, the request will be passed to a webhook response. A webhook response is a class that determines the HTTP response for the request. An 'ok' message response with 200 status code is returned by default, but you can easily create your own webhook response.

Verifying the signature of incoming webhooks

This package assumes that an incoming webhook request has a header that can be used to verify the payload has not been tampered with. The name of the header containing the signature can be configured in the signature_header_name key of the config file. By default, the package uses the DefaultSignatureValidator to validate signatures. This is how that class will compute the signature.

$computedSignature = hash_hmac('sha256', $request->getContent(), $configuredSigningSecret);

If the $computedSignature does match the value, the request will be passed to the webhook profile. If $computedSignature does not match the value in the signature header, the package will respond with a 500 and discard the request.

Creating your own signature validator

A signature validator is any class that implements Spatie\WebhookClient\SignatureValidator\SignatureValidator. Here's what that interface looks like.

use Illuminate\Http\Request;
use Spatie\WebhookClient\WebhookConfig;

interface SignatureValidator
{
    public function isValid(Request $request, WebhookConfig $config): bool;
}

WebhookConfig is a data transfer object that lets you easily pull up the config (containing the header name that contains the signature and the secret) for the webhook request.

After creating your own SignatureValidator you must register it in the signature_validator in the webhook-client config file.

Determining which webhook requests should be stored and processed

After the signature of an incoming webhook request is validated, the request will be passed to a webhook profile. A webhook profile is a class that determines if the request should be stored and processed. If the webhook sending app sends out request where your app isn't interested in, you can use this class to filter out such events.

By default the \Spatie\WebhookClient\WebhookProfile\ProcessEverythingWebhookProfile class is used. As its name implies, this default class will determine that all incoming requests should be stored and processed.

Creating your own webhook profile

A webhook profile is any class that implements \Spatie\WebhookClient\WebhookProfile\WebhookProfile. This is what that interface looks like:

namespace Spatie\WebhookClient\WebhookProfile;

use Illuminate\Http\Request;

interface WebhookProfile
{
    public function shouldProcess(Request $request): bool;
}

After creating your own WebhookProfile you must register it in the webhook_profile key in the webhook-client config file.

Storing and processing webhooks

After the signature is validated and the webhook profile has determined that the request should be processed, the package will store and process the request.

The request will first be stored in the webhook_calls table. This is done using the WebhookCall model.

Should you want to customize the table name or anything on the storage behavior, you can let the package use an alternative model. A webhook storing model can be specified in the webhook_model. Make sure your model extends Spatie\WebhookClient\Models\WebhookCall.

You can change how the webhook is stored by overriding the storeWebhook method of WebhookCall. In the storeWebhook method you should return a saved model.

Next, the newly created WebhookCall model will be passed to a queued job that will process the request. Any class that extends \Spatie\WebhookClient\Jobs\ProcessWebhookJob is a valid job. Here's an example:

namespace App\Jobs;

use Spatie\WebhookClient\Jobs\ProcessWebhookJob as SpatieProcessWebhookJob;

class ProcessWebhookJob extends SpatieProcessWebhookJob
{
    public function handle()
    {
        // $this->webhookCall // contains an instance of `WebhookCall`

        // perform the work here
    }
}

You should specify the class name of your job in the process_webhook_job of the webhook-client config file.

Creating your own webhook response

A webhook response is any class that implements \Spatie\WebhookClient\WebhookResponse\RespondsToWebhook. This is what that interface looks like:

namespace Spatie\WebhookClient\WebhookResponse;

use Illuminate\Http\Request;
use Spatie\WebhookClient\WebhookConfig;

interface RespondsToWebhook
{
    public function respondToValidWebhook(Request $request, WebhookConfig $config);
}

After creating your own WebhookResponse you must register it in the webhook_response key in the webhook-client config file.

Handling incoming webhook request for multiple apps

This package allows webhooks to be received from multiple different apps. Let's take a look at an example config file where we add support for two webhook URLs. All comments from the config have been removed for brevity.

return [
    'configs' => [
        [
            'name' => 'webhook-sending-app-1',
            'signing_secret' => 'secret-for-webhook-sending-app-1',
            'signature_header_name' => 'Signature-for-app-1',
            'signature_validator' => \Spatie\WebhookClient\SignatureValidator\DefaultSignatureValidator::class,
            'webhook_profile' => \Spatie\WebhookClient\WebhookProfile\ProcessEverythingWebhookProfile::class,
            'webhook_response' => \Spatie\WebhookClient\WebhookResponse\DefaultRespondsTo::class,
            'webhook_model' => \Spatie\WebhookClient\Models\WebhookCall::class,
            'process_webhook_job' => '',
        ],
        [
            'name' => 'webhook-sending-app-2',
            'signing_secret' => 'secret-for-webhook-sending-app-2',
            'signature_header_name' => 'Signature-for-app-2',
            'signature_validator' => \Spatie\WebhookClient\SignatureValidator\DefaultSignatureValidator::class,
            'webhook_profile' => \Spatie\WebhookClient\WebhookProfile\ProcessEverythingWebhookProfile::class,
            'webhook_response' => \Spatie\WebhookClient\WebhookResponse\DefaultRespondsTo::class,
            'webhook_model' => \Spatie\WebhookClient\Models\WebhookCall::class,
            'process_webhook_job' => '',
        ],
    ],
];

When registering routes for the package, you should pass the name of the config as a second parameter.

Route::webhooks('receiving-url-for-app-1', 'webhook-sending-app-1');
Route::webhooks('receiving-url-for-app-2', 'webhook-sending-app-2');

Change route method

Being an incoming webhook client, there are instances where you might want to establish a route method other than the default post. You have the flexibility to modify the standard post method to options such as get, put, patch, or delete.

Route::webhooks('receiving-url-for-app-1', 'webhook-sending-app-1', 'get');
Route::webhooks('receiving-url-for-app-1', 'webhook-sending-app-1', 'put');
Route::webhooks('receiving-url-for-app-1', 'webhook-sending-app-1', 'patch');
Route::webhooks('receiving-url-for-app-1', 'webhook-sending-app-1', 'delete');

Using the package without a controller

If you don't want to use the routes and controller provided by your macro, you can programmatically add support for webhooks to your own controller.

Spatie\WebhookClient\WebhookProcessor is a class that verifies the signature, calls the web profile, stores the webhook request, and starts a queued job to process the stored webhook request. The controller provided by this package also uses that class under the hood.

It can be used like this:

$webhookConfig = new \Spatie\WebhookClient\WebhookConfig([
    'name' => 'webhook-sending-app-1',
    'signing_secret' => 'secret-for-webhook-sending-app-1',
    'signature_header_name' => 'Signature',
    'signature_validator' => \Spatie\WebhookClient\SignatureValidator\DefaultSignatureValidator::class,
    'webhook_profile' => \Spatie\WebhookClient\WebhookProfile\ProcessEverythingWebhookProfile::class,
    'webhook_response' => \Spatie\WebhookClient\WebhookResponse\DefaultRespondsTo::class,
    'webhook_model' => \Spatie\WebhookClient\Models\WebhookCall::class,
    'process_webhook_job' => '',
]);

(new \Spatie\WebhookClient\WebhookProcessor($request, $webhookConfig))->process();

Deleting models

Whenever a webhook comes in, this package will store as a WebhookCall model. After a while, you might want to delete old models.

The WebhookCall model has Laravel's MassPrunable trait applied on it. You can customize the cutoff date in the webhooks config file.

In this example all models will be deleted when older than 30 days.

return [
    'configs' => [
        // ...
    ],

    'delete_after_days' => 30,
];

After configuring the model, you should schedule the model:prune Artisan command in your application's Kernel class. Don't forget to explicitly mention the WebhookCall class. You are free to choose the appropriate interval at which this command should be run:

namespace App\Console;

use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Spatie\WebhookClient\Models\WebhookCall;

class Kernel extends ConsoleKernel
{
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('model:prune', [
            '--model' => [WebhookCall::class],
        ])->daily();
    
        // This will not work, as models in a package are not used by default
        // $schedule->command('model:prune')->daily();
    }
}

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security-related issues, please email [email protected] instead of using the issue tracker.

Postcardware

You're free to use this package, but if it makes it to your production environment, we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

We publish all received postcards on our company website.

Credits

License

The MIT License (MIT). Please see License File for more information.

laravel-webhook-client's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-webhook-client's Issues

JSON column type for payload?

In the migration create_webhook_calls_table.php.stub, the payload column is defined using $table->text(). This means that I'm unable to use queries like WebhookCall::where('payload->type', 'invoice.paid')->first(); as the database (Postgres in this case) doesn't understand how to query text columns as JSON.

Would it be possible to update the migration to use a $table->json() definition if it detects that that the driver used in the connection defined in config('database.default') supports JSON columns?

Could not find the configuration for ``

I am using several configuration.

return [
    'configs' => [
        [
	        'name' => 'woo-sl',
	        'signing_secret' => env('WEBHOOK_CLIENT_SECRET_SL'),
	        'signature_header_name' => 'x-wc-webhook-signature',
	        'signature_validator' => \App\Webhooks\Incoming\WooCommerceSignatureValidator::class,
	        'webhook_profile' => \Spatie\WebhookClient\WebhookProfile\ProcessEverythingWebhookProfile::class,
	        'webhook_response' => \Spatie\WebhookClient\WebhookResponse\DefaultRespondsTo::class,
	        'webhook_model' => \Spatie\WebhookClient\Models\WebhookCall::class,
	        'process_webhook_job' => App\Jobs\CreateOrderFromWebhook::class,
        ],
        [
	        'name' => 'woo-hr',
	        'signing_secret' => env('WEBHOOK_CLIENT_SECRET_HR'),
	        'signature_header_name' => 'x-wc-webhook-signature',
	        'signature_validator' => \App\Webhooks\Incoming\WooCommerceSignatureValidator::class,
	        'webhook_profile' => \Spatie\WebhookClient\WebhookProfile\ProcessEverythingWebhookProfile::class,
	        'webhook_response' => \Spatie\WebhookClient\WebhookResponse\DefaultRespondsTo::class,
	        'webhook_model' => \Spatie\WebhookClient\Models\WebhookCall::class,
	        'process_webhook_job' => App\Jobs\CreateOrderFromWebhook::class,
        ],
        [
	        'name' => 'woo-de',
	        'signing_secret' => env('WEBHOOK_CLIENT_SECRET_DE'),
	        'signature_header_name' => 'x-wc-webhook-signature',
	        'signature_validator' => \App\Webhooks\Incoming\WooCommerceSignatureValidator::class,
	        'webhook_profile' => \Spatie\WebhookClient\WebhookProfile\ProcessEverythingWebhookProfile::class,
	        'webhook_response' => \Spatie\WebhookClient\WebhookResponse\DefaultRespondsTo::class,
	        'webhook_model' => \Spatie\WebhookClient\Models\WebhookCall::class,
	        'process_webhook_job' => App\Jobs\CreateOrderFromWebhook::class,
        ],
        [
	        'name' => 'woo-it',
	        'signing_secret' => env('WEBHOOK_CLIENT_SECRET_IT'),
	        'signature_header_name' => 'x-wc-webhook-signature',
	        'signature_validator' => \App\Webhooks\Incoming\WooCommerceSignatureValidator::class,
	        'webhook_profile' => \Spatie\WebhookClient\WebhookProfile\ProcessEverythingWebhookProfile::class,
	        'webhook_response' => \Spatie\WebhookClient\WebhookResponse\DefaultRespondsTo::class,
	        'webhook_model' => \Spatie\WebhookClient\Models\WebhookCall::class,
	        'process_webhook_job' => App\Jobs\CreateOrderFromWebhook::class,
        ],
     ],
];

Routes are defined:

// Webhooks for each market
Route::webhooks('webhook-receiving-url-sl', 'woo-sl');
Route::webhooks('webhook-receiving-url-hr', 'woo-hr');
Route::webhooks('webhook-receiving-url-de', 'woo-de');
Route::webhooks('webhook-receiving-url-it', 'woo-it');

And all webhook jobs are failing with this error: Spatie\WebhookClient\Exceptions\InvalidConfig: Could not find the configuration for `` in /var/www/metrics.popolnapostava.com/vendor/spatie/laravel-webhook-client/src/Exceptions/InvalidConfig.php:15

Error screenshot

I already executed commands: php artisan config:clear, cache:clear, routes:clear etc... it did not helped.

And enigma is this: If i run this code directly in artisan tinker:

$webhookConfig = app(Spatie\WebhookClient\WebhookConfigRepository::class)->getConfig('woo-de');

I get result back with config values. But during execution of webhook this same code returns null. I am lost from here what can be wrong.... Does anyone has an idea what is causing this error?

Webhooks Attribute not found

when using Route::webhooks('...', '...') i get an error like:
InvalidArgumentException Attribute [webhooks] does not exist.
and in the stack trace, the error is thrown on the web.php file

Question rather than issue

Hi I'm new to this package and I want to verify a header that does not have a signature key. It actually has a user and password, so when you receive the request at the url endpoint you need to verify that header. Im not sure about how to use custom verify signature because I don't understand it for my case.

Could someone help me up with this?

Thanks in advance

The signature is invalid.

Really excited to find this! Hope you can point out my error.

Mac OS 10.13.6
Laravel framework 5.8.35
Valet server using 'valet share' to create testing URL locally.

I'm testing locally using a github webhook. In webhook-client.php I have the following:

'signature_header_name' => 'X-Hub-Signature',

.env entry is (for testing):

WEBHOOK_CLIENT_SECRET=aCrazyMixedUpSecret

Github webhooks send headers to include the signature like this:

X-Hub-Signature: sha1=3fd37bf5a7bdd77c41c1c1954a83fb1936c10624

So, in the DefaultSignatureValidator.php class, I changed the isValid function to replace the sha1= part of the string and also set the algo parameter to be sha1 and logged it like:

public function isValid(Request $request, WebhookConfig $config): bool
{
    $signature = $request->header($config->signatureHeaderName);
    $signature = trim(str_replace("sha1=", "", $signature));

    if (! $signature) {
        return false;
    }

    $signingSecret = $config->signingSecret;

    if (empty($signingSecret)) {
        throw WebhookFailed::signingSecretNotSet();
    }

    logger(hash('sha1',$signingSecret));

    $computedSignature = hash_hmac('sha1', $signature, $signingSecret);
    logger($computedSignature);
    return hash_equals($signature, $computedSignature);
}

The log file shows that the 2 hashes are clearly different but I can't figure out why.

Here's the section in the log file showing the debug logger trace followed by the error and the top 3 lines in stacktrace.

[2019-09-04 19:56:47] local.DEBUG: 2875a4a6d743dd08f056b6af8fea43745cf29687  
[2019-09-04 19:56:47] local.DEBUG: da6e7ae92bb6611e7b6a4aec9e3a8a20e260b257  
[2019-09-04 19:56:47] local.ERROR: The signature is invalid. {"exception":"[object] (Spatie\\WebhookClient\\Exceptions\\WebhookFailed(code: 0): The signature is invalid. at /Users/apppath/vendor/spatie/laravel-webhook-client/src/Exceptions/WebhookFailed.php:11)
[stacktrace]
#0 /Users/apppath/vendor/spatie/laravel-webhook-client/src/WebhookProcessor.php(44): Spatie\\WebhookClient\\Exceptions\\WebhookFailed::invalidSignature()
#1 /Users/apppath/vendor/spatie/laravel-webhook-client/src/WebhookProcessor.php(28): Spatie\\WebhookClient\\WebhookProcessor->ensureValidSignature()
#2 /Users/apppath/vendor/spatie/laravel-webhook-client/src/WebhookController.php(11): Spatie\\WebhookClient\\WebhookProcessor->process()

Scratching my head. Anything you can point out that I might be doing wrong would be greatly appreciated.

[2020-05-13 11:36:29] local.ERROR: Typed property Spatie\WebhookClient\ProcessWebhookJob::$webhookCall must not be accessed before initialization {"exception":"[object] (Error(code: 0): Typed property Spatie\\WebhookClient\\ProcessWebhookJob::$webhookCall must not be accessed before initialization at

Hello Spatie team, I am using your package and really find it great, it works perfectly in laravel 6 , When I run from server client gives below error, all of my webhook calls throw this error, that is why I am a bit puzzled, what does this mean? How could I fix it? Missing something?

[2020-05-13 11:36:29] local.ERROR: Typed property Spatie\WebhookClient\ProcessWebhookJob::$webhookCall must not be accessed before initialization {"exception":"[object] (Error(code: 0): Typed property Spatie\WebhookClient\ProcessWebhookJob::$webhookCall must not be accessed before initialization at C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Queue\SerializesModels.php:133)
[stacktrace]
#0 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Queue\SerializesModels.php(133): ReflectionProperty->getValue(Object(App\Handler\WebHooksHandler))
#1 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Queue\SerializesModels.php(77): Spatie\WebhookClient\ProcessWebhookJob->getPropertyValue(Object(ReflectionProperty))
#2 [internal function]: Spatie\WebhookClient\ProcessWebhookJob->__serialize()
#3 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Queue\Queue.php(147): serialize(Object(App\Handler\WebHooksHandler))
#4 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Queue\Queue.php(116): Illuminate\Queue\Queue->createObjectPayload(Object(App\Handler\WebHooksHandler), NULL)
#5 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Queue\Queue.php(94): Illuminate\Queue\Queue->createPayloadArray(Object(App\Handler\WebHooksHandler), NULL, '')
#6 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Queue\SyncQueue.php(38): Illuminate\Queue\Queue->createPayload(Object(App\Handler\WebHooksHandler), NULL, '')
#7 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(182): Illuminate\Queue\SyncQueue->push(Object(App\Handler\WebHooksHandler))
#8 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(158): Illuminate\Bus\Dispatcher->pushCommandToQueue(Object(Illuminate\Queue\SyncQueue), Object(App\Handler\WebHooksHandler))
#9 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(73): Illuminate\Bus\Dispatcher->dispatchToQueue(Object(App\Handler\WebHooksHandler))
#10 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Foundation\Bus\PendingDispatch.php(134): Illuminate\Bus\Dispatcher->dispatch(Object(App\Handler\WebHooksHandler))
#11 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Foundation\helpers.php(391): Illuminate\Foundation\Bus\PendingDispatch->__destruct()
#12 C:\inetpub\wwwroot\ableauth\vendor\spatie\laravel-webhook-client\src\WebhookProcessor.php(62): dispatch(Object(App\Handler\WebHooksHandler))
#13 C:\inetpub\wwwroot\ableauth\vendor\spatie\laravel-webhook-client\src\WebhookProcessor.php(34): Spatie\WebhookClient\WebhookProcessor->processWebhook(Object(Spatie\WebhookClient\Models\WebhookCall))
#14 C:\inetpub\wwwroot\ableauth\vendor\spatie\laravel-webhook-client\src\WebhookController.php(11): Spatie\WebhookClient\WebhookProcessor->process()
#15 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php(48): Spatie\WebhookClient\WebhookController->__invoke(Object(Illuminate\Http\Request), Object(Spatie\WebhookClient\WebhookConfig))
#16 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Routing\Route.php(239): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Spatie\WebhookClient\WebhookController), '__invoke')
#17 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Routing\Route.php(196): Illuminate\Routing\Route->runController()
#18 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Routing\Router.php(685): Illuminate\Routing\Route->run()
#19 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(128): Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#20 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Routing\Middleware\SubstituteBindings.php(41): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#21 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Routing\Middleware\SubstituteBindings->handle(Object(Illuminate\Http\Request), Object(Closure))
#22 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken.php(76): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#23 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))
#24 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\View\Middleware\ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#25 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#26 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#27 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php(62): Illuminate\Session\Middleware\StartSession->handleStatefulRequest(Object(Illuminate\Http\Request), Object(Illuminate\Session\Store), Object(Closure))
#28 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#29 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#30 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#31 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\EncryptCookies.php(66): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#32 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
#33 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#34 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Routing\Router.php(687): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#35 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Routing\Router.php(662): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#36 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Routing\Router.php(628): Illuminate\Routing\Router->runRoute(Object(Illuminate\Http\Request), Object(Illuminate\Routing\Route))
#37 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Routing\Router.php(617): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#38 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(165): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#39 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(128): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))
#40 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#41 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))
#42 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#43 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))
#44 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\ValidatePostSize.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#45 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle(Object(Illuminate\Http\Request), Object(Closure))
#46 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode.php(63): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#47 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#48 C:\inetpub\wwwroot\ableauth\vendor\fruitcake\laravel-cors\src\HandleCors.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#49 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Fruitcake\Cors\HandleCors->handle(Object(Illuminate\Http\Request), Object(Closure))
#50 C:\inetpub\wwwroot\ableauth\vendor\fideloper\proxy\src\TrustProxies.php(57): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#51 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Fideloper\Proxy\TrustProxies->handle(Object(Illuminate\Http\Request), Object(Closure))
#52 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#53 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(140): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#54 C:\inetpub\wwwroot\ableauth\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(109): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#55 C:\inetpub\wwwroot\ableauth\public\index.php(55): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#56 {main}
"}

Custom response

We've been using the Webhook Client and it's been working great! However, we just ran into a case where the response from the webhook controller needs to be XML with some static content.

Specifically, we are using Twilio and when an inbound SMS is received, we just need to respond with content type text/xml and the body <Response></Response>.

Any way to customize this?

Thanks for the great work!

Error handling could be more precise

Thanks for a package I'm enjoying sinking my teeth into.

I forgot to rerun my migrations so the web calls database was AWOL. What I got was an "Invalid Signature" error, so I naturally spent a while debugging the signature config and secret. It was not until I commented out the throw WebhookFailed::invalidSignature(); in WebhookProcessor.php that I got a missing table error, which obviously had nothing to do with the signature being invalid. Once I ran my migrations my signature was fine and all worked as intended.

Might be worth differentiating signature errors from other errors?

Make work with no header...

Hey,

Im happy to do a PR but thought Id check first...

I have a need to setup webhooks from a third part app. But as its a third party sending the data I cant control how and if they send headers.

I tried setting up a SignatureValidator which just returns true, but the package rejects empty headers early.

How do you feel about integrating the signature check into the validator? That way a custom validator would have full control over that process, and would enable people to avoid headers altogether if desired.

Thanks for another amazing package!!! Ill be sending postcards very soon when I launch :)

Lee

Ability to handle multiple jobs

Hi there,

Thanks for the awesome package. I have been using it and love it.
1 think that I think it would be good to have is the ability to trigger multiple jobs.

My use case is: I have a incoming webhook from Postmark and it needs to be handled in 2 separated jobs. I end up with creating 1 job to recieve the incoming webhook, then dispatch 2 jobs to do what I need.

Cheers,

small Docs on WebhookCall

can you please create a small doc for WebhookCall? like for example how to access the request content... i'm currently using $this->webhookCall->getAttribute('payload') and then accessing the response field using arrays, but i don't know if it is the way it should be accessed

Without validation

Hello @freekmurze,

I was wondering if you think it would make sense to allow the validator to be null for completely unvalidated webhooks.

I know it's not recommended, but some services don't offer webhooks with signatures or other signing methods.

I'm adding a custom validator that simply returns true for these services atm.

If you would consider this a worthy change, can would prepare a PR for your consideration.

Cheers,
Peter

Could not find the configuration for ``

Hello,

I have an api with dingo, install laravel-webhook-client but in the tests I get the following error:

{
    "message": "Could not find the configuration for ``",
    "status_code": 500
}

URL: api.site.test
Routes: api.php

Route::webhooks('/webhook/listener/conekta', 'webhook_listener_conekta');

$api = app(Router::class);

$api->version('v1', [
    'namespace' => 'App\Http\Controllers\API\V1',
    'middleware' => 'api.auth',
], function ($api) {
    $api->post('/orders', 'OrdersController@create');
});

webhook-client.php

...
    'configs' => [
        [
            'name' => 'webhook_listener_conekta',
            'signing_secret' => env('GW_CONEKTA_WEBHOOK_SK'),
            'signature_header_name' => 'Digest',
            'signature_validator' => \App\Gateways\Services\OpenPay\WebhookSignatureValidator::class,
            'webhook_profile' => \App\Gateways\Services\OpenPay\ProcessEverythingWebhookProfile::class,
            'process_webhook_job' => '',
        ],
...

Using Postman to test webhook

This really isn't an issue but more of a question that I have no idea where to turn to and google is failing me right now. I'm trying to use Postman to test my webhook on a Laravel application and I'm trying to get away with not setting up the webhook-server. I got the client all setup but I keep getting the error "signature is invalid" in Postman. I have the env set with a WEBHOOK_CLIENT_SECRET and the handler but everything else is set to the defaults of the config provided. I've tried quite a few different "authorization" options in Postman. I saw someone created a customed signature to get around it if the env is staging or local. I was trying to get away from that if I could.

I know this is out of scope of the package. I am just kind of not sure where to go for answers on this.

Compressed payloads

What do you think of adding an option to compress payloads when saving them to a database? Payloads can grow quite large, and since it's all JSON data I figure there's lots to gain from compressing the data.

RestClient::Exceptions::ReadTimeout

I'm having trouble receiving a webhook with the following error in response: "RestClient :: Exceptions :: ReadTimeout: Timed out reading data from server". How can I solve this? Can you help me?

Error installing composer require spatie/laravel-webhook-client

I'm trying to install this package in a Lumen project.
composer require spatie/laravel-webhook-client

But I'm getting the error;

  [InvalidArgumentException]                                                                                           
  Package spatie/laravel-webhook-client at version  has a PHP requirement incompatible with your PHP version (7.1.23)  

My composer.json;

{
"name": "laravel/lumen",
"description": "The Laravel Lumen Framework.",
"keywords": ["framework", "laravel", "lumen"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=7.1.3",
"dusterio/lumen-passport": "^0.2.15",
"laravel/lumen-framework": "5.8.*"
},
"require-dev": {
"fzaninotto/faker": "^1.4",
"phpunit/phpunit": "^7.0",
"mockery/mockery": "^1.0"
},
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/"
]
},
"scripts": {
"post-root-package-install": [
"@php -r "file_exists('.env') || copy('.env.example', '.env');""
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
},
"minimum-stability": "dev",
"prefer-stable": true
}

Spatie\WebhookClient\Exceptions\InvalidConfig: `app\Classes\MailGunValidator` is not a valid signature validator class.

I have created a new class to validate the signature and placed it in app\Classes\MailGunValidator
In config/webhook-client.php I have

'signature_validator' => \app\Classes\MailGunValidator::class,

My valildator class is:

`<?php

namespace App\Classes;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
//use Spatie\WebhookClient\SignatureValidator\SignatureValidator;
use Spatie\WebhookClient\WebhookConfig;

class MailGunValidator implements \Spatie\WebhookClient\SignatureValidator\SignatureValidator
{
public function isValid(Request $request, WebhookConfig $config): bool
{
$secret = config('webhook-client.signing_secret');
$timestamp = $request->header('timestamp');
$token = $request->header('token');
$signature = $request->header('signature');
$compareTo = hash_hmac('sha256',$timestamp.$token,$secret);
Log::info('IsValid:'. $signature."\n".$compareTo);
return hash_equals($signature,$compareTo);
}
}
`
Why is the package not recognizing my class as implementing the SignatureValidator?

Accepting Webhooks without Signatures

Love this package, however I am using it to connect to multiple CRMs for fulfillment, and some do not provide a signature in the header. Is there a way to conditionally remove the signature requirement? Could this be added to the webhook-client.php file?

Could not find the configuration for `default`

I am getting the following error:
Spatie\WebhookClient\Exceptions\InvalidConfig: Could not find the configuration for default in file /var/www/html/vendor/spatie/laravel-webhook-client/src/Exceptions/InvalidConfig.php on line 14

This is the configuration file /config/webhook-client.php

return [ 'configs' => [ [ 'name' => 'default', 'signing_secret' => env('WEBHOOK_CLIENT_SECRET'), 'signature_header_name' => 'Signature', 'signature_validator' => \Spatie\WebhookClient\SignatureValidator\DefaultSignatureValidator::class, 'webhook_profile' => \Spatie\WebhookClient\WebhookProfile\ProcessEverythingWebhookProfile::class, 'webhook_model' => \Spatie\WebhookClient\Models\WebhookCall::class, 'process_webhook_job' => App\Handler\ProcessWebhook::class, ], ], ];

url string query signatures

My impression is that currently this package cannot validate signatures sent in the url string, only in the POST header (which is of course good practice). Some APIs, like Mailchimp, seem to only provide for url signatures.

I am customising the package to allow for this but before I commit and do a tested PR as a contribution, I wanted to check I am not making this up? Would this functionality be a desirable addition to the package, or is it better as a personal fork? Or does it already exist and I missed it?

Thanks again

Jira API signing_secret ?

I'm working on Jira API Webhooks but it seems that they don't offer signing_secret for their webhooks . So is it mandatory to process the calls ?

Set response on webhook request error?

I am willing to PR this if needed but I would like to have access to the response even when the webhook call has failed. Guzzle RequestException exceptions have a getResponse method which allows you to get this.

Current code CallWebhookJob

try {
    $this->response = $client->request(...);

   ...
} catch (Exception $exception) {
    /** @var \Spatie\WebhookServer\BackoffStrategy\BackoffStrategy $backoffStrategy */
    $backoffStrategy = app($this->backoffStrategyClass);

    $waitInSeconds = $backoffStrategy->waitInSecondsAfterAttempt($this->attempts());

    $this->dispatchEvent(WebhookCallFailedEvent::class);

    $this->release($waitInSeconds);
}

Proposed change to CallWebhookJob?
Detect if exception is a RequestException and set the response.

try {
    $this->response = $client->request(...);

   ...
} catch (Exception $exception) {
    
    if ($exception instanceof GuzzleHttp\Exception\RequestException) {
        $this->response = $exception->getResponse();
    }

  ...
}

Issue with invalidProcessWebhookJob

Howdy, I am getting this and cannot seem to resolve it.

Argument 1 passed to Spatie\WebhookClient\Exceptions\InvalidConfig::invalidProcessWebhookJob() must be of the type string, null given, called in /shared/httpd/yccv7/vendor/spatie/laravel-webhook-client/src/WebhookConfig.php on line 56 at /shared/httpd/yccv7/vendor/spatie/laravel-webhook-client/src/Exceptions/InvalidConfig.php:39)

I am using Laravel 7, Cashier 10.7.1, and the stripe webhooks package. When I get a response from the Stripe CLI forwarding over to the website, I get the above. If I send it to the normal Laravel Cashier routes, everything is fine and I get a 200 OK. I am not using a custom job, I am just trying to use the default "\Spatie\StripeWebhooks\ProcessStripeWebhookJob::class," model.

webhook not working in 2.3.0

"message": "`` is not a valid process webhook job class. A valid class should implement `Spatie\\WebhookClient\\ProcessWebhookJob`.",
"exception": "Spatie\\WebhookClient\\Exceptions\\InvalidConfig",
"file": "/var/www/html/equity-backend/vendor/spatie/laravel-webhook-client/src/Exceptions/InvalidConfig.php",
"line": 35,

it's shows this error. works fine with v2.2.0

Please fix the problem ASAP :)

InvalidConfig

Spatie\WebhookClient\Exceptions\InvalidConfig
`App\Jobs\WooCommerce\ProcessWebhookJob` is not a valid process webhook job class. A valid class should implement `Spatie\WebhookClient\ProcessWebhookJob`.
http://127.0.0.1:8000/api/webhook-receiving-url

webhook-client.php:
'process_webhook_job' => app\Jobs\WooCommerce\ProcessWebhookJob::class,
ProcessWebhookJob.php:

namespace App\Jobs;

use App\Category;
use \Spatie\WebhookClient\ProcessWebhookJob as SpatieProcessWebhookJob;

class ProcessWebhookJob extends SpatieProcessWebhookJob
{
    public function handle()
    {
        // $this->webhookCall // contains an instance of `WebhookCall`
        $payload = json_decode($this->webhookCall->payload);
        // do stuff
    }
}

Route::webHooks(..) not correctly named

Hi, in your documentation you say that Route::webHooks(..) should be called, but your code registers a macro webhooks. (without capital H). I wasn't sure if your documentation or your code is wrong, so I didnt do a PR.

This issue causes an exception

{"exception":"[object] (InvalidArgumentException(code: 0): Attribute [webHooks] does not exist. at /Users/cor/Code/docker-webhook/vendor/laravel/framework/src/Illuminate/Routing/RouteRegistrar.php:94)

error bootServices

 "message": "Call to undefined method Spatie\\WebhookClient\\WebhookController::bootServices()",
    "exception": "Error",

Customize response

Hi, it is possible to customize the error response to invalid signature? Instead of 500 I will customize it to 401, like for Xero accounting app.

Empty webhookCall when processing job with redis

The webhook_calls table gets succesfully filled with the name and payload and the job is also gets dispatched by Redis. But when I log::debug $this->webhookCall inside the job and check the logs it is empty.

edit: fixed it by removing line
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
inside the job

Exception raised when added a crontab entry

Hallo everyone,
OSx catalina 10.15.4,
PHP 7.4.4,
Laravel (framework 7.9.2) fresh installation, only laravel-webhook-client package installed,
crontab entry: * * * * * cd /Library/WebServer/Documents/Foo/Bar && php artisan schedule:run >> /dev/null 2>&1

Adding the previous line to crontab to let the scheduler run, even if there is no instruction in the function schedule in the file Console/Kernel.php, the following error is raised anytime cron launches the schedule (in this case every minute, two tries and then i stopped cron).
No errors if php artisan schedule:run is launched directly from terminal, and no problems at all with the package functionalities (i can receive webhooks properly).

[2020-05-03 07:23:01] local.ERROR: syntax error, unexpected '$url' (T_VARIABLE), expecting ')' {"exception":"[object] (ParseError(code: 0): syntax error, unexpected '$url' (T_VARIABLE), expecting ')' at /Library/WebServer/Documents/IIC/FakeWebhook/vendor/spatie/laravel-webhook-client/src/WebhookClientServiceProvider.php:28)
[stacktrace]
#0 /Library/WebServer/Documents/IIC/FakeWebhook/vendor/composer/ClassLoader.php(322): Composer\Autoload\includeFile('/Library/WebSer...')
#1 [internal function]: Composer\Autoload\ClassLoader->loadClass('Spatie\\WebhookC...')
#2 /Library/WebServer/Documents/IIC/FakeWebhook/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(690): spl_autoload_call('Spatie\\WebhookC...')
#3 /Library/WebServer/Documents/IIC/FakeWebhook/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(624): Illuminate\Foundation\Application->resolveProvider('Spatie\\WebhookC...')
#4 /Library/WebServer/Documents/IIC/FakeWebhook/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php(75): Illuminate\Foundation\Application->register('Spatie\\WebhookC...')
#5 /Library/WebServer/Documents/IIC/FakeWebhook/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(604): Illuminate\Foundation\ProviderRepository->load(Array)
#6 /Library/WebServer/Documents/IIC/FakeWebhook/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/RegisterProviders.php(17): Illuminate\Foundation\Application->registerConfiguredProviders()
#7 /Library/WebServer/Documents/IIC/FakeWebhook/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(230): Illuminate\Foundation\Bootstrap\RegisterProviders->bootstrap(Object(Illuminate\Foundation\Application))
#8 /Library/WebServer/Documents/IIC/FakeWebhook/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(310): Illuminate\Foundation\Application->bootstrapWith(Array)
#9 /Library/WebServer/Documents/IIC/FakeWebhook/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(127): Illuminate\Foundation\Console\Kernel->bootstrap()
#10 /Library/WebServer/Documents/IIC/FakeWebhook/artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#11 {main}
"}
[2020-05-03 07:24:00] local.ERROR: syntax error, unexpected '$url' (T_VARIABLE), expecting ')' {"exception":"[object] (ParseError(code: 0): syntax error, unexpected '$url' (T_VARIABLE), expecting ')' at /Library/WebServer/Documents/IIC/FakeWebhook/vendor/spatie/laravel-webhook-client/src/WebhookClientServiceProvider.php:28)
[stacktrace]
#0 /Library/WebServer/Documents/IIC/FakeWebhook/vendor/composer/ClassLoader.php(322): Composer\Autoload\includeFile('/Library/WebSer...')
#1 [internal function]: Composer\Autoload\ClassLoader->loadClass('Spatie\\WebhookC...')
#2 /Library/WebServer/Documents/IIC/FakeWebhook/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(690): spl_autoload_call('Spatie\\WebhookC...')
#3 /Library/WebServer/Documents/IIC/FakeWebhook/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(624): Illuminate\Foundation\Application->resolveProvider('Spatie\\WebhookC...')
#4 /Library/WebServer/Documents/IIC/FakeWebhook/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php(75): Illuminate\Foundation\Application->register('Spatie\\WebhookC...')
#5 /Library/WebServer/Documents/IIC/FakeWebhook/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(604): Illuminate\Foundation\ProviderRepository->load(Array)
#6 /Library/WebServer/Documents/IIC/FakeWebhook/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/RegisterProviders.php(17): Illuminate\Foundation\Application->registerConfiguredProviders()
#7 /Library/WebServer/Documents/IIC/FakeWebhook/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(230): Illuminate\Foundation\Bootstrap\RegisterProviders->bootstrap(Object(Illuminate\Foundation\Application))
#8 /Library/WebServer/Documents/IIC/FakeWebhook/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(310): Illuminate\Foundation\Application->bootstrapWith(Array)
#9 /Library/WebServer/Documents/IIC/FakeWebhook/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(127): Illuminate\Foundation\Console\Kernel->bootstrap()
#10 /Library/WebServer/Documents/IIC/FakeWebhook/artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#11 {main}
"}

I think it's worth an investigation :)

Thank you All,
Andrea

is not a valid process webhook job class

Spatie\WebhookClient\Exceptions\InvalidConfig: App\Handler\WebhookHandler is not a valid process webhook job class. A valid class should implement Spatie\WebhookClient\ProcessWebhookJob. in file /Users/janarpalk/Projects/forexbook/vendor/spatie/laravel-webhook-client/src/Exceptions/InvalidConfig.php on line 35

Within webhook-client.php:
'process_webhook_job' => App\Handler\WebhookHandler::class,

Within WebhookHandler.php:


namespace App\Handler;

use Spatie\WebhookClient\ProcessWebhookJob;

class WehbhookHandler extends ProcessWebhookJob {
    public function handle() {
        Log::debug('test');
        Log::debug($this->webhookCall);
    }
}

uh?

pass data from validation to Job

Stripe for example use a Event constructor in order to validate the request: if the construction doesn't throw an exception, the validation is positive, otherwise the request is not valid. But at the moment, i need to requild the event inside the job. Is there any way to pass the evet from the validation to the job in order to not rebuild it ?

Base Table or View not found

I received a request from the server. But error occurred. Base table or view not found: 1146 Table 'image-gallery.webhook_calls'.I have configued the client to use DB_DATABASE=webhook-client. but it is using webhook server database..Please help..

Change to Signature Validation

Is there any way of altering the behaviour, to validate the signature differently?

The system I am integrating with creates the signature based on other data it sends back, so I need to validate against the password I send to them, and the airbillnumber they respond with;

This is calculated by adding the API Key used and the returned airbill number and hashing with MD5
signature = MD5 (password + airbillnumber)

Many thanks!

No query results for model [Spatie\WebhookClient\Models\WebhookCall]

Hello Spatie team, I am using your package and really find it great, works perfectly, thing is when I run it in my MacBook I don't get any issues, but when I deploy to production, some of my webhook calls throw this error, not all of them, that is why I am a bit puzzled, what does this mean? How could I fix it? Missing something?

No query results for model? But my webhook_calls table gets filled and emptied.. How can i find the problem here?

Illuminate\Database\Eloquent\ModelNotFoundException: No query results for model [Spatie\WebhookClient\Models\WebhookCall]. in /webstore/api/releases/v-1.1.2/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:470

Stack trace:
#0 /webstore/api/releases/v-1.1.2/vendor/laravel/framework/src/Illuminate/Queue/SerializesAndRestoresModelIdentifiers.php(102): Illuminate\Database\Eloquent\Builder->firstOrFail()
#1 /webstore/api/releases/v-1.1.2/vendor/laravel/framework/src/Illuminate/Queue/SerializesAndRestoresModelIdentifiers.php(57): Spatie\WebhookClient\ProcessWebhookJob->restoreModel(Object(Illuminate\Contracts\Database\ModelIdentifier))
#2 /webstore/api/releases/v-1.1.2/vendor/laravel/framework/src/Illuminate/Queue/SerializesModels.php(45): Spatie\WebhookClient\ProcessWebhookJob->getRestoredPropertyValue(Object(Illuminate\Contracts\Database\ModelIdentifier))
#3 [internal function]: Spatie\WebhookClient\ProcessWebhookJob->__wakeup()
#4 /webstore/api/releases/v-1.1.2/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(53): unserialize('O:35:"Infrastru...')
#5 /webstore/api/releases/v-1.1.2/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(88): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\RedisJob), Array)
#6 /webstore/api/releases/v-1.1.2/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(368): Illuminate\Queue\Jobs\Job->fire()
#7 /webstore/api/releases/v-1.1.2/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(314): Illuminate\Queue\Worker->process('redis', Object(Illuminate\Queue\Jobs\RedisJob), Object(Illuminate\Queue\WorkerOptions))
#8 /webstore/api/releases/v-1.1.2/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(134): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\RedisJob), 'redis', Object(Illuminate\Queue\WorkerOptions))
#9 /webstore/api/releases/v-1.1.2/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(112): Illuminate\Queue\Worker->daemon('redis', 'default,priorit...', Object(Illuminate\Queue\WorkerOptions))
#10 /webstore/api/releases/v-1.1.2/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(96): Illuminate\Queue\Console\WorkCommand->runWorker('redis', 'default,priorit...')
#11 /webstore/api/releases/v-1.1.2/vendor/laravel/horizon/src/Console/WorkCommand.php(46): Illuminate\Queue\Console\WorkCommand->handle()
#12 [internal function]: Laravel\Horizon\Console\WorkCommand->handle()
#13 /webstore/api/releases/v-1.1.2/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(32): call_user_func_array(Array, Array)
#14 /webstore/api/releases/v-1.1.2/vendor/laravel/framework/src/Illuminate/Container/Util.php(36): Illuminate\Container\BoundMethod::Illuminate\Container{closure}()
#15 /webstore/api/releases/v-1.1.2/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): Illuminate\Container\Util::unwrapIfClosure(Object(Closure))
#16 /webstore/api/releases/v-1.1.2/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#17 /webstore/api/releases/v-1.1.2/vendor/laravel/framework/src/Illuminate/Container/Container.php(590): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#18 /webstore/api/releases/v-1.1.2/vendor/laravel/framework/src/Illuminate/Console/Command.php(134): Illuminate\Container\Container->call(Array)
#19 /webstore/api/releases/v-1.1.2/vendor/symfony/console/Command/Command.php(255): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#20 /webstore/api/releases/v-1.1.2/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#21 /webstore/api/releases/v-1.1.2/vendor/symfony/console/Application.php(1012): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 /webstore/api/releases/v-1.1.2/vendor/symfony/console/Application.php(272): Symfony\Component\Console\Application->doRunCommand(Object(Laravel\Horizon\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 /webstore/api/releases/v-1.1.2/vendor/symfony/console/Application.php(148): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#24 /webstore/api/releases/v-1.1.2/vendor/laravel/framework/src/Illuminate/Console/Application.php(93): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 /webstore/api/releases/v-1.1.2/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(131): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#26 /webstore/api/releases/v-1.1.2/artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#27 {main}

syntax error, unexpected '$url' (T_VARIABLE), expecting ')'

Hello, I've got syntax error after fresh install on laravel app for woocommerce webhook handle. Here is what I get:

Symfony\Component\Debug\Exception\FatalThrowableError
syntax error, unexpected '$url' (T_VARIABLE), expecting ')'
::Composer\Autoload\includeFile:28
vendor/spatie/laravel-webhook-client/src/WebhookClientServiceProvider.php:28

And the line is:
Route::macro('webhooks', fn(string $url, string $name = 'default') => Route::post($url, '\Spatie\WebhookClient\WebhookController')->name("webhook-client-{$name}"));

Spatie\WebhookClient\Exceptions\InvalidConfig: App\Jobs\ProcessPayment is not a valid process webhook job class.

Config:

[
    'name' => 'stripe',
    'signing_secret' => env('STRIPE_WEBHOOK_SECRET'),
    'signature_header_name' => 'Stripe-Signature',
    'signature_validator' => \App\SignatureValidators\Stripe::class,
    'webhook_profile' => \Spatie\WebhookClient\WebhookProfile\ProcessEverythingWebhookProfile::class,
    'webhook_model' => \Spatie\WebhookClient\Models\WebhookCall::class,
    'process_webhook_job' => \App\Jobs\ProcessPayment\Stripe::class,
],

Class:

<?php

namespace App\Jobs\ProcessPayment;

use \Spatie\WebhookClient\ProcessWebhookJob;

class Stripe extends ProcessWebhookJob
{
    public function handle()
    {
        $data = $this->webhookCall->payload;
    }
}

Error:

Spatie\WebhookClient\Exceptions\InvalidConfig: `App\Jobs\ProcessPaymenst\Stripe` is not a valid process webhook job class. A valid class should implement `Spatie\WebhookClient\ProcessWebhookJob`.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.