SaaS billing requires flexibility. Laravel Cashier simplifies Stripe integration for subscriptions, metered billing, and usage tracking. At ZIRA Software, we've built SaaS platforms serving thousands of paying customers.
Installation
composer require laravel/cashier
php artisan migrate
Basic Subscription
use Laravel\Cashier\Billable;
class User extends Authenticatable
{
use Billable;
}
// Create subscription
$user->newSubscription('default', 'price_monthly')->create($paymentMethod);
// Check subscription
if ($user->subscribed('default')) {
// User has active subscription
}
// Cancel subscription
$user->subscription('default')->cancel();
Multiple Plans
// Bronze plan
$user->newSubscription('default', 'price_bronze')->create($paymentMethod);
// Swap plans
$user->subscription('default')->swap('price_silver');
// With proration
$user->subscription('default')->swapAndInvoice('price_gold');
Metered Billing
// Report usage
$user->subscription('default')->reportUsage(100);
// Usage-based pricing
$subscription = $user->newSubscription('default', 'price_metered')
->meteredPrice('price_per_api_call')
->create($paymentMethod);
// Track usage
$user->subscription('default')->incrementQuantity(10); // Add 10 API calls
Customer Portal
Route::get('/billing', function (Request $request) {
return $request->user()->redirectToBillingPortal();
});
Webhooks
// Handle Stripe webhooks
protected function handleCustomerSubscriptionCreated(array $payload)
{
$user = $this->getUserByStripeId($payload['data']['object']['customer']);
// Handle new subscription
}
Conclusion
Laravel Cashier eliminates subscription billing complexity. Stripe integration provides powerful billing features with minimal code.
Building a SaaS platform? Contact ZIRA Software for subscription billing implementation.