PHP code example of spatie / laravel-webhook-client
1. Go to this page and download the library: Download spatie/laravel-webhook-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
spatie / laravel-webhook-client example snippets
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,
];
use Illuminate\Http\Request;
use Spatie\WebhookClient\WebhookConfig;
interface SignatureValidator
{
public function isValid(Request $request, WebhookConfig $config): bool;
}
namespace Spatie\WebhookClient\WebhookProfile;
use Illuminate\Http\Request;
interface WebhookProfile
{
public function shouldProcess(Request $request): bool;
}
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
}
}
namespace Spatie\WebhookClient\WebhookResponse;
use Illuminate\Http\Request;
use Spatie\WebhookClient\WebhookConfig;
interface RespondsToWebhook
{
public function respondToValidWebhook(Request $request, WebhookConfig $config);
}
use Illuminate\Support\Facades\Schedule;
use Spatie\WebhookClient\Models\WebhookCall;
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();