Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AuthorizeOperation.php
Go to the documentation of this file.
1 <?php
7 
12 
14 {
23  public function authorize(OrderPaymentInterface $payment, $isOnline, $amount)
24  {
25  // check for authorization amount to be equal to grand total
29  $payment->setShouldCloseParentTransaction(false);
30  $isSameCurrency = $payment->isSameCurrency();
31  if (!$isSameCurrency || !$payment->isCaptureFinal($amount)) {
32  $payment->setIsFraudDetected(true);
33  }
34 
35  // update totals
36  $amount = $payment->formatAmount($amount, true);
37  $payment->setBaseAmountAuthorized($amount);
38 
39  // do authorization
40  $order = $payment->getOrder();
41  if ($isOnline) {
42  // invoke authorization on gateway
43  $method = $payment->getMethodInstance();
44  $method->setStore($order->getStoreId());
45  $method->authorize($payment, $amount);
46  }
47 
48  $message = $this->stateCommand->execute($payment, $amount, $order);
49  // update transactions, order state and add comments
50  $transaction = $payment->addTransaction(Transaction::TYPE_AUTH);
51  $message = $payment->prependMessage($message);
52  $payment->addTransactionCommentsToOrder($transaction, $message);
53 
54  return $payment;
55  }
56 }
$transaction
$order
Definition: order.php:55
authorize($isOnline, $amount)
Definition: Payment.php:1105
$message
$amount
Definition: order.php:14
$payment
Definition: order.php:17
$method
Definition: info.phtml:13