PHPackages                             vanthao03596/laravel-paddle-webhooks - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. vanthao03596/laravel-paddle-webhooks

ActiveLibrary

vanthao03596/laravel-paddle-webhooks
====================================

Handle paddle webhooks in a Laravel application

1.0.0(4y ago)13MITPHPPHP ^7.4 || ^8.0

Since Aug 19Pushed 4y ago1 watchersCompare

[ Source](https://github.com/vanthao03596/laravel-paddle-webhooks)[ Packagist](https://packagist.org/packages/vanthao03596/laravel-paddle-webhooks)[ Docs](https://github.com/vanthao03596/laravel-paddle-webhooks)[ GitHub Sponsors](https://github.com/vanthao03596)[ RSS](/packages/vanthao03596-laravel-paddle-webhooks/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

Handle Paddle webhooks in a Laravel application
===============================================

[](#handle-paddle-webhooks-in-a-laravel-application)

[![Latest Version on Packagist](https://camo.githubusercontent.com/3d158dc34d94de4072aa95dd0f1e4b7300f265f42edc5ee117d17aaa2478dd4d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f76616e7468616f30333539362f6c61726176656c2d706164646c652d776562686f6f6b732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/vanthao03596/laravel-paddle-webhooks)[![GitHub Tests Action Status](https://camo.githubusercontent.com/0a59d85d20b3e2de70d3a1ca7a1e3de3fccaf0c7d6c2e3f843fab04ea6c2f26d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f76616e7468616f30333539362f6c61726176656c2d706164646c652d776562686f6f6b732f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/vanthao03596/laravel-paddle-webhooks/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/63a1f4e62e5328c8a214c106983f811d35876c70aadad43eba81fbcc95226ca8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f76616e7468616f30333539362f6c61726176656c2d706164646c652d776562686f6f6b732f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/vanthao03596/laravel-paddle-webhooks/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/8c1be3fd1c97c4aa869a6ada52cd7d13b1e15c3fd5106546fe6b63c618ac767a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f76616e7468616f30333539362f6c61726176656c2d706164646c652d776562686f6f6b732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/vanthao03596/laravel-paddle-webhooks)

[Paddle](https://paddle.com/) can notify your application of events using webhooks. This package can help you handle those webhooks. Out of the box it will verify the Paddle signature of all incoming requests. All valid calls will be logged to the database. You can easily define jobs or events that should be dispatched when specific events hit your app.

This package will not handle what should be done after the webhook request has been validated and the right job or event is called. You should still code up any work (eg. regarding payments) yourself.

Highly recommend reading [the entire documentation on webhooks over at Paddle](https://developer.paddle.com/webhook-reference/intro) before use this package.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require vanthao03596/laravel-paddle-webhooks
```

The service provider will automatically register itself.

You must publish the config file with:

```
php artisan vendor:publish --provider="Vanthao03596\PaddleWebhooks\PaddleWebhooksServiceProvider" --tag="config"
```

This is the contents of the config file that will be published at `config/paddle-webhooks.php`:

This is the contents of the published config file:

```
return [
    /*
     * Paddle will sign each webhook using a public key to create signature . You can find the used public key at the
     * webhook configuration settings: https://vendors.paddle.com/public-key.
     */
    'signing_secret' => env('PADDLE_PUBLIC_KEY'),

    /*
     * You can define the job that should be run when a certain webhook hits your application
     * here. The key is the name of the Paddle event type.
     *
     * You can find a list of Paddle webhook types here:
     * https://developer.paddle.com/webhook-reference/intro.
     */
    'jobs' => [
        // 'subscription_created' => \App\Jobs\PaddleWebhooks\HandleSubscriptionCreated::class,
        // 'payment_succeeded' => \App\Jobs\PaddleWebhooks\HandlePaymentSucceeded::class,
    ],

    /*
     * The classname of the model to be used. The class should equal or extend
     * Vanthao03596\PaddleWebhooks\ProcessPaddleWebhookJob.
     */
    'model' => \Vanthao03596\PaddleWebhooks\ProcessPaddleWebhookJob::class,

    /**
     * This class determines if the webhook call should be stored and processed.
     */
    'profile' => \Spatie\WebhookClient\WebhookProfile\ProcessEverythingWebhookProfile::class,

    /*
     * When disabled, the package will not verify if the signature is valid.
     * This can be handy in local environments.
     */
    'verify_signature' => env('PADDLE_SIGNATURE_VERIFY', true),
];
```

Next, you must publish the migration with:

```
php artisan vendor:publish --provider="Spatie\WebhookClient\WebhookClientServiceProvider" --tag="migrations"
```

After the migration has been published you can create the `webhook_calls` table by running the migrations:

```
php artisan migrate
```

Finally, take care of the routing: At [the Paddle dashboard](https://sandbox-vendors.paddle.com/alerts-webhooks) you must configure at what url Paddle webhooks should hit your app. In the routes file of your app you must pass that route to `Route::paddleWebhooks`:

```
Route::paddleWebhooks('webhook-route-configured-at-the-paddle-dashboard');
```

Behind the scenes this will register a `POST` route to a controller provided by this package. Because Paddle has no way of getting a csrf-token, you must add that route to the `except` array of the `VerifyCsrfToken` middleware:

```
protected $except = [
    'webhook-route-configured-at-the-paddle-dashboard',
];
```

Usage
-----

[](#usage)

Paddle will send out webhooks for several event types. You can find the [full list of events types](https://developer.paddle.com/webhook-reference/intro) in the Paddle documentation.

Paddle will sign all requests hitting the webhook url of your app. This package will automatically verify if the signature is valid. If it is not, the request was probably not sent by Paddle.

Unless something goes terribly wrong, this package will always respond with a `200` to webhook requests. Sending a `200` will prevent Paddle from resending the same event over and over again. All webhook requests with a valid signature will be logged in the `webhook_calls` table. The table has a `payload` column where the entire payload of the incoming webhook is saved.

If the signature is not valid, the request will not be logged in the `webhook_calls` table but a `Vanthao03596\PaddleWebhooks\Exceptions\WebhookFailed` exception will be thrown. If something goes wrong during the webhook request the thrown exception will be saved in the `exception` column. In that case the controller will send a `500` instead of `200`.

There are two ways this package enables you to handle webhook requests: you can opt to queue a job or listen to the events the package will fire.

### Handling webhook requests using jobs

[](#handling-webhook-requests-using-jobs)

If you want to do something when a specific event type comes in you can define a job that does the work. Here's an example of such a job:

```
