TotalMinMax.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Model\Checks;
  7. use Magento\Payment\Model\MethodInterface;
  8. use Magento\Quote\Model\Quote;
  9. /**
  10. * Checks is order total in allowed range or not
  11. *
  12. * @api
  13. * @since 100.0.2
  14. */
  15. class TotalMinMax implements SpecificationInterface
  16. {
  17. /**
  18. * Config value key for min order total
  19. */
  20. const MIN_ORDER_TOTAL = 'min_order_total';
  21. /**
  22. * Config value key for max order total
  23. */
  24. const MAX_ORDER_TOTAL = 'max_order_total';
  25. /**
  26. * Check whether payment method is applicable to quote
  27. *
  28. * @param MethodInterface $paymentMethod
  29. * @param \Magento\Quote\Model\Quote $quote
  30. * @return bool
  31. */
  32. public function isApplicable(MethodInterface $paymentMethod, Quote $quote)
  33. {
  34. $total = $quote->getBaseGrandTotal();
  35. $minTotal = $paymentMethod->getConfigData(self::MIN_ORDER_TOTAL);
  36. $maxTotal = $paymentMethod->getConfigData(self::MAX_ORDER_TOTAL);
  37. if (!empty($minTotal) && $total < $minTotal || !empty($maxTotal) && $total > $maxTotal) {
  38. return false;
  39. }
  40. return true;
  41. }
  42. }