Billing Made Simple: The Power of Laravel Cashier with Braintree

Laravel is a popular PHP framework, loved by developers for its elegance and flexibility. One of the many robust packages offered by the Laravel ecosystem is Laravel Cashier. Designed to handle subscription billing, Cashier simplifies the integration of several payment services. Today, we’ll focus on integrating Cashier with Braintree, a full-stack payment platform known for its user-friendly features.

Billing Made Simple: The Power of Laravel Cashier with Braintree

1. Why Use Laravel Cashier with Braintree?

Laravel Cashier provides an expressive, fluent interface to subscription billing services. It can handle coupons, swapping subscription, subscription “quantities”, cancellation grace periods, and even generate invoice PDFs. Combining this with Braintree, which offers a range of payment options (from credit cards to PayPal), makes for a powerful billing solution.

2. Setting Things Up

2.1. Installation

Start by requiring the Cashier package via Composer:

composer require laravel/cashier-braintree

Next, publish the Cashier migrations:

php artisan vendor:publish --tag="cashier-migrations"

After the migration has been published, you can create the `cashier_braintree_subscriptions` and `cashier_braintree_plans` tables by running the migrations:

php artisan migrate

2.2. Configuration

In your `.env` file, set your Braintree credentials:


3. Key Concepts

3.1 Creating Subscriptions

Once set up, creating subscriptions becomes straightforward.

Here’s a basic example:

$user->newSubscription('main', 'monthly-premium')->create($creditCardToken);

In the code above, `’main’` is the name of the subscription, and `’monthly-premium’` would be the id of the plan you’ve created in your Braintree dashboard.

3.2 Checking Subscription Status

To verify if a user is subscribed to a given plan:

if ($user->subscribed('main')) {
    // User is subscribed to "main" plan

3.3 Handling Webhooks

Webhooks allow Braintree to communicate with your application about various events. Cashier can handle these webhook events for you. All you need to do is point a route to Cashier’s controller.


Remember to configure the webhook URL in your Braintree dashboard.

4. Advanced Features

4.1 Coupons

Cashier makes it easy to handle discount coupons:

$user->newSubscription('main', 'monthly-premium')

4.2 Swapping Subscriptions

Switching users between plans is just as straightforward:


4.3 Subscription Quantities

You can easily manage the quantity for subscription plans:


4.4 Cancellation & Grace Period

Cancelling a subscription but allowing access until the period ends is a graceful touch:


To resume a subscription:


Wrapping Up

Laravel Cashier, combined with Braintree, truly offers a seamless way to manage subscription billing. It abstracts away most of the complexity, allowing you to focus on what really matters – building your application.

Billing and subscription management can be a daunting task, but with tools like Laravel Cashier, it becomes a lot more manageable. It’s a testament to how Laravel continues to offer solutions that make the life of developers easier, allowing us to build robust applications without getting bogged down by the intricacies of subscription billing.

Remember to always check the official documentation for both Laravel Cashier and Braintree, as they provide a wealth of information to help you harness the full potential of this powerful combination. Happy coding!

Previously at
Flag Argentina
time icon
Experienced Full Stack Engineer with expertise in Laravel and AWS. 7 years of hands-on Laravel development, leading impactful projects and teams.