src/EventSubscriber/Order/OrderCheckoutSubscriber.php line 33
<?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\Order;use App\Entity\Customer\Customer;use App\Entity\Order\Order;use App\Generator\Order\OrderNumberGeneratorInterface;use App\OrderProductionStates;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\Workflow\Event\Event;use Symfony\Component\Workflow\WorkflowInterface;use Webmozart\Assert\Assert;class OrderCheckoutSubscriber implements EventSubscriberInterface{public function __construct(private OrderNumberGeneratorInterface $orderNumberGenerator,private WorkflowInterface $orderProductionStateMachine,) {}public function onEnter(Event $event){/** @var Order $order */$order = $event->getSubject();Assert::isInstanceOf($order, Order::class);/** @var Customer $customer */$customer = $order->getCustomer();Assert::notNull($customer, 'Can not create order without customer');// When order was paid by Stripe (direct or complement), do not check/debit creditsif (!$order->isDirectPayment()) {Assert::greaterThanEq(($customer->getCredits() - $order->getTotal()),0,'Not enough customer credits to decrease for order.',);$customer->setCredits($customer->getCredits() - $order->getTotal());}$order->setCheckoutCompletedAt(new \DateTimeImmutable());$order->setNumber($this->orderNumberGenerator->generate($order));$this->orderProductionStateMachine->apply($order, OrderProductionStates::TRANSITION_CUSTOMER_DOWLOAD);}public static function getSubscribedEvents(){return ['workflow.order.enter.in_production' => 'onEnter',];}}