Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MethodList.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Payment\Model;
8 
11 
19 {
24  protected $paymentHelper;
25 
31 
35  private $paymentMethodList;
36 
40  private $paymentMethodInstanceFactory;
41 
46  public function __construct(
47  \Magento\Payment\Helper\Data $paymentHelper,
48  \Magento\Payment\Model\Checks\SpecificationFactory $specificationFactory
49  ) {
50  $this->paymentHelper = $paymentHelper;
51  $this->methodSpecificationFactory = $specificationFactory;
52  }
53 
58  public function getAvailableMethods(\Magento\Quote\Api\Data\CartInterface $quote = null)
59  {
60  $store = $quote ? $quote->getStoreId() : null;
61  $availableMethods = [];
62 
63  foreach ($this->getPaymentMethodList()->getActiveList($store) as $method) {
64  $methodInstance = $this->getPaymentMethodInstanceFactory()->create($method);
65  if ($methodInstance->isAvailable($quote) && $this->_canUseMethod($methodInstance, $quote)) {
66  $methodInstance->setInfoInstance($quote->getPayment());
67  $availableMethods[] = $methodInstance;
68  }
69  }
70  return $availableMethods;
71  }
72 
80  protected function _canUseMethod($method, \Magento\Quote\Api\Data\CartInterface $quote)
81  {
82  return $this->methodSpecificationFactory->create(
83  [
88  ]
89  )->isApplicable(
90  $method,
91  $quote
92  );
93  }
94 
100  private function getPaymentMethodList()
101  {
102  if ($this->paymentMethodList === null) {
103  $this->paymentMethodList = ObjectManager::getInstance()->get(
104  \Magento\Payment\Api\PaymentMethodListInterface::class
105  );
106  }
107  return $this->paymentMethodList;
108  }
109 
115  private function getPaymentMethodInstanceFactory()
116  {
117  if ($this->paymentMethodInstanceFactory === null) {
118  $this->paymentMethodInstanceFactory = ObjectManager::getInstance()->get(
119  \Magento\Payment\Model\Method\InstanceFactory::class
120  );
121  }
122  return $this->paymentMethodInstanceFactory;
123  }
124 }
_canUseMethod($method, \Magento\Quote\Api\Data\CartInterface $quote)
Definition: MethodList.php:80
$quote
$method
Definition: info.phtml:13
getAvailableMethods(\Magento\Quote\Api\Data\CartInterface $quote=null)
Definition: MethodList.php:58
__construct(\Magento\Payment\Helper\Data $paymentHelper, \Magento\Payment\Model\Checks\SpecificationFactory $specificationFactory)
Definition: MethodList.php:46