I stand up for children in need. Please join me in helping this family.

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

Simplifying Routing with Laravel Folio: A Comprehensive Guide

Laravel Folio simplifies routing by using Blade templates to generate routes automatically. Install Folio, create pages in the 'pages' directory, and enjoy automatic routing. It supports dynamic routes, model binding, and middleware. Ideal for static pages, blogs, documentation sites, and admin panels.