Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
InvoiceOrder Class Reference
Inheritance diagram for InvoiceOrder:
InvoiceOrderInterface

Public Member Functions

 __construct (ResourceConnection $resourceConnection, OrderRepositoryInterface $orderRepository, InvoiceDocumentFactory $invoiceDocumentFactory, PaymentAdapterInterface $paymentAdapter, OrderStateResolverInterface $orderStateResolver, OrderConfig $config, InvoiceRepository $invoiceRepository, InvoiceOrderValidator $invoiceOrderValidator, NotifierInterface $notifierInterface, LoggerInterface $logger)
 
 execute ( $orderId, $capture=false, array $items=[], $notify=false, $appendComment=false, InvoiceCommentCreationInterface $comment=null, InvoiceCreationArgumentsInterface $arguments=null)
 
- Public Member Functions inherited from InvoiceOrderInterface
 execute ( $orderId, $capture=false, array $items=[], $notify=false, $appendComment=false, \Magento\Sales\Api\Data\InvoiceCommentCreationInterface $comment=null, \Magento\Sales\Api\Data\InvoiceCreationArgumentsInterface $arguments=null)
 

Detailed Description

Class InvoiceOrder @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 27 of file InvoiceOrder.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ResourceConnection  $resourceConnection,
OrderRepositoryInterface  $orderRepository,
InvoiceDocumentFactory  $invoiceDocumentFactory,
PaymentAdapterInterface  $paymentAdapter,
OrderStateResolverInterface  $orderStateResolver,
OrderConfig  $config,
InvoiceRepository  $invoiceRepository,
InvoiceOrderValidator  $invoiceOrderValidator,
NotifierInterface  $notifierInterface,
LoggerInterface  $logger 
)

InvoiceOrder constructor.

Parameters
ResourceConnection$resourceConnection
OrderRepositoryInterface$orderRepository
InvoiceDocumentFactory$invoiceDocumentFactory
PaymentAdapterInterface$paymentAdapter
OrderStateResolverInterface$orderStateResolver
OrderConfig$config
InvoiceRepository$invoiceRepository
InvoiceOrderValidator$invoiceOrderValidator
NotifierInterface$notifierInterface
LoggerInterface$logger@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 93 of file InvoiceOrder.php.

104  {
105  $this->resourceConnection = $resourceConnection;
106  $this->orderRepository = $orderRepository;
107  $this->invoiceDocumentFactory = $invoiceDocumentFactory;
108  $this->paymentAdapter = $paymentAdapter;
109  $this->orderStateResolver = $orderStateResolver;
110  $this->config = $config;
111  $this->invoiceRepository = $invoiceRepository;
112  $this->invoiceOrderValidator = $invoiceOrderValidator;
113  $this->notifierInterface = $notifierInterface;
114  $this->logger = $logger;
115  }
$invoiceRepository
$config
Definition: fraud_order.php:17
$orderRepository
Definition: order.php:69
$logger

Member Function Documentation

◆ execute()

execute (   $orderId,
  $capture = false,
array  $items = [],
  $notify = false,
  $appendComment = false,
InvoiceCommentCreationInterface  $comment = null,
InvoiceCreationArgumentsInterface  $arguments = null 
)
Parameters
int$orderId
bool$capture
array$items
bool$notify
bool$appendComment
\Magento\Sales\Api\Data\InvoiceCommentCreationInterface | null$comment
\Magento\Sales\Api\Data\InvoiceCreationArgumentsInterface | null$arguments
Returns
int
Exceptions

Definition at line 132 of file InvoiceOrder.php.

140  {
141  $connection = $this->resourceConnection->getConnection('sales');
142  $order = $this->orderRepository->get($orderId);
143  $invoice = $this->invoiceDocumentFactory->create(
144  $order,
145  $items,
146  $comment,
147  ($appendComment && $notify),
148  $arguments
149  );
150  $errorMessages = $this->invoiceOrderValidator->validate(
151  $order,
152  $invoice,
153  $capture,
154  $items,
155  $notify,
156  $appendComment,
157  $comment,
158  $arguments
159  );
160  if ($errorMessages->hasMessages()) {
161  throw new \Magento\Sales\Exception\DocumentValidationException(
162  __("Invoice Document Validation Error(s):\n" . implode("\n", $errorMessages->getMessages()))
163  );
164  }
165  $connection->beginTransaction();
166  try {
167  $order = $this->paymentAdapter->pay($order, $invoice, $capture);
168  $order->setState(
169  $this->orderStateResolver->getStateForOrder($order, [OrderStateResolverInterface::IN_PROGRESS])
170  );
171  $order->setStatus($this->config->getStateDefaultStatus($order->getState()));
172  $invoice->setState(\Magento\Sales\Model\Order\Invoice::STATE_PAID);
173  $this->invoiceRepository->save($invoice);
174  $this->orderRepository->save($order);
175  $connection->commit();
176  } catch (\Exception $e) {
177  $this->logger->critical($e);
178  $connection->rollBack();
179  throw new \Magento\Sales\Exception\CouldNotInvoiceException(
180  __('Could not save an invoice, see error log for details')
181  );
182  }
183  if ($notify) {
184  if (!$appendComment) {
185  $comment = null;
186  }
187  $this->notifierInterface->notify($order, $invoice, $comment);
188  }
189  return $invoice->getEntityId();
190  }
$order
Definition: order.php:55
__()
Definition: __.php:13
$invoice
$arguments
$connection
Definition: bulk.php:13
$items

The documentation for this class was generated from the following file: