1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Paypal\Block\Adminhtml\Order;
use Magento\Backend\Block\Widget\Context;
use Magento\Framework\Registry;
use Magento\Paypal\Model\Adminhtml\Express;
use Magento\Sales\Block\Adminhtml\Order\View as OrderView;
use Magento\Sales\Helper\Reorder;
use Magento\Sales\Model\Config;
use Magento\Sales\Model\Order;
use Magento\Framework\Exception\LocalizedException;
/**
* Adminhtml sales order view.
* @api
* @since 100.2.2
*/
class View extends OrderView
{
/**
* @var Express
*/
private $express;
/**
* @param Context $context
* @param Registry $registry
* @param Config $salesConfig
* @param Reorder $reorderHelper
* @param Express $express
* @param array $data
*/
public function __construct(
Context $context,
Registry $registry,
Config $salesConfig,
Reorder $reorderHelper,
Express $express,
array $data = []
) {
$this->express = $express;
parent::__construct(
$context,
$registry,
$salesConfig,
$reorderHelper,
$data
);
}
/**
* Constructor.
*
* @return void
* @throws LocalizedException
* @since 100.2.2
*/
protected function _construct()
{
parent::_construct();
$order = $this->getOrder();
if ($order === null) {
return;
}
$message = __('Are you sure you want to authorize full order amount?');
if ($this->_isAllowedAction('Magento_Paypal::authorization') && $this->canAuthorize($order)) {
$this->addButton(
'order_authorize',
[
'label' => __('Authorize'),
'class' => 'authorize',
'onclick' => "confirmSetLocation('{$message}', '{$this->getPaymentAuthorizationUrl()}')",
]
);
}
}
/**
* Returns URL for authorization of full order amount.
*
* @return string
*/
private function getPaymentAuthorizationUrl(): string
{
return $this->getUrl('paypal/express/authorization');
}
/**
* Checks if order available for payment authorization.
*
* @param Order $order
* @return bool
* @throws LocalizedException
* @since 100.2.2
*/
public function canAuthorize(Order $order): bool
{
if ($order->canUnhold() || $order->isPaymentReview()) {
return false;
}
$state = $order->getState();
if ($order->isCanceled() || $state === Order::STATE_COMPLETE || $state === Order::STATE_CLOSED) {
return false;
}
return $this->express->isOrderAuthorizationAllowed($order->getPayment());
}
}