PHPackages                             renatoxm/laravel-postmark-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. renatoxm/laravel-postmark-webhooks

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

renatoxm/laravel-postmark-webhooks
==================================

Handle Postmark webhooks in a Laravel application.

v2.0.3(2y ago)15721MITPHPPHP ^8.0

Since Aug 16Pushed 2y agoCompare

[ Source](https://github.com/renatoxm/laravel-postmark-webhooks)[ Packagist](https://packagist.org/packages/renatoxm/laravel-postmark-webhooks)[ Docs](https://github.com/renatoxm/laravel-postmark-webhooks)[ GitHub Sponsors](https://github.com/RenatoXM)[ RSS](/packages/renatoxm-laravel-postmark-webhooks/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (5)Versions (17)Used By (0)

Handle Postmark webhooks in a Laravel application
=================================================

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

[![Latest Version on Packagist](https://camo.githubusercontent.com/c2918324a0bf1afe2eb73414cabd8db709c420308a346741554609f285ac6c2f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72656e61746f786d2f6c61726176656c2d706f73746d61726b2d776562686f6f6b732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/renatoxm/laravel-postmark-webhooks)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Tests](https://camo.githubusercontent.com/96778f337d28b4a29b9d68f0954cc228726825be8f73530322086eb23398933e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f72656e61746f786d2f6c61726176656c2d706f73746d61726b2d776562686f6f6b732f74657374732e796d6c3f6272616e63683d6d61696e)](https://github.com/renatoxm/laravel-postmark-webhooks/actions/workflows/tests.yml)[![StyleCI](https://camo.githubusercontent.com/17e0936b490cc08cfecded982298d9ccdf0247c437cdb9e74045f98cd51f4d62/68747470733a2f2f7374796c6563692e696f2f7265706f732f3637393232333035382f736869656c643f6272616e63683d6d61696e)](https://styleci.io/repos/679223058)[![Total Downloads](https://camo.githubusercontent.com/64177570ff10a1bee7f832004d0fd7f233a3b534dcb027e6310b0dbf6493115d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72656e61746f786d2f6c61726176656c2d706f73746d61726b2d776562686f6f6b732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/renatoxm/laravel-postmark-webhooks)

Postmark can send out several webhooks to *your* application when an event occurs.
This way Postmark is able to immediately notify you when something new occurs.

This package can help you handle those webhooks.

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

[](#installation)

You can install the package via composer:

```
composer require RenatoXM/laravel-postmark-webhooks
```

Publish config and migration files:

```
sail artisan vendor:publish --provider="RenatoXM\PostmarkWebhooks\PostmarkWebhooksServiceProvider"
```

This package will log all incoming webhooks to the database by default.
Run the migrations to create a `postmark_webhook_logs` table in the database:

```
php artisan migrate
```

> If you want to disable database logging you can set `POSTMARK_WEBHOOKS_LOG_ENABLED=false` in your `.env` file.

Setup webhooks with Postmark
----------------------------

[](#setup-webhooks-with-postmark)

Visit the [servers](https://account.postmarkapp.com/servers) page on your [Postmark account](https://account.postmarkapp.com/). Choose the server you want to setup webhooks for.
Go to `settings` &gt; `webhooks` &gt; `add webbook`.

This package will register a route where Postmark can post their webhooks to: `/api/webhooks/postmark`.

Fill in your webhook URL: `https:///api/webhooks/postmark`
Pick the events Postmark should send to you and save the webhook.
You are ready to receive webhook notifications from Postmark!

> You may change the `/api/webhooks/postmark` endpoint to anything you like.
> You can do this by changing the `path` key in the `config/postmark-webooks.php` file.

Protection of your webhook
--------------------------

[](#protection-of-your-webhook)

This package protects your webhook automatically by only allowing requests from the [IP range](https://postmarkapp.com/support/article/800-ips-for-firewalls#webhooks) that Postmark uses.

Disabling webhook protection
----------------------------

[](#disabling-webhook-protection)

If you need to test in Development using ngrok to test Postmark webhooks you can disable the webhook entirely. To do that, add `POSTMARK_WEBHOOKS_MIDDLEWARE_DISABLE=true` to your `.env` file.

```
POSTMARK_WEBHOOKS_MIDDLEWARE_DISABLE=true
```

**WARNING:** Do not forget to enable it back in production!

Usage
-----

[](#usage)

Postmark can send out several event types by posting a webhook.
You can find the [full list of webhooks](https://postmarkapp.com/developer/webhooks/webhooks-overview) in the Postmark documentation.

All webhook requests will be logged in the `postmark_webhook_logs` table.
The table has a `payload` column where the entire payload of the incoming webhook is saved.
The ID Postmark assigned to the original message will be saved in the `message_id` column,
the event type will be stored in the `record_type` column and the email address as well in the `email` column.

> Note that event types will be converted to `snake_case`.
> For example `SpamComplaint` will be saved as `spam_complaint`.

### Events

[](#events)

Whenever a webhook call comes in, this package will fire a `PostmarkWebhookCalled` event.
You may register an event listener in the `EventServiceProvider`:

```
/**
 * The event listener mappings for the application.
 *
 * @var array
 */
protected $listen = [
    PostmarkWebhookCalled::class => [
        YourListener::class,
    ],
];
```

Example of a listener:

```
