Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Authorization.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
12 use Magento\Framework\Controller\Result\RawFactory;
24 use Psr\Log\LoggerInterface;
25 
32 class Authorization extends Order
33 {
38  const ADMIN_RESOURCE = 'Magento_Paypal::authorization';
39 
43  private $express;
44 
60  public function __construct(
61  Action\Context $context,
62  Registry $coreRegistry,
63  FileFactory $fileFactory,
64  InlineInterface $translateInline,
68  RawFactory $resultRawFactory,
72  Express $express
73  ) {
74  $this->express = $express;
75 
76  parent::__construct(
77  $context,
78  $coreRegistry,
79  $fileFactory,
80  $translateInline,
87  $logger
88  );
89  }
90 
96  public function execute(): Redirect
97  {
98  $resultRedirect = $this->resultRedirectFactory->create();
99  $order = $this->_initOrder();
100  if ($order !== false) {
101  try {
102  $this->express->authorizeOrder($order);
103  $this->orderRepository->save($order);
104  $this->messageManager->addSuccessMessage(__('Payment authorization has been successfully created.'));
105  } catch (LocalizedException $e) {
106  $this->messageManager->addErrorMessage($e->getMessage());
107  } catch (\Throwable $e) {
108  $this->messageManager->addErrorMessage(__('Unable to make payment authorization.'));
109  }
110 
111  $resultRedirect->setPath('sales/order/view', ['order_id' => $order->getId()]);
112  } else {
113  $resultRedirect->setPath('sales/order/index');
114  }
115 
116  return $resultRedirect;
117  }
118 }
$order
Definition: order.php:55
__()
Definition: __.php:13
__construct(Action\Context $context, Registry $coreRegistry, FileFactory $fileFactory, InlineInterface $translateInline, PageFactory $resultPageFactory, JsonFactory $resultJsonFactory, LayoutFactory $resultLayoutFactory, RawFactory $resultRawFactory, OrderManagementInterface $orderManagement, OrderRepositoryInterface $orderRepository, LoggerInterface $logger, Express $express)