Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
View.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
18 
24 class View extends OrderView
25 {
29  private $express;
30 
39  public function __construct(
40  Context $context,
42  Config $salesConfig,
43  Reorder $reorderHelper,
44  Express $express,
45  array $data = []
46  ) {
47  $this->express = $express;
48 
49  parent::__construct(
50  $context,
51  $registry,
52  $salesConfig,
53  $reorderHelper,
54  $data
55  );
56  }
57 
65  protected function _construct()
66  {
67  parent::_construct();
68 
69  $order = $this->getOrder();
70  if ($order === null) {
71  return;
72  }
73  $message = __('Are you sure you want to authorize full order amount?');
74  if ($this->_isAllowedAction('Magento_Paypal::authorization') && $this->canAuthorize($order)) {
75  $this->addButton(
76  'order_authorize',
77  [
78  'label' => __('Authorize'),
79  'class' => 'authorize',
80  'onclick' => "confirmSetLocation('{$message}', '{$this->getPaymentAuthorizationUrl()}')",
81  ]
82  );
83  }
84  }
85 
91  private function getPaymentAuthorizationUrl(): string
92  {
93  return $this->getUrl('paypal/express/authorization');
94  }
95 
104  public function canAuthorize(Order $order): bool
105  {
106  if ($order->canUnhold() || $order->isPaymentReview()) {
107  return false;
108  }
109 
110  $state = $order->getState();
111  if ($order->isCanceled() || $state === Order::STATE_COMPLETE || $state === Order::STATE_CLOSED) {
112  return false;
113  }
114 
115  return $this->express->isOrderAuthorizationAllowed($order->getPayment());
116  }
117 }
$order
Definition: order.php:55
__()
Definition: __.php:13
$message
__construct(Context $context, Registry $registry, Config $salesConfig, Reorder $reorderHelper, Express $express, array $data=[])
Definition: View.php:39
getUrl($params='', $params2=[])
Definition: View.php:316
addButton($buttonId, $data, $level=0, $sortOrder=0, $region='toolbar')
Definition: Container.php:85