src/Core/Ports/Http/Webhook/Insales/UpdateOrderAction.php line 21

  1. <?php
  2.     
  3.     namespace App\Core\Ports\Http\Webhook\Insales;
  4.     use App\Core\Application\Command\Application\CalculationPayments\CalculationPaymentsCommand;
  5.     use App\Core\Application\Command\Insales\UpdateReadyExportClientCount\UpdateReadyExportClientCountCommand;
  6.     use App\Core\Domain\Model;
  7.     use App\Core\Application\Command\Insales\Webhook\UpdateOrder\UpdateOrderCommand;
  8.     use App\Core\Application\Query\Insales\GetApplication\GetApplicationQuery;
  9.     use App\Core\Domain\Infrastructure\HandlerInterface;
  10.     use Symfony\Component\HttpFoundation\Request;
  11.     use Symfony\Component\HttpFoundation\Response;
  12.     use Symfony\Component\Routing\Annotation\Route;
  13.     /**
  14.      * Обновление заказа insales
  15.      *
  16.      * Class UpdateOrderAction
  17.      * @package App\Core\Ports\Http\Webhook\Insales
  18.      */
  19.     final class UpdateOrderAction
  20.     {
  21.         public const ROUTE_NAME 'webhook.insales.update-order';
  22.     
  23.         /**
  24.          * @param HandlerInterface $handler
  25.          */
  26.         public function __construct(
  27.             private HandlerInterface $handler
  28.         )
  29.         {
  30.         }
  31.     
  32.         #[Route(
  33.             path'/webhook/insales/{uuid}/update-order',
  34.             nameself::ROUTE_NAME
  35.         )]
  36.         public function __invoke(string $uuidRequest $request): Response
  37.         {
  38.      
  39.             /** @var Model\Insales\Application $application */
  40.             $application $this->handler->handle(
  41.                 new GetApplicationQuery(
  42.                     $uuid
  43.                 )
  44.             );
  45.             
  46.             /** @var Model\Insales\Order $order */
  47.             $order $this->handler->handle(
  48.                 new UpdateOrderCommand(
  49.                     $application,
  50.                     \json_decode($request->getContent(), true)
  51.                 )
  52.             );
  53.             $this->handler->handle(
  54.                 (new CalculationPaymentsCommand($application))
  55.                     ->setClient($order->getClient())
  56.             );
  57.     
  58.             $this->handler->handle(
  59.                 new UpdateReadyExportClientCountCommand(
  60.                     $application
  61.                 )
  62.             );
  63.         
  64.             return new Response(nullResponse::HTTP_OK);
  65.         }
  66.     }