src/Component/Stripe/Event/VendorCheckListener.php line 21

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace BitBag\OpenMarketplace\Component\Stripe\Event;
  4. use BitBag\OpenMarketplace\Component\Customer\Model\CustomerInterface;
  5. use Sylius\Component\Customer\Context\CustomerContextInterface;
  6. use Symfony\Component\HttpKernel\Event\RequestEvent;
  7. use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
  8. final class VendorCheckListener
  9. {
  10.     private const ORGANIZATION_STRIPE_SETUP_ROUTE 'bitbag_sylius_organization_plugin_shop_account_organization_payments';
  11.     public function __construct(
  12.         private CustomerContextInterface $customerContext
  13.     ) {
  14.     }
  15.     public function onKernelRequest(RequestEvent $event): void
  16.     {
  17.         $request $event->getRequest();
  18.         if (self::ORGANIZATION_STRIPE_SETUP_ROUTE === $request->attributes->get('_route')) {
  19.             /** @var CustomerInterface $customer */
  20.             $customer $this->customerContext->getCustomer();
  21.             $vendor $customer->getOrganizationVendor();
  22.             if (null === $vendor) {
  23.                 throw new AccessDeniedHttpException();
  24.             }
  25.         }
  26.     }
  27. }