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, 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.

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 low-level concerns (signature verification, deduplication, logging) while allowing custom business logic via jobs or events.
  • Separation of Concerns: Decouples webhook handling from business logic by leveraging Laravel’s queue system and event listeners. This adheres to SOLID principles, particularly the Single Responsibility Principle (SRP).
  • Extensibility: Supports custom models, profiles, and job logic, enabling tailored behavior for complex workflows (e.g., multi-tenant Stripe Connect setups).
  • Idempotency: Built-in deduplication via the webhook_calls table mitigates duplicate event risks, a critical requirement for financial systems.

Integration Feasibility

  • Laravel Native: Leverages Laravel’s built-in features (queues, events, middleware) with minimal friction. No external dependencies beyond Stripe’s PHP SDK.
  • Stripe SDK Agnostic: While it uses Stripe’s PHP SDK for payload transformation, the core logic is decoupled, allowing flexibility in SDK versioning.
  • Database Dependency: Requires a webhook_calls table, which is a minor trade-off for reliability and auditability. Migration is straightforward via Artisan.

Technical Risk

  • Signature Verification: Disabling verification (verify_signature) in non-production environments could expose the system to replay attacks. Requires disciplined environment management.
  • Queue Reliability: Job failures (e.g., dead-letter queues) must be monitored to avoid silent failures. The package lacks built-in retry logic for failed jobs—requires custom implementation (e.g., failed_jobs table monitoring).
  • Payload Size: Storing raw payloads in the database could bloat storage for high-volume systems. Consider archiving or sampling for analytics.
  • Stripe API Changes: Breaking changes in Stripe’s webhook payload structure may require package updates. Monitor Stripe’s changelog.
  • Multi-Environment Secrets: Managing multiple signing secrets (e.g., for Stripe Connect) adds complexity to deployment pipelines. Requires CI/CD safeguards for secret rotation.

Key Questions

  1. Scalability Needs:
    • Will the system handle high-volume webhook traffic (e.g., >10K events/hour)? If so, assess queue backlog and database write performance.
    • Are there SLA requirements for webhook processing latency? Queue configuration (STRIPE_WEBHOOK_QUEUE) may need tuning (e.g., dedicated queue, batch processing).
  2. Compliance/Auditability:
    • Does the system require immutable logs of all webhook events? If so, ensure the webhook_calls table is backed up and retained per compliance policies.
    • Are there regulatory constraints on storing raw payment data? Consider masking sensitive fields in the payload.
  3. Error Handling:
    • How should failed webhooks be alerted? The package lacks built-in notifications; integrate with tools like Laravel Horizon or Sentry.
    • What’s the RTO/RPO for webhook processing? Test failover scenarios (e.g., database downtime).
  4. Testing Strategy:
    • How will webhook handlers be tested? Mock Stripe events using libraries like stripe-mock or Laravel’s HTTP tests.
    • Are there edge cases to validate (e.g., malformed payloads, missing signatures, duplicate events)?
  5. Customization Depth:
    • Will custom profiles/jobs be needed? Evaluate the effort to extend ProcessStripeWebhookJob or WebhookProfile.
    • Are there plans to use Stripe’s webhook signing with libraries? The package’s verification is library-agnostic.

Integration Approach

Stack Fit

  • Laravel Ecosystem: Optimized for Laravel 8+/9+ with first-party integrations (queues, events, middleware). No conflicts with Laravel’s routing or middleware stack.
  • Queue Systems: Supports Redis, database, or other Laravel queue drivers. Ideal for decoupling webhook processing from HTTP requests.
  • Stripe SDK: Compatible with Stripe’s PHP SDK (v7+). Ensure SDK version alignment with Stripe’s supported versions.
  • Database: Requires MySQL/PostgreSQL/SQLite for the webhook_calls table. No schema migrations for other databases.

Migration Path

  1. Preparation:
    • Audit existing Stripe webhook handling (e.g., raw route controllers, manual signature verification).
    • Set up Stripe test mode and configure a test webhook endpoint in the Stripe Dashboard.
  2. Installation:
    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
    
  3. Configuration:
    • Update .env with STRIPE_WEBHOOK_SECRET (from Stripe Dashboard).
    • Configure stripe-webhooks.php:
      • Map Stripe event types to jobs (e.g., charge.succeededHandleSuccessfulCharge).
      • Set default_job if needed (e.g., for unhandled events).
      • Define queue (e.g., stripe) and connection (e.g., redis).
    • Exclude the webhook route from CSRF middleware in App\Http\Middleware\VerifyCsrfToken.
  4. Routing:
    Route::stripeWebhooks('/stripe/webhook');
    
  5. Implementation:
    • Develop jobs/listeners for critical events (e.g., payment_intent.succeeded, invoice.payment_failed).
    • Test locally with Stripe’s CLI or webhook test tool.
  6. Deployment:
    • Roll out in stages (e.g., non-critical events first).
    • Monitor queue backlogs and database growth post-deployment.

Compatibility

  • Laravel Versions: Tested on Laravel 8+ (LTS). For Laravel 7, use v1.x of the package.
  • PHP Versions: Requires PHP 8.0+. Align with Laravel’s supported PHP versions.
  • Stripe SDK: Ensure compatibility with Stripe’s PHP SDK (e.g., v10.x for Laravel 9+).
  • Middleware: Conflicts possible with other middleware (e.g., rate limiting). Order matters: place VerifyStripeWebhookSignature before business logic middleware.

Sequencing

  1. Critical Path:
    • Signature verification → Logging → Job dispatch/event firing.
    • Ensure this path is optimized for low latency (e.g., avoid heavy operations in the webhook route).
  2. Non-Critical Path:
    • Custom logic in jobs/listeners can be async (e.g., send emails, update analytics).
  3. Fallbacks:
    • Implement a default_job to handle unregistered events gracefully.
    • Use try-catch in jobs to log failures without crashing the webhook handler.

Operational Impact

Maintenance

  • Configuration Drift: Monitor stripe-webhooks.php for changes (e.g., new event types). Use environment variables for secrets to avoid hardcoding.
  • Dependency Updates: Regularly update the package and Stripe SDK to patch vulnerabilities. Test updates in staging.
  • Job Management:
    • Monitor failed jobs via Laravel’s failed_jobs table or tools like Horizon.
    • Implement job retries with exponential backoff for transient failures.
  • Logging:
    • Leverage Laravel’s logging to track webhook processing (e.g., stripe-webhooks channel).
    • Consider adding custom logs for business-critical events (e.g., payment_intent.succeeded).

Support

  • Debugging:
    • Use the webhook_calls table to audit events. Add indexes on payload->id and created_at for performance.
    • Replay failed webhooks manually with:
      ProcessStripeWebhookJob::dispatch(WebhookCall::find($id));
      
  • Stripe Dashboard:
    • Verify webhook delivery status in Stripe’s Dashboard.
    • Check "Test webhook" logs for failed deliveries.
  • Documentation:
    • Maintain runbooks for common issues (e.g., "Webhook signature verification failed").
    • Document event-to-job mappings and business logic in a central wiki.

Scaling

  • Horizontal Scaling:
    • Stateless webhook handler (after logging) allows scaling Laravel instances.
    • Use a dedicated queue (e.g., stripe) to isolate webhook processing from other jobs.
  • Database Scaling:
    • Partition webhook_calls by date if retention policies require archiving old events.
    • Consider
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.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony