PHP code example of bambamboole / laravel-webhooks
1. Go to this page and download the library: Download bambamboole/laravel-webhooks 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/ */
bambamboole / laravel-webhooks example snippets
use Bambamboole\LaravelWebhooks\Attributes\WebhookEvent;
#[WebhookEvent(
name: 'invoice.paid',
title: 'Invoice paid',
summary: 'Sent when an invoice is paid.',
tags: ['billing'],
)]
final class InvoicePaid
{
public function __construct(public int $invoiceId, public int $amount) {}
/**
* @return array{invoiceId:int, amount:int}
*/
public function webhookPayload(): array
{
return [
'invoiceId' => $this->invoiceId,
'amount' => $this->amount,
];
}
/**
* @return array{self:string}
*/
public function webhookLinks(): array
{
return [
'self' => route('api.invoices.show', $this->invoiceId),
];
}
}
use Bambamboole\LaravelWebhooks\WebhookSubscription;
use Bambamboole\LaravelWebhooks\WebhookSubscriptionRepository;
final class CustomWebhookSubscriptionRepository implements WebhookSubscriptionRepository
{
public function forEvent(string $eventName, object $event): iterable
{
yield new WebhookSubscription(
url: 'https://example.com/webhooks',
secret: 'signing-secret',
headers: ['X-Webhook-Source' => 'app'],
id: 'subscription-123',
);
}
}
use Bambamboole\LaravelWebhooks\DispatchWebhookEvent;
use Illuminate\Support\Facades\Event;
Event::listen(InvoicePaid::class, DispatchWebhookEvent::class);
use Bambamboole\LaravelWebhooks\Models\WebhookDelivery;
WebhookDelivery::where('status', WebhookDelivery::STATUS_FAILED)->latest()->get();
$delivery->subscription; // the WebhookSubscription it was delivered to, if any