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()); } }