faaren-tech/webhook-receiver

Build to receive webhooks.

1.0.0-rc.3 2022-02-01 08:37 UTC

This package is auto-updated.

Last update: 2024-06-06 17:57:36 UTC


README

Open Tasks

  1. Add authorization logic (e.g. for Stripe)
  2. Custom table name

Webhook Receiver

This package will be used by all FAAREN Services which receive webhooks. It provides a basic structure to handle incoming webhooks. With this package you can simply define new endpoints for webhooks. Those webhooks will be stored within a database. Via a simple HandlerInterface you can define custom handlers for each of your endpoints.
This package also offers a basic CRUD functionality to interact with your stored webhooks via the Webhook model.

Installation

Call the following command:

composer require faaren-tech/webhook-receiver

The package is tested only for Laravel 8.x.

Config

Publish the relevant configuration file via (select the WebhookReceiverServiceProvider from the shown list):

php artisan vendor:publish 
  • You can customize the middleware separately for webhook endpoints and crud-routes.
  • You can customize the prefix for both the webhook endpoints and the crud-routes.

Creating new endpoints

It is very easy to add new endpoints to your application.

  1. Create a new webhook handler, e.g. MyExampleWebhookHandler within app/Http/WebhookEndpoints
  2. Implement FaarenTech\WebhookReceiver\Interfaces\WebhookEndpointHandlerInterface
  3. Add the endpoint to your config/webhook_receiver configuration file (see below)
  4. Set up your new endpoint within your webhook sender (e.g. MailJet, Stripe, etc) for the endpoint webhook/endpoints/my-example-endpoint
return [
    // other configuration options
    'endpoints' => [
        'my-example-endpoint' => MyExampleWebhookHandler::class
    ]
];

Example files

If you want you can take a look at the following files:

Testing

Add the relevant testsuite to your main phpunit.xml:

<testsuites>
    ...
    <testsuite name="FaarenTechWebhookReceiver">
        <directory suffix="Test.php">./vendor/faaren-tech/webhook-receiver</directory>
    </testsuite>
</testsuites>