This library adds support for creating Activities which are then fired as webhooks to subscribers of those activities.
Use Composer to install the package in your project:
composer require eoneopay/webhooks
Inject the \EoneoPay\Webhooks\Activities\Interface\ActivityFactoryInterface
service
into your application where an activity needs to be created. The send method on this
interface accepts an ActivityDataInterface
implementation that represents a specific
activity to be created.
For each of the different activities you will fire inside your application you will need
to create a class that implements ActivityDataInterface
.
ActivityFactoryInterface
receives an instance of ActivityDataInterface
PayloadManager
to build the payload for the ActivityDataInterface
ActivityDataInterface
and save it as a new ActivityInterface
entity.WebhookManager#processActivity
RequestProcessor#process
To integrate the package into your Laravel or Lumen you need to register the following service providers:
\EoneoPay\Webhooks\Bridge\Laravel\Providers\WebhookServiceProvider
\EoneoPay\Webhooks\Bridge\Laravel\Providers\WebhookEventServiceProvider
Any implementation of this library will need to:
EoneoPay\Webhooks\Subscription\Interfaces\SubscriptionResolverInterface
Implement a service for the interface EoneoPay\Webhooks\Payload\Interfaces\PayloadBuilderInterface
interface WebHookPayloadBuilderInterface extends PayloadBuilderInterface
{ ... }
final class PayloadBuilder implements WebHookPayloadBuilderInterface { ... }
- bind and tag the service for the interface `YourNamespace\WebHookPayloadBuilderInterface`
$this->app->bind(WebHookPayloadBuilderInterface::class, PayloadBuilder::class); $this->app->tag([WebHookPayloadBuilderInterface::class], ['webhooks_payload_builders']);
EoneoPay\Externals\Bridge\Laravel\ORM\ResolveTargetEntityExtension
to
config/doctrine.php
under the extensions
keyconfig/doctrine.php
to add the following changes to the configuration:
<?php
declare(strict_types=1);
use EoneoPay\Externals\Bridge\LaravelDoctrine\Extensions\ResolveTargetEntityExtension; use EoneoPay\Webhooks\Models\ActivityInterface; use EoneoPay\Webhooks\Models\WebhookRequestInterface; use EoneoPay\Webhooks\Models\WebhookResponseInterface; use EoneoPay\Webhooks\Bridge\Doctrine\Entities\Activity; use EoneoPay\Webhooks\Bridge\Doctrine\Entities\Lifecycle\Request; use EoneoPay\Webhooks\Bridge\Doctrine\Entities\Lifecycle\Response;
return [ 'managers' => [ 'default' => [ // ... 'namespaces' => [ // ... // Add the Webhooks Entities to the namespace mappings 'Eoneopay\Webhooks\Bridge\Doctrine\Entities' ], 'paths' => [ // ... // Add the Webhooks filepath to the Entity Manager \base_path('vendor/eoneopay/webhooks/src/Bridge/Doctrine/Entities') ] // ... ] ],
// ...
'extensions' => [
// ...
// Add the ResolveTargetEntityExtension to Doctrine
ResolveTargetEntityExtension::class
],
// ...
'replacements' => [
// Add replacements so Doctrine can look up entities by interface
ActivityInterface::class => Activity::class,
WebhookRequestInterface::class => Request::class,
WebhookResponseInterface::class => Response::class
]
];