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

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. class FundingSubscriber implements EventSubscriberInterface
  14. {
  15.     public const FUNDING_ELIGIBILITY_EXTENSION 'swagPayPalFundingEligibility';
  16.     private FundingEligibilityDataService $fundingEligibilityDataService;
  17.     private SettingsValidationServiceInterface $settingsValidationService;
  18.     public function __construct(
  19.         SettingsValidationServiceInterface $settingsValidationService,
  20.         FundingEligibilityDataService $fundingEligibilityDataService
  21.     ) {
  22.         $this->settingsValidationService $settingsValidationService;
  23.         $this->fundingEligibilityDataService $fundingEligibilityDataService;
  24.     }
  25.     public static function getSubscribedEvents(): array
  26.     {
  27.         return [
  28.             FooterPageletLoadedEvent::class => 'addFundingAvailabilityData',
  29.         ];
  30.     }
  31.     public function addFundingAvailabilityData(FooterPageletLoadedEvent $event): void
  32.     {
  33.         try {
  34.             $this->settingsValidationService->validate($event->getSalesChannelContext()->getSalesChannelId());
  35.         } catch (PayPalSettingsInvalidException $e) {
  36.             return;
  37.         }
  38.         $event->getPagelet()->addExtension(
  39.             self::FUNDING_ELIGIBILITY_EXTENSION,
  40.             $this->fundingEligibilityDataService->buildData($event->getSalesChannelContext())
  41.         );
  42.     }
  43. }