OrderCanInvoice.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Paypal\Plugin;
  8. use Magento\Paypal\Model\Adminhtml\Express;
  9. use Magento\Sales\Model\Order;
  10. /**
  11. * Decorates Order::canInvoice method for PayPal Express payments.
  12. */
  13. class OrderCanInvoice
  14. {
  15. /**
  16. * @var Express
  17. */
  18. private $express;
  19. /**
  20. * Initialize dependencies.
  21. *
  22. * @param Express $express
  23. */
  24. public function __construct(Express $express)
  25. {
  26. $this->express = $express;
  27. }
  28. /**
  29. * Checks a possibility to invoice of PayPal Express payments when payment action is "order".
  30. *
  31. * @param Order $order
  32. * @param bool $result
  33. * @return bool
  34. * @throws \Magento\Framework\Exception\LocalizedException
  35. */
  36. public function afterCanInvoice(Order $order, bool $result): bool
  37. {
  38. if (!$order->getPayment()) {
  39. return false;
  40. }
  41. if ($this->express->isOrderAuthorizationAllowed($order->getPayment())) {
  42. return false;
  43. }
  44. return $result;
  45. }
  46. }