custom/plugins/SwagPayPal/src/Storefront/Data/FundingSubscriber.php line 42

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\Storefront\Data;
  8. use Shopware\Storefront\Pagelet\Footer\FooterPageletLoadedEvent;
  9. use Swag\PayPal\Setting\Exception\PayPalSettingsInvalidException;
  10. use Swag\PayPal\Setting\Service\SettingsValidationServiceInterface;
  11. use Swag\PayPal\Storefront\Data\Service\FundingEligibilityDataService;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. /**
  14.  * @internal
  15.  */
  16. class FundingSubscriber implements EventSubscriberInterface
  17. {
  18.     public const FUNDING_ELIGIBILITY_EXTENSION 'swagPayPalFundingEligibility';
  19.     private FundingEligibilityDataService $fundingEligibilityDataService;
  20.     private SettingsValidationServiceInterface $settingsValidationService;
  21.     public function __construct(
  22.         SettingsValidationServiceInterface $settingsValidationService,
  23.         FundingEligibilityDataService $fundingEligibilityDataService
  24.     ) {
  25.         $this->settingsValidationService $settingsValidationService;
  26.         $this->fundingEligibilityDataService $fundingEligibilityDataService;
  27.     }
  28.     public static function getSubscribedEvents(): array
  29.     {
  30.         return [
  31.             FooterPageletLoadedEvent::class => 'addFundingAvailabilityData',
  32.         ];
  33.     }
  34.     public function addFundingAvailabilityData(FooterPageletLoadedEvent $event): void
  35.     {
  36.         try {
  37.             $this->settingsValidationService->validate($event->getSalesChannelContext()->getSalesChannelId());
  38.         } catch (PayPalSettingsInvalidException $e) {
  39.             return;
  40.         }
  41.         $data $this->fundingEligibilityDataService->buildData($event->getSalesChannelContext());
  42.         if ($data === null) {
  43.             return;
  44.         }
  45.         $event->getPagelet()->addExtension(self::FUNDING_ELIGIBILITY_EXTENSION$data);
  46.     }
  47. }