Skip to content
Steven Roland

Laravel Cashier (Paddle): Simplifying Subscription Billing

Laravel Cashier Paddle provides an expressive, fluent interface to Paddle's subscription billing services. It handles most of the boilerplate subscription billing code, allowing developers to focus on building their applications. Let's explore how to use Cashier Paddle and some of its key features.

Getting Started

First, install Cashier Paddle via Composer:

composer require laravel/cashier-paddle

Next, add the Billable trait to your User model:

use Laravel\Paddle\Billable;

class User extends Authenticatable
{
    use Billable;
}

Configuration

Configure your Paddle keys in your .env file:

PADDLE_VENDOR_ID=your-paddle-vendor-id
PADDLE_VENDOR_AUTH_CODE=your-paddle-vendor-auth-code
PADDLE_PUBLIC_KEY="your-paddle-public-key"
PADDLE_SANDBOX=true

Creating Subscriptions

Creating a subscription is straightforward with Cashier Paddle:

$user = User::find(1);

$subscription = $user->newSubscription('default', $planId)->create($paymentMethod);

This creates a new subscription for the user with the 'default' name and the specified Paddle plan ID.

Checking Subscription Status

You can easily check a user's subscription status:

if ($user->subscribed('default')) {
    // User has an active subscription
}

if ($user->subscription('default')->onTrial()) {
    // User is on trial
}

if ($user->subscription('default')->cancelled()) {
    // Subscription is cancelled
}

Handling Paddle Webhooks

Cashier Paddle automatically handles Paddle's webhooks. Just set up a route:

use Illuminate\Support\Facades\Route;
use Laravel\Paddle\Http\Controllers\WebhookController;

Route::post(
    '/paddle/webhook',
    [WebhookController::class, 'handleWebhook']
);

Single Charges

For one-time charges, use the charge method:

$user->charge(1000, 'Product Name');

Suggested Usages

  • SaaS Applications: Implement tiered pricing plans for your software service.

  • Digital Content Subscriptions: Offer premium content access through subscriptions.

  • Membership Sites: Manage member access and recurring payments.

  • E-learning Platforms: Charge for course access or premium features.

  • API Access: Implement usage-based billing for API access.

Subscription Modifiers

Cashier Paddle supports subscription modifiers for flexible pricing:

$user->subscription('default')->addModifier(500, 'Extra Feature');

Conclusion

Laravel Cashier Paddle simplifies the complex world of subscription billing with Paddle, allowing you to focus on building great products. With its intuitive API and seamless Paddle integration, implementing a robust billing system has never been easier.

Remember to always refer to the official Laravel Cashier Paddle documentation for the most up-to-date information and best practices.

Support My Work

If you enjoy my content, consider supporting me through Buy Me a Coffee or GitHub Sponsors.

Buy Me A Coffee
or

More posts

The Unavoidable Nature of Pain: Embracing Our Emotions

Inspired by John Green's quote, this post explores the unavoidable nature of pain and why it's crucial to embrace rather than avoid it. It offers insights on healthy ways to process pain and highlights its role in personal growth and empathy.

Laravel Cashier: Stripe vs Paddle - Choosing the Right Payment Solution

This post compares Laravel Cashier for Stripe and Paddle, covering installation, key features, pricing, availability, and developer experience. Stripe offers more control and payment methods, while Paddle provides automatic tax handling and global digital product sales support.

The Universality of Struggle: Finding Humanity in Hardship

Inspired by S.E. Hinton's quote from "The Outsiders," this post explores how universal struggle can foster empathy and human connection. It offers insights on breaking down social barriers, challenging assumptions, and finding unity in shared hardships.