ValidatorCanInvoice.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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\Framework\Exception\LocalizedException;
  9. use Magento\Paypal\Model\Adminhtml\Express;
  10. use Magento\Sales\Api\Data\OrderInterface;
  11. use Magento\Sales\Model\Order\Validation\CanInvoice;
  12. /**
  13. * Decorates order canInvoice validator method for PayPal Express payments
  14. * when payment action set to "Order".
  15. */
  16. class ValidatorCanInvoice
  17. {
  18. /**
  19. * @var Express
  20. */
  21. private $express;
  22. /**
  23. * Initialize dependencies.
  24. *
  25. * @param Express $express
  26. */
  27. public function __construct(Express $express)
  28. {
  29. $this->express = $express;
  30. }
  31. /**
  32. * Checks a possibility to invoice of PayPal Express payments when payment action is "order".
  33. *
  34. * @param CanInvoice $subject
  35. * @param array $result
  36. * @param OrderInterface $order
  37. * @return array
  38. * @throws LocalizedException
  39. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  40. */
  41. public function afterValidate(CanInvoice $subject, array $result, OrderInterface $order): array
  42. {
  43. if ($this->express->isOrderAuthorizationAllowed($order->getPayment())) {
  44. $result[] = __('An invoice cannot be created when none of authorization transactions available.');
  45. }
  46. return $result;
  47. }
  48. }