Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractOperation.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Framework\Event\ManagerInterface as EventManagerInterface;
15 
19 abstract class AbstractOperation
20 {
24  protected $stateCommand;
25 
30 
35 
39  protected $eventManager;
40 
47  public function __construct(
51  EventManagerInterface $eventManager
52  ) {
53  $this->stateCommand = $stateCommand;
54  $this->transactionBuilder = $transactionBuilder;
55  $this->transactionManager = $transactionManager;
56  $this->eventManager = $eventManager;
57  }
58 
66  protected function invoice(OrderPaymentInterface $payment)
67  {
69  $invoice = $payment->getOrder()->prepareInvoice();
70 
71  $invoice->register();
72  if ($payment->getMethodInstance()->canCapture()) {
73  $invoice->capture();
74  }
75 
76  $payment->getOrder()->addRelatedObject($invoice);
77  return $invoice;
78  }
79 
89  {
90  foreach ($data as $key => $amount) {
91  if (null !== $amount) {
92  $was = $payment->getDataUsingMethod($key);
93  $payment->setDataUsingMethod($key, $was + $amount);
94  }
95  }
96  }
97 
105  protected function getInvoiceForTransactionId(OrderInterface $order, $transactionId)
106  {
107  foreach ($order->getInvoiceCollection() as $invoice) {
108  if ($invoice->getTransactionId() == $transactionId) {
109  $invoice->load($invoice->getId());
110  // to make sure all data will properly load (maybe not required)
111  return $invoice;
112  }
113  }
114  foreach ($order->getInvoiceCollection() as $invoice) {
115  if ($invoice->getState() == \Magento\Sales\Model\Order\Invoice::STATE_OPEN
116  && $invoice->load($invoice->getId())
117  ) {
118  $invoice->setTransactionId($transactionId);
119  return $invoice;
120  }
121  }
122  return false;
123  }
124 }
getInvoiceForTransactionId(OrderInterface $order, $transactionId)
$order
Definition: order.php:55
$amount
Definition: order.php:14
$payment
Definition: order.php:17
$invoice
__construct(CommandInterface $stateCommand, BuilderInterface $transactionBuilder, ManagerInterface $transactionManager, EventManagerInterface $eventManager)