PHP code example of goldnead / statamic-webhook-manager
1. Go to this page and download the library: Download goldnead/statamic-webhook-manager 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/ */
goldnead / statamic-webhook-manager example snippets
// config/webhook-manager.php
'storage' => [
'driver' => env('WEBHOOK_MANAGER_DRIVER', 'eloquent'), // 'eloquent' | 'flat'
'flat' => [
'path' => env('WEBHOOK_MANAGER_FLAT_PATH', base_path('content/webhooks')),
],
],
// config/webhook-manager.php
'inbound' => [
'rate_limit_per_minute' => 60, // 0 disables throttling
],
use Goldnead\WebhookManager\Facades\WebhookManager;
WebhookManager::registerTrigger(new MyCustomTrigger());
WebhookManager::registerCondition(new MyCustomCondition());
WebhookManager::registerAction(new MyCustomAction());
WebhookManager::registerAuthScheme(new MyCustomAuthScheme());
WebhookManager::registerVariableResolver(new MyCustomResolver());
WebhookManager::registerSuccessEvaluator(new MyCustomEvaluator());
'event_triggers' => [
'order.shipped' => [
'event' => \App\Events\OrderShipped::class, // FQCN to listen for ( // optional, default "event"
'description' => 'Fires when an order ships', // optional
// Optional payload mapper: Closure, invokable class-string, or [class, method].
// Omit it to serialise the event via toArray()/public properties.
'payload' => \App\Webhooks\OrderShippedPayload::class,
],
],
class OrderShippedPayload
{
public function __invoke(\App\Events\OrderShipped $event): array
{
return ['id' => $event->order->id, 'total' => $event->order->total];
}
}
use Goldnead\WebhookManager\Facades\WebhookManager;
WebhookManager::registerEventTrigger(\App\Events\OrderShipped::class, [
'handle' => 'order.shipped',
'label' => 'Order — shipped',
'source_type' => 'order',
'payload' => fn (\App\Events\OrderShipped $e) => ['id' => $e->order->id],
]);
use Goldnead\WebhookManager\Facades\WebhookLog;
WebhookLog::forSubject('payment', $payment->id); // Collection<Delivery>, newest first
WebhookLog::forSubject('payment', $payment->id, 5); // limit
WebhookLog::countForSubject('payment', $payment->id); // int
WebhookLog::subjectTypes(); // configured type handles
bash
php artisan webhook-manager:storage:migrate --from=eloquent --to=flat --dry-run
php artisan webhook-manager:storage:migrate --from=eloquent --to=flat