<?php
declare(strict_types=1);
namespace BitBag\OpenMarketplace\Component\Stripe\Event;
use BitBag\OpenMarketplace\Component\Customer\Model\CustomerInterface;
use Sylius\Component\Customer\Context\CustomerContextInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
final class VendorCheckListener
{
private const ORGANIZATION_STRIPE_SETUP_ROUTE = 'bitbag_sylius_organization_plugin_shop_account_organization_payments';
public function __construct(
private CustomerContextInterface $customerContext
) {
}
public function onKernelRequest(RequestEvent $event): void
{
$request = $event->getRequest();
if (self::ORGANIZATION_STRIPE_SETUP_ROUTE === $request->attributes->get('_route')) {
/** @var CustomerInterface $customer */
$customer = $this->customerContext->getCustomer();
$vendor = $customer->getOrganizationVendor();
if (null === $vendor) {
throw new AccessDeniedHttpException();
}
}
}
}