Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CanRefund.php
Go to the documentation of this file.
1 <?php
7 
12 
16 class CanRefund implements ValidatorInterface
17 {
21  private $priceCurrency;
22 
28  public function __construct(PriceCurrencyInterface $priceCurrency)
29  {
30  $this->priceCurrency = $priceCurrency;
31  }
32 
36  public function validate($entity)
37  {
38  $messages = [];
39  if ($entity->getState() === Order::STATE_PAYMENT_REVIEW ||
40  $entity->getState() === Order::STATE_HOLDED ||
41  $entity->getState() === Order::STATE_CANCELED ||
42  $entity->getState() === Order::STATE_CLOSED
43  ) {
44  $messages[] = __(
45  'A creditmemo can not be created when an order has a status of %1',
46  $entity->getStatus()
47  );
48  } elseif (!$this->isTotalPaidEnoughForRefund($entity)) {
49  $messages[] = __('The order does not allow a creditmemo to be created.');
50  }
51 
52  return $messages;
53  }
54 
63  private function isTotalPaidEnoughForRefund(OrderInterface $order)
64  {
65  return !abs($this->priceCurrency->round($order->getTotalPaid()) - $order->getTotalRefunded()) < .0001;
66  }
67 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$order
Definition: order.php:55
__()
Definition: __.php:13
$entity
Definition: element.phtml:22
__construct(PriceCurrencyInterface $priceCurrency)
Definition: CanRefund.php:28