Home

Awesome

:warning: I'm unsure about the future of this package. I might be abandoning it, so please consider using Laravel Cashier (Paddle).

Laravel Paddle

Latest Version on Packagist run-tests Quality Score Total Downloads

This package provides an integration with Paddle.com for Laravel. Read the blogpost about the introduction of the package!

Features

Sponsor Us

<img src="https://inertiaui.com/visit-card.jpg" />

❤️ We proudly support the community by developing Laravel packages and giving them away for free. If this package saves you time or if you're relying on it professionally, please consider sponsoring the maintenance and development and check out our latest premium package: Inertia Table. Keeping track of issues and pull requests takes time, but we're happy to help!

Installation

Only the master branch and version 2.0 of this package are compatible with Laravel 8.0 and higher. If you're still using an older version of Laravel (or PHP < 7.3), please use the chart below to find out which version you should use. Mind that older versions are no longer supported.

Laravel VersionPackage Version
8.0-11.02.0
6.0-7.01.0

You can install the package via composer:

composer require protonemedia/laravel-paddle

Configuration

Publish the config file:

php artisan vendor:publish --provider="ProtoneMedia\LaravelPaddle\PaddleServiceProvider" --tag=config

Set your Vendor ID and Code and the Public Key settings in your .env file or in the config/paddle.php file. The Public Key is used to verify incoming webhooks from Paddle.

PADDLE_SANDBOX=false
PADDLE_VENDOR_ID=123
PADDLE_VENDOR_AUTH_CODE=456
PADDLE_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----
...
-----END PUBLIC KEY-----"

Paddle Sandbox

As of version 2.2.0, this package supports the Paddle Sandbox environment. To use this environment, set the sandbox_environment configuration key to true. This will configure the API URLs, as well as the Paddle JavaScript library. If you've published the Blade View while using a previous version of this package, make sure you republish the view:

php artisan vendor:publish --provider="ProtoneMedia\LaravelPaddle\PaddleServiceProvider" --tag=views

Usage

The API calls are available with the Paddle facade. Check out the the documentation to learn all about the Paddle API. You can build your API calls fluently or you could simply pass an array which holds the data. This package has some basic validation rules for the given data and this might result in an InvalidDataException if your data is invalid. Whenever an API call fails it will throw a PaddleApiException.

// Fluent:
$paddleResponse = Paddle::product()
    ->generatePayLink()
    ->productId($paddlePlanId)
    ->customerEmail($team->owner->email)
    ->passthrough(['team_id' => $team->id])
    ->send();

// Array with payload:
$payload = [
    'product_id' => $paddlePlanId,
    'customer_email' => $team->owner->email,
    'passthrough' => ['team_id' => $team->id],
];

$paddleResponse = Paddle::product()
    ->generatePayLink($payload)
    ->send();

return Redirect::to($paddleResponse['url']);

Available API calls

// alerts
Paddle::alert()->getWebhookHistory();

// checkouts
Paddle::checkout()->getOrderDetails();
Paddle::checkout()->getUserHistory();
Paddle::checkout()->getPrices();

// products
Paddle::product()->listCoupons();
Paddle::product()->createCoupon();
Paddle::product()->updateCoupon();
Paddle::product()->deleteCoupon();

Paddle::product()->listProducts();
Paddle::product()->generateLicense();
Paddle::product()->generatePayLink();
Paddle::product()->listTransactions($entity, $id);

// subscriptions
Paddle::subscription()->listPlans();
Paddle::subscription()->createPlan();

Paddle::subscription()->listUsers();
Paddle::subscription()->updateUser();
Paddle::subscription()->previewUpdate();
Paddle::subscription()->cancelUser();

Paddle::subscription()->listModifiers();
Paddle::subscription()->createModifier();
Paddle::subscription()->deleteModifier();

Paddle::subscription()->listPayments();
Paddle::subscription()->reschedulePayment();
Paddle::subscription()->createOneOffCharge($subscriptionId);

Webhooks and Laravel Events

You can configure your webhook URI in the paddle.php config file. Update your webhook settings at Paddle accordingly. By default the URI is paddle/webhook. This means that the webhook calls will be posted to https://your-domain.com/paddle/webhook.

Every webhook will be mapped to an Event and contains the payload of the webhook. For example when the Subscription Created webhook is called, the request is verified and a SubscriptionCreated event will be fired.

Events:

Some webhooks, like the Fulfillment Webhook, don't have an alert_name key. Those webhooks will be mapped to a ProtoneMedia\LaravelPaddle\Events\GenericWebhook event.

When you register a listener to handle the event, the payload is easily accessible. You also have access to the original HTTP request.

<?php

namespace App\Listeners;

use ProtoneMedia\LaravelPaddle\Events\SubscriptionCreated;

class CreateSubscriptionModel
{
    public function handle(SubscriptionCreated $event)
    {
        $status = $event->status;

        $nextBillDate = $event->next_bill_date;

        // or

        $webhookData = $event->all();

        //

        $request = $event->getRequest();
    }
}

Blade directive

This directive imports the Paddle JavaScript library and configures it with your Vendor ID.

<body>
    {{-- your app --}}

    @paddle
</body>

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Other Laravel packages

Security

If you discover any security related issues, please email pascal@protone.media instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.