laravel/cashier
Laravel Cashier offers a fluent Laravel interface for Stripe subscription billing. Manage subscriptions, coupons, plan swaps, quantities, and cancellation grace periods, with support for generating invoice PDFs—all while handling the boilerplate billing code.
Laravel Cashier (Stripe integration) is a highly strategic fit for any Laravel-based SaaS, subscription, or recurring billing application. It abstracts Stripe’s complex billing logic into an elegant, Laravel-native API, reducing boilerplate while maintaining flexibility. Key architectural strengths:
User, Subscription, Invoice) align with business logic, enabling clean separation of concerns.CustomerSubscriptionCreated) allows for seamless integration with Laravel’s event system (e.g., broadcasting, queues).CashierServiceProvider integrates with Laravel’s service container).Anti-Patterns to Avoid:
newSubscription()) should be preferred over raw Stripe calls to maintain consistency.VerifyWebhookSignature must be used to prevent duplicate processing.| Component | Feasibility | Notes |
|---|---|---|
| Laravel Core | ✅ High | Designed for Laravel 10/11/12/13; minimal configuration required (composer require). |
| Stripe API | ✅ High | Directly maps to Stripe’s subscription, invoicing, and payment flows. |
| Database | ✅ High | Includes migrations for users, subscriptions, invoices, and billing_portal_sessions. |
| Frontend (Checkout) | ✅ High | Supports Stripe Checkout, Elements, and embedded UI with minimal JS. |
| Testing | ✅ High | Built-in test helpers (e.g., createTestSubscription()) and mockable Stripe SDK. |
| Multi-Tenancy | ⚠️ Medium | Requires customization (e.g., scoping Stripe customers to tenants via middleware). |
| Legacy Systems | ⚠️ Medium | May need adapters for non-Laravel systems (e.g., legacy PHP or non-SQL databases). |
Critical Dependencies:
strict_types=1).| Risk Area | Severity | Mitigation |
|---|---|---|
| Stripe API Changes | High | Cashier’s changelog highlights breaking changes (e.g., Stripe SDK v16 tax handling). |
| Webhook Reliability | High | Implement exponential backoff for retries and dead-letter queues for failed events. |
| Data Migration | Medium | Test migrations thoroughly; use php artisan migrate:fresh --seed for rollbacks. |
| Custom Billing Logic | Medium | Extend Cashier via traits or service containers (e.g., custom BillingService). |
| Performance | Low | Stripe API rate limits may require caching (e.g., Cache::remember). |
| Compliance (PCI/DSP2) | Medium | Ensure Stripe’s PCI compliance is maintained; avoid storing raw card data. |
Key Questions for the Team:
billing.yourdomain.com) be used for Checkout?billingPortal setup)?Cashier is optimized for the following Laravel stack:
billingPortal() method for self-service.VerifyWebhookSignature middleware..env (never hardcoded).subscription_deleted) via Laravel’s logging.Non-Fit Scenarios:
| Phase | Tasks | Tools/Commands |
|---|---|---|
| 1. Setup | Install Cashier, configure .env, set up Stripe keys. |
composer require laravel/cashier |
| 2. Database | Run migrations (users, subscriptions, etc.). |
php artisan migrate |
| 3. Models | Extend User model with hasOne for subscriptions. |
php artisan make:model Subscription |
| 4. Webhooks | Configure Stripe webhook endpoint and VerifyWebhookSignature middleware. |
php artisan make:middleware VerifyWebhook |
| 5. Checkout | Implement createSubscription() or newSubscription() in controllers. |
Stripe Checkout JS snippet |
| 6. Billing Portal | Add billingPortal() route and middleware for secure access. |
Route::middleware(['auth', 'verified'])->get() |
| 7. Testing | Write feature tests for subscriptions, invoices, and webhooks. | php artisan test |
| 8. Monitoring | Set up logging for Stripe events and failed payments. | Laravel Log + Sentry/Error Tracking |
Backward Compatibility:
Schema::table() or Doctrine Migrations for schema changes.| Compatibility Check | Status | Notes |
|---|---|---|
| Laravel 13 | ✅ Yes | Officially supported (v16.5.0+). |
| PHP 8.5 | ✅ Yes | Type declarations and strict mode supported. |
| Stripe SDK v16 | ✅ Yes | Required for new features (e.g., Usage-Based Billing). |
| Tailwind CSS | ✅ Yes | Billing portal UI is Tailwind-compatible. |
| Livewire/Inertia | ✅ Yes | Works with both for reactive subscription management. |
| Multi-Auth (Sanctum/JWT) | ✅ Yes | Billing portal can be scoped to specific guards. |
How can I help you explore Laravel packages today?