Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PaymentMethodList.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Payment\Model;
7 
9 
14 {
18  private $methodFactory;
19 
23  private $helper;
24 
29  public function __construct(
30  \Magento\Payment\Api\Data\PaymentMethodInterfaceFactory $methodFactory,
31  \Magento\Payment\Helper\Data $helper
32  ) {
33  $this->methodFactory = $methodFactory;
34  $this->helper = $helper;
35  }
36 
40  public function getList($storeId)
41  {
42  $methodsCodes = array_keys($this->helper->getPaymentMethods());
43 
44  $methodsInstances = array_map(
45  function ($code) {
46  return $this->helper->getMethodInstance($code);
47  },
48  $methodsCodes
49  );
50 
51  $methodsInstances = array_filter($methodsInstances, function (MethodInterface $method) {
52  return !($method instanceof \Magento\Payment\Model\Method\Substitution);
53  });
54 
55  @uasort(
56  $methodsInstances,
57  function (MethodInterface $a, MethodInterface $b) use ($storeId) {
58  return (int)$a->getConfigData('sort_order', $storeId) - (int)$b->getConfigData('sort_order', $storeId);
59  }
60  );
61 
62  $methodList = array_map(
63  function (MethodInterface $methodInstance) use ($storeId) {
64 
65  return $this->methodFactory->create([
66  'code' => (string)$methodInstance->getCode(),
67  'title' => (string)$methodInstance->getTitle(),
68  'storeId' => (int)$storeId,
69  'isActive' => (bool)$methodInstance->isActive($storeId)
70  ]);
71  },
72  $methodsInstances
73  );
74 
75  return array_values($methodList);
76  }
77 
81  public function getActiveList($storeId)
82  {
83  $methodList = array_filter(
84  $this->getList($storeId),
85  function (PaymentMethodInterface $method) {
86  return $method->getIsActive();
87  }
88  );
89 
90  return array_values($methodList);
91  }
92 }
$helper
Definition: iframe.phtml:13
__construct(\Magento\Payment\Api\Data\PaymentMethodInterfaceFactory $methodFactory, \Magento\Payment\Helper\Data $helper)
$method
Definition: info.phtml:13
getConfigData($field, $storeId=null)
$code
Definition: info.phtml:12