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

Cashier Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

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:

  • Domain-Driven Design (DDD) Alignment: Models (User, Subscription, Invoice) align with business logic, enabling clean separation of concerns.
  • Event-Driven Extensibility: Built-in webhook handling (e.g., CustomerSubscriptionCreated) allows for seamless integration with Laravel’s event system (e.g., broadcasting, queues).
  • Modularity: Decouples Stripe-specific logic from business logic, easing future migrations (e.g., switching to another payment provider).
  • Laravel Ecosystem Synergy: Leverages Laravel features like Eloquent, Queues, Notifications, and Testing (e.g., CashierServiceProvider integrates with Laravel’s service container).

Anti-Patterns to Avoid:

  • Over-customization of Stripe’s API: Cashier’s abstractions (e.g., newSubscription()) should be preferred over raw Stripe calls to maintain consistency.
  • Ignoring Webhook Idempotency: Stripe webhooks may retry; Cashier’s VerifyWebhookSignature must be used to prevent duplicate processing.

Integration Feasibility

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:

  • Stripe PHP SDK (v16+): Cashier v16.x requires Stripe SDK v16; downgrading may break features like Usage-Based Billing.
  • Laravel Version: Supports Laravel 10–13; v16.x drops support for Laravel <10.
  • PHP 8.1+: Required for type safety and modern features (e.g., strict_types=1).

Technical Risk

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:

  1. Stripe Account Setup:
    • Are webhook endpoints and API keys already configured in Stripe Dashboard?
    • Will custom domains (e.g., billing.yourdomain.com) be used for Checkout?
  2. Subscription Models:
    • How will pricing tiers (e.g., monthly/annual) map to Stripe Products/Plans?
    • Are there usage-based billing requirements (e.g., metered seats)?
  3. User Flow:
    • Will users self-manage subscriptions (requires billingPortal setup)?
    • Are trial periods or free plans needed (Cashier supports both)?
  4. Failure Handling:
    • How will failed payments be communicated to users (e.g., email retries)?
    • Are dunning management (Stripe’s retry logic) and invoice generation (PDFs) required?
  5. Scaling:
    • Will high-volume subscriptions (e.g., 10K+ users) require Stripe’s Billing API optimizations?
    • Are regional pricing or tax calculations needed (Cashier supports both)?

Integration Approach

Stack Fit

Cashier is optimized for the following Laravel stack:

  • Backend: Laravel 10–13 (PHP 8.1–8.5), with Eloquent ORM and Queues (for async webhooks).
  • Frontend:
    • Checkout: Stripe Checkout (hosted) or Stripe Elements (embedded).
    • Billing Portal: billingPortal() method for self-service.
    • UI: Tailwind CSS or Blade templates for subscription management.
  • Database: MySQL/PostgreSQL (SQLite supported but not recommended for production).
  • DevOps:
    • Webhooks: HTTPS endpoint with VerifyWebhookSignature middleware.
    • Secrets: Stripe keys in .env (never hardcoded).
    • Monitoring: Log Stripe events (e.g., subscription_deleted) via Laravel’s logging.

Non-Fit Scenarios:

  • Non-Laravel Backends: Requires significant refactoring (e.g., Symfony, Node.js).
  • Headless CMS: May need custom adapters for content management.
  • Monolithic Apps: Cashier’s modularity is ideal for microservices (e.g., separate billing service).

Migration Path

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:

  • Major Version Upgrades: Cashier v16.x requires Laravel 10+; upgrade guides are provided in the changelog.
  • Data Migration: Use Schema::table() or Doctrine Migrations for schema changes.

Compatibility

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