6
6
namespace Magento \Payment \Model ;
7
7
8
8
use Magento \Payment \Api \Data \PaymentMethodInterface ;
9
+ use Magento \Payment \Api \Data \PaymentMethodInterfaceFactory ;
10
+ use Magento \Payment \Api \PaymentMethodListInterface ;
11
+ use Magento \Payment \Helper \Data ;
12
+ use UnexpectedValueException ;
9
13
10
- /**
11
- * Payment method list class.
12
- */
13
- class PaymentMethodList implements \Magento \Payment \Api \PaymentMethodListInterface
14
+ class PaymentMethodList implements PaymentMethodListInterface
14
15
{
15
16
/**
16
- * @var \Magento\Payment\Api\Data\ PaymentMethodInterfaceFactory
17
+ * @var PaymentMethodInterfaceFactory
17
18
*/
18
19
private $ methodFactory ;
19
20
20
21
/**
21
- * @var \Magento\Payment\Helper\ Data
22
+ * @var Data
22
23
*/
23
24
private $ helper ;
24
25
25
26
/**
26
- * @param \Magento\Payment\Api\Data\ PaymentMethodInterfaceFactory $methodFactory
27
- * @param \Magento\Payment\Helper\ Data $helper
27
+ * @param PaymentMethodInterfaceFactory $methodFactory
28
+ * @param Data $helper
28
29
*/
29
30
public function __construct (
30
- \ Magento \ Payment \ Api \ Data \ PaymentMethodInterfaceFactory $ methodFactory ,
31
- \ Magento \ Payment \ Helper \ Data $ helper
31
+ PaymentMethodInterfaceFactory $ methodFactory ,
32
+ Data $ helper
32
33
) {
33
34
$ this ->methodFactory = $ methodFactory ;
34
35
$ this ->helper = $ helper ;
35
36
}
36
37
37
38
/**
38
- * {@inheritdoc}
39
+ * @inheritDoc
39
40
*/
40
41
public function getList ($ storeId )
41
42
{
42
43
$ methodsCodes = array_keys ($ this ->helper ->getPaymentMethods ());
43
-
44
44
$ methodsInstances = array_map (
45
45
function ($ code ) {
46
- return $ this ->helper ->getMethodInstance ($ code );
46
+ try {
47
+ return $ this ->helper ->getMethodInstance ($ code );
48
+ } catch (UnexpectedValueException $ e ) {
49
+ return null ;
50
+ }
47
51
},
48
52
$ methodsCodes
49
53
);
50
54
51
- $ methodsInstances = array_filter ($ methodsInstances , function (MethodInterface $ method ) {
52
- return !($ method instanceof \Magento \Payment \Model \Method \Substitution);
55
+ $ methodsInstances = array_filter ($ methodsInstances , function ($ method ) {
56
+ return $ method && !($ method instanceof \Magento \Payment \Model \Method \Substitution);
53
57
});
54
58
55
- @ uasort (
59
+ uasort (
56
60
$ methodsInstances ,
57
61
function (MethodInterface $ a , MethodInterface $ b ) use ($ storeId ) {
58
62
return (int )$ a ->getConfigData ('sort_order ' , $ storeId ) - (int )$ b ->getConfigData ('sort_order ' , $ storeId );
@@ -76,7 +80,7 @@ function (MethodInterface $methodInstance) use ($storeId) {
76
80
}
77
81
78
82
/**
79
- * {@inheritdoc}
83
+ * @inheritDoc
80
84
*/
81
85
public function getActiveList ($ storeId )
82
86
{
0 commit comments