AmplitudeProvider.php
2 months ago
AssetsProvider.php
11 months ago
BlocksProvider.php
3 months ago
ClientProvider.php
2 months ago
ContainerProvider.php
11 months ago
DatabaseProvider.php
8 months ago
HostingRoutesProvider.php
2 months ago
IntegrationsProvider.php
5 months ago
JobsProvider.php
7 months ago
MenusProvider.php
11 months ago
NoticesProvider.php
4 months ago
ProviderInterface.php
11 months ago
RedirectsProvider.php
11 months ago
RoutesProvider.php
9 months ago
SurveysProvider.php
2 months ago
TrackingProvider.php
8 months ago
WebhooksProvider.php
8 months ago
WpdbProvider.php
11 months ago
WebhooksProvider.php
48 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Hostinger\Reach\Providers; |
| 4 | use Hostinger\Reach\Api\Handlers\IntegrationsApiHandler; |
| 5 | use Hostinger\Reach\Api\Handlers\ReachApiHandler; |
| 6 | use Hostinger\Reach\Api\Webhooks\Handlers\CartAbandoned; |
| 7 | use Hostinger\Reach\Api\Webhooks\Handlers\OrderPurchased; |
| 8 | use Hostinger\Reach\Container; |
| 9 | use Hostinger\Reach\Repositories\CartRepository; |
| 10 | use Hostinger\Reach\Repositories\FormRepository; |
| 11 | |
| 12 | if ( ! defined( 'ABSPATH' ) ) { |
| 13 | die; |
| 14 | } |
| 15 | |
| 16 | class WebhooksProvider implements ProviderInterface { |
| 17 | |
| 18 | public function register( Container $container ): void { |
| 19 | |
| 20 | $webhooks = array( |
| 21 | OrderPurchased::class => array( |
| 22 | $container->get( ReachApiHandler::class ), |
| 23 | $container->get( IntegrationsApiHandler::class ), |
| 24 | $container->get( FormRepository::class ), |
| 25 | ), |
| 26 | CartAbandoned::class => array( |
| 27 | $container->get( ReachApiHandler::class ), |
| 28 | $container->get( IntegrationsApiHandler::class ), |
| 29 | $container->get( CartRepository::class ), |
| 30 | $container->get( FormRepository::class ), |
| 31 | ), |
| 32 | ); |
| 33 | |
| 34 | foreach ( $webhooks as $class_name => $dependencies ) { |
| 35 | $webhook = new $class_name( ...$dependencies ); |
| 36 | $container->set( |
| 37 | $webhook::class, |
| 38 | function () use ( $webhook ) { |
| 39 | return $webhook; |
| 40 | } |
| 41 | ); |
| 42 | |
| 43 | $webhook = $container->get( $webhook::class ); |
| 44 | $webhook->init(); |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 |