src/EventSubscriber/Payment/PaymentPromotionCountSubscriber.php line 30
<?php/** This file is part of the Pellipop project.** (c) Mobizel** For the full copyright and license information, please view the LICENSE* file that was distributed with this source code.*/declare(strict_types=1);namespace App\EventSubscriber\Payment;use App\Entity\Payment\Payment;use App\Entity\Promotion\PromotionCode;use Sylius\Component\Resource\Repository\RepositoryInterface;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\Workflow\Event\Event;use Webmozart\Assert\Assert;class PaymentPromotionCountSubscriber implements EventSubscriberInterface{public function __construct(private RepositoryInterface $promotionCodeRepository,) {}public function onEnter(Event $event){/** @var Payment $payment */$payment = $event->getSubject();Assert::isInstanceOf($payment, Payment::class);/** @var PromotionCode|null $promotionCode */$promotionCode = $payment->getPromotionCode();if (null !== $promotionCode) {$promotionCode->setUsed($promotionCode->getUsed() + 1);$promotionCode->setUsedAt(new \DateTime());if (null !== $payment->getCustomer()) {$promotionCode->setUserEmail($payment->getCustomer()->getEmail());}$this->promotionCodeRepository->add($promotionCode);}}public static function getSubscribedEvents(){return ['workflow.payment.enter.completed' => 'onEnter',];}}