Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RegisterCaptureNotificationOperation.php
Go to the documentation of this file.
1 <?php
7 
12 
14 {
23  public function registerCaptureNotification(OrderPaymentInterface $payment, $amount, $skipFraudDetection = false)
24  {
28  $payment->setTransactionId(
29  $this->transactionManager->generateTransactionId(
30  $payment,
32  $payment->getAuthorizationTransaction()
33  )
34  );
35 
36  $order = $payment->getOrder();
37  $amount = (double)$amount;
38  $invoice = $this->getInvoiceForTransactionId($order, $payment->getTransactionId());
39 
40  // register new capture
41  if (!$invoice) {
42  if ($payment->isSameCurrency() && $payment->isCaptureFinal($amount)) {
43  $invoice = $order->prepareInvoice()->register();
44  $invoice->setOrder($order);
45  $order->addRelatedObject($invoice);
46  $payment->setCreatedInvoice($invoice);
47  $payment->setShouldCloseParentTransaction(true);
48  } else {
49  $payment->setIsFraudDetected(!$skipFraudDetection);
50  $this->updateTotals($payment, ['base_amount_paid_online' => $amount]);
51  }
52  }
53 
54  if (!$payment->getIsTransactionPending()) {
55  if ($invoice && Invoice::STATE_OPEN == $invoice->getState()) {
56  $invoice->setOrder($order);
57  $invoice->pay();
58  $this->updateTotals($payment, ['base_amount_paid_online' => $amount]);
59  $order->addRelatedObject($invoice);
60  }
61  }
62 
63  $message = $this->stateCommand->execute($payment, $amount, $order);
64  $transaction = $payment->addTransaction(
66  $invoice,
67  true
68  );
69  $message = $payment->prependMessage($message);
70  $payment->addTransactionCommentsToOrder($transaction, $message);
71  return $payment;
72  }
73 }
$transaction
getInvoiceForTransactionId(OrderInterface $order, $transactionId)
$order
Definition: order.php:55
registerCaptureNotification($amount, $skipFraudDetection=false)
Definition: Payment.php:479
$message
$amount
Definition: order.php:14
$payment
Definition: order.php:17
$invoice