Skip to content

Commit 17603f2

Browse files
authored
ENGCOM-8283: Avoid exception when config.xml nodes exist for not-installed payment methods #27940
2 parents af1c17d + 2e0dde8 commit 17603f2

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

app/code/Magento/Payment/Model/PaymentMethodList.php

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,53 +6,57 @@
66
namespace Magento\Payment\Model;
77

88
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;
913

10-
/**
11-
* Payment method list class.
12-
*/
13-
class PaymentMethodList implements \Magento\Payment\Api\PaymentMethodListInterface
14+
class PaymentMethodList implements PaymentMethodListInterface
1415
{
1516
/**
16-
* @var \Magento\Payment\Api\Data\PaymentMethodInterfaceFactory
17+
* @var PaymentMethodInterfaceFactory
1718
*/
1819
private $methodFactory;
1920

2021
/**
21-
* @var \Magento\Payment\Helper\Data
22+
* @var Data
2223
*/
2324
private $helper;
2425

2526
/**
26-
* @param \Magento\Payment\Api\Data\PaymentMethodInterfaceFactory $methodFactory
27-
* @param \Magento\Payment\Helper\Data $helper
27+
* @param PaymentMethodInterfaceFactory $methodFactory
28+
* @param Data $helper
2829
*/
2930
public function __construct(
30-
\Magento\Payment\Api\Data\PaymentMethodInterfaceFactory $methodFactory,
31-
\Magento\Payment\Helper\Data $helper
31+
PaymentMethodInterfaceFactory $methodFactory,
32+
Data $helper
3233
) {
3334
$this->methodFactory = $methodFactory;
3435
$this->helper = $helper;
3536
}
3637

3738
/**
38-
* {@inheritdoc}
39+
* @inheritDoc
3940
*/
4041
public function getList($storeId)
4142
{
4243
$methodsCodes = array_keys($this->helper->getPaymentMethods());
43-
4444
$methodsInstances = array_map(
4545
function ($code) {
46-
return $this->helper->getMethodInstance($code);
46+
try {
47+
return $this->helper->getMethodInstance($code);
48+
} catch (UnexpectedValueException $e) {
49+
return null;
50+
}
4751
},
4852
$methodsCodes
4953
);
5054

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);
5357
});
5458

55-
@uasort(
59+
uasort(
5660
$methodsInstances,
5761
function (MethodInterface $a, MethodInterface $b) use ($storeId) {
5862
return (int)$a->getConfigData('sort_order', $storeId) - (int)$b->getConfigData('sort_order', $storeId);
@@ -76,7 +80,7 @@ function (MethodInterface $methodInstance) use ($storeId) {
7680
}
7781

7882
/**
79-
* {@inheritdoc}
83+
* @inheritDoc
8084
*/
8185
public function getActiveList($storeId)
8286
{

dev/tests/integration/_files/Magento/TestModuleFakePaymentMethod/etc/config.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
<supported>1</supported>
3333
</instant_purchase>
3434
</fake_vault>
35+
<fake_no_model>
36+
<!-- This method on purpose does not have a 'model' node. -->
37+
<title>Fake Payment Method without &lt;model&gt;</title>
38+
<active>0</active>
39+
</fake_no_model>
3540
</payment>
3641
</default>
37-
</config>
42+
</config>

0 commit comments

Comments
 (0)