Skip to content

Avoid exception when config.xml nodes exist for not-installed payment methods #27940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions app/code/Magento/Payment/Model/PaymentMethodList.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,57 @@
namespace Magento\Payment\Model;

use Magento\Payment\Api\Data\PaymentMethodInterface;
use Magento\Payment\Api\Data\PaymentMethodInterfaceFactory;
use Magento\Payment\Api\PaymentMethodListInterface;
use Magento\Payment\Helper\Data;
use UnexpectedValueException;

/**
* Payment method list class.
*/
class PaymentMethodList implements \Magento\Payment\Api\PaymentMethodListInterface
class PaymentMethodList implements PaymentMethodListInterface
{
/**
* @var \Magento\Payment\Api\Data\PaymentMethodInterfaceFactory
* @var PaymentMethodInterfaceFactory
*/
private $methodFactory;

/**
* @var \Magento\Payment\Helper\Data
* @var Data
*/
private $helper;

/**
* @param \Magento\Payment\Api\Data\PaymentMethodInterfaceFactory $methodFactory
* @param \Magento\Payment\Helper\Data $helper
* @param PaymentMethodInterfaceFactory $methodFactory
* @param Data $helper
*/
public function __construct(
\Magento\Payment\Api\Data\PaymentMethodInterfaceFactory $methodFactory,
\Magento\Payment\Helper\Data $helper
PaymentMethodInterfaceFactory $methodFactory,
Data $helper
) {
$this->methodFactory = $methodFactory;
$this->helper = $helper;
}

/**
* {@inheritdoc}
* @inheritDoc
*/
public function getList($storeId)
{
$methodsCodes = array_keys($this->helper->getPaymentMethods());

$methodsInstances = array_map(
function ($code) {
return $this->helper->getMethodInstance($code);
try {
return $this->helper->getMethodInstance($code);
} catch (UnexpectedValueException $e) {
return null;
}
},
$methodsCodes
);

$methodsInstances = array_filter($methodsInstances, function (MethodInterface $method) {
return !($method instanceof \Magento\Payment\Model\Method\Substitution);
$methodsInstances = array_filter($methodsInstances, function ($method) {
return $method && !($method instanceof \Magento\Payment\Model\Method\Substitution);
});

@uasort(
uasort(
$methodsInstances,
function (MethodInterface $a, MethodInterface $b) use ($storeId) {
return (int)$a->getConfigData('sort_order', $storeId) - (int)$b->getConfigData('sort_order', $storeId);
Expand All @@ -76,7 +80,7 @@ function (MethodInterface $methodInstance) use ($storeId) {
}

/**
* {@inheritdoc}
* @inheritDoc
*/
public function getActiveList($storeId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
<supported>1</supported>
</instant_purchase>
</fake_vault>
<fake_no_model>
<!-- This method on purpose does not have a 'model' node. -->
<title>Fake Payment Method without &lt;model&gt;</title>
<active>0</active>
</fake_no_model>
</payment>
</default>
</config>
</config>