vendor/store.shopware.com/swagpaypal/src/Webhook/Registration/WebhookSubscriber.php line 43

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /*
  3.  * (c) shopware AG <info@shopware.com>
  4.  * For the full copyright and license information, please view the LICENSE
  5.  * file that was distributed with this source code.
  6.  */
  7. namespace Swag\PayPal\Webhook\Registration;
  8. use Psr\Log\LoggerInterface;
  9. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityDeletedEvent;
  10. use Shopware\Core\System\SalesChannel\SalesChannelEvents;
  11. use Shopware\Core\System\SystemConfig\SystemConfigService;
  12. use Swag\PayPal\Setting\Settings;
  13. use Swag\PayPal\Webhook\WebhookServiceInterface;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. class WebhookSubscriber implements EventSubscriberInterface
  16. {
  17.     private LoggerInterface $logger;
  18.     private SystemConfigService $systemConfigService;
  19.     private WebhookServiceInterface $webhookService;
  20.     public function __construct(
  21.         LoggerInterface $logger,
  22.         SystemConfigService $systemConfigService,
  23.         WebhookServiceInterface $webhookService
  24.     ) {
  25.         $this->logger $logger;
  26.         $this->systemConfigService $systemConfigService;
  27.         $this->webhookService $webhookService;
  28.     }
  29.     public static function getSubscribedEvents(): array
  30.     {
  31.         return [
  32.             SalesChannelEvents::SALES_CHANNEL_DELETED => 'removeSalesChannelWebhookConfiguration',
  33.         ];
  34.     }
  35.     public function removeSalesChannelWebhookConfiguration(EntityDeletedEvent $event): void
  36.     {
  37.         $generalWebhookId $this->systemConfigService->getString(Settings::WEBHOOK_ID);
  38.         foreach ($event->getIds() as $salesChannelId) {
  39.             $webhookId $this->systemConfigService->getString(Settings::WEBHOOK_ID$salesChannelId);
  40.             try {
  41.                 if ($webhookId !== $generalWebhookId) {
  42.                     $this->webhookService->deregisterWebhook($salesChannelId);
  43.                 }
  44.             } catch (\Throwable $e) {
  45.                 $this->logger->error($e->getMessage(), ['error' => $e]);
  46.             }
  47.         }
  48.     }
  49. }