PHPackages                             beaub/laravel-easypost-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. [HTTP &amp; Networking](/categories/http)
4. /
5. beaub/laravel-easypost-webhooks

ActiveLibrary[HTTP &amp; Networking](/categories/http)

beaub/laravel-easypost-webhooks
===============================

Handle easypost webhooks in a Laravel application

1.0.2(8y ago)061MITPHPPHP ^7.0

Since Oct 27Pushed 8y ago1 watchersCompare

[ Source](https://github.com/beaubuehler/laravel-easypost-webhooks)[ Packagist](https://packagist.org/packages/beaub/laravel-easypost-webhooks)[ RSS](/packages/beaub-laravel-easypost-webhooks/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (4)Dependencies (4)Versions (5)Used By (0)

Handle Easypost Webhooks in a Laravel application
=================================================

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

[EasyPost](https://easypost.com) can notify your application of events using webhooks. This package can help you handle those webhooks. 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 yourself.

Before using this package we highly recommend reading [the entire documentation on webhooks over at EasyPost](https://www.easypost.com/docs/api.html#webhooks).

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

[](#installation)

You can install the package via composer:

```
composer require beaub/laravel-easypost-webhooks
```

The service provider will automatically register itself.

You must publish the config file with:

```
php artisan vendor:publish --provider="BeauB\EasypostWebhooks\EasypostWebhooksServiceProvider" --tag="config"
```

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

```
return [

    /*
     * You can define the job that should be run when a certain webhook hits your application
     * here. The key is the name of the Easypost event description with the `.` replaced by a `_`.
     *
     * You can find a list of Easypost webhook description types here:
     * https://www.easypost.com/docs/api#possible-event-types.
     */
    'jobs' => [
        // 'refund_successful' => \App\Jobs\EasypostWebhooks\HandleSuccessfulRefund::class,
        // 'tracker_created' => \App\Jobs\EasypostWebhooks\HandleTrackerCreated::class,
    ],

    /*
     * The classname of the model to be used. The class should equal or extend
     * BeauB\EasypostWebhooks\EasypostWebhookCall.
     */
    'model' => BeauB\EasypostWebhooks\EasypostWebhookCall::class,
];
```

Next, you must publish the migration with:

```
php artisan vendor:publish --provider="BeauB\EasypostWebhooks\EasypostWebhooksServiceProvider" --tag="migrations"
```

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

```
php artisan migrate
```

Finally, take care of the routing: At [the Easypost dashboard](https://www.easypost.com/account/webhooks-and-events) you must configure at what url Eaypost webhooks should hit your app. In the routes file of your app you must pass that route to `Route::easypostWebhooks`:

```
Route::easypostWebhooks('webhook-route-configured-at-the-easypost-dashboard');
```

Behind the scenes this will register a `POST` route to a controller provided by this package. Because Easypost 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-easypost-dashboard',
];
```

Usage
-----

[](#usage)

Easypost will send out webhooks for several event types. You can find the [full list of events types](https://www.easypost.com/docs/api#possible-event-types) in the Easypost documentation.

Unlike Stripe, Easypost does not sign the webhooks it sends to your server. In order to ensure that requests are valid, [use Basic Authentication and HTTPS on your endpoint](https://www.easypost.com/docs/api.html#webhooks). This package does not include this functionality. Refer to the Lavavel documentation regarding \[Basic Authentication\] () to secure your endpoint.

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

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:

```
