# Laravel Cashier

What is Laravel Cashier?

Laravel Cashier is a subscription billing library for Laravel applications that integrates seamlessly with Stripe or Paddle. It simplifies handling subscription logic, such as billing, payments, and invoices, in SaaS applications.

---

## Origin

Cashier was introduced to reduce the complexity of integrating billing systems into Laravel applications, leveraging popular payment gateways like Stripe and Paddle.

---

## Why is Laravel Cashier Used?

1. **Simplifies Billing Logic**: Handles complex subscription scenarios with minimal code.
2. **Automates Payment Processing**: Manages recurring payments and invoicing automatically.
3. **Speeds Up Development**: Provides out-of-the-box functionality for common billing tasks.

---

## Best Practices

1. **Use Webhooks**: Handle payment updates and failures with webhook listeners.
2. **Test Billing Scenarios**: Simulate subscription and payment processes during development.
3. **Secure Billing Pages**: Protect sensitive routes with proper authentication.

---

## Example in Action

Install Cashier:

```bash
composer require laravel/cashier
```

Set up the `Billable` trait in your `User` model:

```php
namespace App\Models;

use Laravel\Cashier\Billable;

class User extends Authenticatable
{
    use Billable;
}
```

Create a new subscription:

```php
$user = User::find(1);
$user->newSubscription('default', 'price_id')->create($paymentMethod);
```

Handle Stripe webhooks:

```bash
php artisan cashier:webhook
```

Cashier streamlines subscription billing, making it easier to build and manage SaaS applications.

Read this definition in a browser: https://ranetrace.com/glossary/laravel-cashier
