spatie/laravel-stripe-webhooks
Laravel package to handle Stripe webhooks: verifies Stripe signatures, logs valid calls to the database, and dispatches configurable jobs or events per webhook type. Provides the plumbing for receiving and validating webhooks; you implement the business logic.
Stripe\Event objects) for richer business logic.webhook_calls table prevents duplicate processing, critical for financial transactions.verify_signature in dev (as recommended) introduces risk of malicious webhook spoofing. Must enforce strict signing in production.customer.created). The payload column in the webhook_calls table uses text, but custom models might need adjustments for very large data.Queue Strategy:
Error Handling:
WebhookFailed exceptions or job failures? (e.g., Laravel Horizon, Sentry)Testing:
Scaling:
webhook_calls table (e.g., by tenant or date) for large-scale deployments?Multi-Environment:
Compliance:
webhook_calls table?webhook_calls table, ensuring consistency with the app’s database schema.Assessment Phase:
payment_intent.succeeded, invoice.payment_failed) to prioritize in the migration.Setup:
composer require spatie/laravel-stripe-webhooks
php artisan vendor:publish --provider="Spatie\StripeWebhooks\StripeWebhooksServiceProvider"
php artisan vendor:publish --provider="Spatie\WebhookClient\WebhookClientServiceProvider" --tag="webhook-client-migrations"
php artisan migrate
routes/web.php:
Route::stripeWebhooks('stripe/webhooks');
Implementation:
charge.succeeded → update user subscription).Cutover:
composer.json for exact versions). Ensure compatibility with your Laravel version.spatie/laravel-stripe-webhooks and spatie/webhook-client. Test upgrades in staging before production.webhook_calls table to replay and debug failed webhooks:
// Replay a failed webhook
dispatch(new \Spatie\StripeWebhooks\ProcessStripeWebhookJob(WebhookCall::find($id)));
failed_jobs table or a monitoring tool).webhook_calls table by date or tenant for large-scale apps.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Invalid signature | Rejected webhook, no processing | Ensure verify_signature is enabled in production; monitor WebhookFailed exceptions. |
| Queue overload | Delayed or missed webhooks | Scale workers; implement circuit breakers for critical events. |
| Database connection issues | Failed logging, replay impossible | Use a robust database with backups; implement local retries for transient failures. |
| Stripe API changes | Broken payload parsing | Test with Stripe’s test events; use SDK version pinning. |
| Job failure (e.g., business logic) | Inconsistent state | Implement idempotency in jobs; log failures for review. |
| Deduplication collision | Duplicate processing | Use unique identifiers (e.g., payload->id) in shouldProcess logic. |
How can I help you explore Laravel packages today?