PHP code example of cboxdk / laravel-webhook-signature

1. Go to this page and download the library: Download cboxdk/laravel-webhook-signature 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/ */

    

cboxdk / laravel-webhook-signature example snippets


// config/webhook-signature.php
'endpoints' => [
    'github' => ['scheme' => 'github', 'secrets' => [env('GITHUB_WEBHOOK_SECRET')]],
],

Route::post('/webhooks/github', GithubController::class)
    ->middleware('webhook.signature:github');

$webhook = VerifiedWebhook::fromRequestOrFail($request);

$webhook->json();               // the payload that was actually signed
$webhook->idempotencyKey();     // the provider's event id
$webhook->secretId;             // which secret verified — watch this during a rotation

Http::webhookSignature('outbound')->post($subscriber->url, $payload);

$this->fakeWebhookEndpoint('github', 'github', 'test-secret');

$this->postSignedWebhook('/webhooks/github', 'github', ['action' => 'opened'])->assertOk();
$this->postUnsignedWebhook('/webhooks/github', ['action' => 'opened'])->assertUnauthorized();