21 use Psr\Log\LoggerInterface;
32 private $resourceConnection;
37 private $orderRepository;
42 private $invoiceDocumentFactory;
47 private $paymentAdapter;
52 private $orderStateResolver;
62 private $invoiceRepository;
67 private $invoiceOrderValidator;
72 private $notifierInterface;
101 InvoiceOrderValidator $invoiceOrderValidator,
107 $this->invoiceDocumentFactory = $invoiceDocumentFactory;
108 $this->paymentAdapter = $paymentAdapter;
109 $this->orderStateResolver = $orderStateResolver;
112 $this->invoiceOrderValidator = $invoiceOrderValidator;
113 $this->notifierInterface = $notifierInterface;
137 $appendComment =
false,
141 $connection = $this->resourceConnection->getConnection(
'sales');
142 $order = $this->orderRepository->get($orderId);
143 $invoice = $this->invoiceDocumentFactory->create(
147 ($appendComment && $notify),
150 $errorMessages = $this->invoiceOrderValidator->validate(
160 if ($errorMessages->hasMessages()) {
161 throw new \Magento\Sales\Exception\DocumentValidationException(
162 __(
"Invoice Document Validation Error(s):\n" . implode(
"\n", $errorMessages->getMessages()))
171 $order->setStatus($this->config->getStateDefaultStatus(
$order->getState()));
173 $this->invoiceRepository->save(
$invoice);
174 $this->orderRepository->save(
$order);
176 }
catch (\Exception $e) {
177 $this->logger->critical($e);
179 throw new \Magento\Sales\Exception\CouldNotInvoiceException(
180 __(
'Could not save an invoice, see error log for details')
184 if (!$appendComment) {
execute( $orderId, $capture=false, array $items=[], $notify=false, $appendComment=false, InvoiceCommentCreationInterface $comment=null, InvoiceCreationArgumentsInterface $arguments=null)
__construct(ResourceConnection $resourceConnection, OrderRepositoryInterface $orderRepository, InvoiceDocumentFactory $invoiceDocumentFactory, PaymentAdapterInterface $paymentAdapter, OrderStateResolverInterface $orderStateResolver, OrderConfig $config, InvoiceRepository $invoiceRepository, InvoiceOrderValidator $invoiceOrderValidator, NotifierInterface $notifierInterface, LoggerInterface $logger)