Webhooks
Webhooks
Vatly sends webhooks to notify your application of events like subscription starts, cancellations, and payment updates. Vatly Laravel handles webhook verification, storage, and event dispatching automatically.
Endpoint
The package registers a webhook endpoint at:
POST /webhooks/vatly
Configure this URL in your Vatly dashboard. Make sure to set your VATLY_WEBHOOK_SECRET in .env.
CSRF protection
Exclude the webhook route from CSRF verification. In Laravel 11+, this is typically done in bootstrap/app.php:
->withMiddleware(function (Middleware $middleware) {
$middleware->validateCsrfTokens(except: [
'webhooks/vatly',
]);
})
Events
When a webhook is received, Vatly Laravel dispatches typed events that you can listen to:
| Event | Description |
|---|---|
WebhookReceived | Raw webhook received (dispatched for every webhook) |
SubscriptionStarted | A new subscription was activated |
SubscriptionCanceledImmediately | Subscription was canceled and ended immediately |
SubscriptionCanceledWithGracePeriod | Subscription was canceled but remains active until ends_at |
Built-in listeners
The package includes listeners that automatically handle subscription lifecycle events:
StartSubscriptionListener-- Creates a localSubscriptionmodel when a subscription startsCancelSubscriptionImmediatelyListener-- Setsends_atto now when immediately canceledCancelSubscriptionWithGracePeriodListener-- Setsends_atto the grace period end date
Custom listeners
Listen for Vatly events in your EventServiceProvider or using the Event facade:
use Vatly\Laravel\Events\SubscriptionStarted;
Event::listen(SubscriptionStarted::class, function (SubscriptionStarted $event) {
// $event->subscriptionId
// $event->planId
// $event->name
// $event->quantity
// Send welcome email, provision features, etc.
});
Webhook call storage
Every webhook is recorded in the vatly_webhook_calls table with:
event_name-- The webhook event typeresource_id-- The Vatly resource IDresource_name-- The resource type (e.g., "subscription")vatly_customer_id-- The associated customer IDobject-- The full webhook payload (JSON)raised_at-- When the event occurred at Vatlytestmode-- Whether this was a test webhook