Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Stripe Webhooks Laravel Package

spatie/laravel-stripe-webhooks

Laravel package to handle Stripe webhooks: verifies Stripe signatures, stores valid webhook calls in the database, and dispatches configurable jobs or events per Stripe event type. You implement the business logic (payments, subscriptions, etc.).

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Event-Driven Integration: The package excels in Laravel’s event-driven architecture, aligning with Stripe’s webhook model. It abstracts signature verification, logging, and payload processing, reducing boilerplate for common use cases.
  • Decoupled Design: Supports both job-based and event-based handling, enabling modularity. Jobs (queued) or listeners (real-time) can be chosen based on latency/scalability needs.
  • Extensibility: Custom profiles, models, and middleware hooks allow adaptation to niche requirements (e.g., multi-tenant secrets, idempotency checks).

Integration Feasibility

  • Low Friction: Requires minimal setup (config, migration, route) and leverages Laravel’s built-in queue/worker systems.
  • Stripe SDK Agnostic: While it doesn’t replace Stripe’s PHP SDK, it integrates seamlessly with it (e.g., payload-to-Stripe-object conversion).
  • CSRF/Validation: Handles Stripe’s signature verification and CSRF exemptions automatically, reducing security risks.

Technical Risk

  • Idempotency: Stripe’s duplicate events are mitigated by the package’s deduplication logic, but custom logic (e.g., shouldProcess) may introduce edge cases.
  • Payload Size: Large payloads (e.g., complex events) could bloat the webhook_calls table. Consider archiving or pruning strategies.
  • Queue Backpressure: Heavy webhook traffic may overwhelm queues. Monitor failed_jobs table and adjust queue workers.
  • Stripe API Changes: Breaking changes in Stripe’s event schema could require package updates (though Spatie’s maturity suggests stability).

Key Questions

  1. Event Volume: How many webhooks/sec must the system handle? Queue depth and worker scaling may need tuning.
  2. Critical Paths: Which events require sub-second processing (e.g., payments)? Event listeners may be better than jobs for these.
  3. Audit Needs: Beyond logging, are webhook payloads needed for compliance? Consider archiving or external storage.
  4. Multi-Environment Secrets: How are STRIPE_WEBHOOK_SECRET and multi-secret configs managed (e.g., env vars, Vault)?
  5. Error Handling: Should failed webhooks trigger alerts (e.g., Slack, PagerDuty)? Extend the WebhookFailed exception handler.

Integration Approach

Stack Fit

  • Laravel Ecosystem: Native support for queues, events, and migrations. Works with Laravel’s service container and middleware stack.
  • Stripe SDK: Complements the official PHP SDK for payload processing (e.g., Stripe\Event::constructFrom).
  • Database: Requires a webhook_calls table (MySQL/PostgreSQL recommended). Consider indexing payload->id for deduplication.
  • Infrastructure: Needs a public endpoint (e.g., Nginx/Apache) and queue workers (e.g., Redis, database queue).

Migration Path

  1. Pilot Phase:
    • Install the package and configure a single webhook endpoint (e.g., charge.succeeded).
    • Test with Stripe’s webhook test tool.
    • Validate signature verification and logging.
  2. Gradual Rollout:
    • Add critical events (e.g., payment_intent.succeeded, invoice.payment_succeeded) to the jobs config.
    • Implement custom logic (e.g., job listeners) for business-critical flows.
  3. Full Adoption:
    • Migrate all Stripe webhooks to the package.
    • Replace ad-hoc webhook handlers with the package’s structure.
    • Deprecate legacy webhook routes.

Compatibility

  • Laravel Versions: Supports Laravel 8+ (check composer.json for exact ranges).
  • PHP Versions: Requires PHP 8.0+ (aligns with Laravel’s requirements).
  • Stripe SDK: Works with Stripe PHP SDK v7+ (verify compatibility with your SDK version).
  • Middleware: Ensure VerifyCsrfToken excludes the webhook route (handled by the package).

Sequencing

  1. Pre-requisites:
    • Set up Stripe webhook endpoints in the Stripe Dashboard.
    • Configure Laravel’s queue system (e.g., QUEUE_CONNECTION=redis).
  2. Package Setup:
    • Publish config (php artisan vendor:publish) and migrations.
    • Run migrations (php artisan migrate).
  3. Routing:
    • Register the webhook route in routes/web.php:
      Route::stripeWebhooks('stripe/webhook');
      
    • Exempt the route from CSRF middleware.
  4. Event Mapping:
    • Define jobs/listeners in config/stripe-webhooks.php.
    • Implement custom logic (e.g., StripeWebhookProfile for filtering).
  5. Testing:
    • Use Stripe’s test mode and webhook test tool.
    • Mock webhook payloads in PHPUnit (e.g., Http::fake()).

Operational Impact

Maintenance

  • Config Management: Centralized in config/stripe-webhooks.php. Use environment variables for secrets (e.g., STRIPE_WEBHOOK_SECRET).
  • Dependency Updates: Monitor Spatie’s releases for breaking changes (e.g., Stripe API version updates).
  • Logging: Webhook calls are logged to webhook_calls. Consider:
    • Retention policies (e.g., archive old logs).
    • Indexing for query performance (e.g., payload->id).
  • Monitoring: Track:
    • Webhook failure rates (WebhookFailed exceptions).
    • Queue lag (e.g., failed_jobs table growth).

Support

  • Debugging:
    • Inspect webhook_calls table for payloads/exceptions.
    • Use telescope or laravel-debugbar to trace job execution.
  • Stripe Dashboard: Verify endpoint URLs and signing secrets match the package config.
  • Community: Leverage Spatie’s GitHub issues and Laravel forums for troubleshooting.

Scaling

  • Horizontal Scaling:
    • Stateless design allows scaling Laravel workers (e.g., Kubernetes, ECS).
    • Ensure queue connection (e.g., Redis) is shared across instances.
  • Vertical Scaling:
    • Increase queue workers for high-volume events.
    • Optimize job payload size (e.g., avoid serializing large objects).
  • Database:
    • Partition webhook_calls table by date if volume exceeds millions/month.
    • Consider read replicas for analytics queries.

Failure Modes

Failure Scenario Impact Mitigation
Invalid signature Rejected webhook (no processing) Monitor WebhookFailed exceptions; verify Stripe secret in config.
Queue overload Delayed processing Scale workers; implement circuit breakers for critical events.
Database connection issues Lost webhook logs Use queue retries; archive logs to S3/backup DB.
Stripe API changes Broken payload parsing Test with Stripe’s test mode; update package if needed.
Custom logic errors Silent failures Wrap job handlers in try-catch; log exceptions to webhook_calls.exception.
Duplicate events Idempotent processing Leverage package’s deduplication; add custom shouldProcess logic if needed.

Ramp-Up

  • Onboarding Time: ~2–4 hours for initial setup (config, routes, first job).
  • Team Skills:
    • Developers: Familiarity with Laravel queues, events, and middleware.
    • Ops: Queue management and monitoring (e.g., Prometheus for queue metrics).
  • Training:
    • Document Stripe event-to-job mappings.
    • Train teams on debugging webhook failures (e.g., inspecting webhook_calls).
  • Checklist:
    • Stripe webhook endpoints configured in dashboard.
    • Laravel queue system operational.
    • Critical events mapped to jobs/listeners.
    • Monitoring alerts for failures/queue lag.
    • Disaster recovery plan for lost webhooks (e.g., backup webhook_calls).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport