Skip to content

Commit f7aa107

Browse files
authored
ENGCOM-6816: Allows additional payment checks in payment method list #24691
2 parents 863772d + af9499f commit f7aa107

File tree

2 files changed

+46
-17
lines changed

2 files changed

+46
-17
lines changed

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

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,29 @@ class MethodList
3939
*/
4040
private $paymentMethodInstanceFactory;
4141

42+
/**
43+
* @var array
44+
*/
45+
private $additionalChecks;
46+
4247
/**
4348
* @param \Magento\Payment\Helper\Data $paymentHelper
44-
* @param Checks\SpecificationFactory $specificationFactory
49+
* @param Checks\SpecificationFactory $specificationFactory
50+
* @param array $additionalChecks
4551
*/
4652
public function __construct(
4753
\Magento\Payment\Helper\Data $paymentHelper,
48-
\Magento\Payment\Model\Checks\SpecificationFactory $specificationFactory
54+
\Magento\Payment\Model\Checks\SpecificationFactory $specificationFactory,
55+
array $additionalChecks = []
4956
) {
5057
$this->paymentHelper = $paymentHelper;
5158
$this->methodSpecificationFactory = $specificationFactory;
59+
$this->additionalChecks = $additionalChecks;
5260
}
5361

5462
/**
63+
* Returns all available payment methods for the given quote.
64+
*
5565
* @param \Magento\Quote\Api\Data\CartInterface $quote
5666
* @return \Magento\Payment\Model\MethodInterface[]
5767
*/
@@ -80,12 +90,15 @@ public function getAvailableMethods(\Magento\Quote\Api\Data\CartInterface $quote
8090
protected function _canUseMethod($method, \Magento\Quote\Api\Data\CartInterface $quote)
8191
{
8292
return $this->methodSpecificationFactory->create(
83-
[
84-
AbstractMethod::CHECK_USE_CHECKOUT,
85-
AbstractMethod::CHECK_USE_FOR_COUNTRY,
86-
AbstractMethod::CHECK_USE_FOR_CURRENCY,
87-
AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX,
88-
]
93+
array_merge(
94+
[
95+
AbstractMethod::CHECK_USE_CHECKOUT,
96+
AbstractMethod::CHECK_USE_FOR_COUNTRY,
97+
AbstractMethod::CHECK_USE_FOR_CURRENCY,
98+
AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX,
99+
],
100+
$this->additionalChecks
101+
)
89102
)->isApplicable(
90103
$method,
91104
$quote

app/code/Magento/Payment/Test/Unit/Model/MethodListTest.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
namespace Magento\Payment\Test\Unit\Model;
88

9-
use Magento\Payment\Model\MethodList;
109
use Magento\Payment\Model\Method\AbstractMethod;
10+
use Magento\Payment\Model\MethodList;
1111

1212
class MethodListTest extends \PHPUnit\Framework\TestCase
1313
{
@@ -36,6 +36,11 @@ class MethodListTest extends \PHPUnit\Framework\TestCase
3636
*/
3737
protected $specificationFactoryMock;
3838

39+
/**
40+
* @var array $additionalChecks
41+
*/
42+
private $additionalChecks;
43+
3944
protected function setUp()
4045
{
4146
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
@@ -49,10 +54,14 @@ protected function setUp()
4954
)->disableOriginalConstructor()->getMock();
5055

5156
$this->specificationFactoryMock = $this->createMock(\Magento\Payment\Model\Checks\SpecificationFactory::class);
57+
58+
$this->additionalChecks = ['acme_custom_payment_method_check' => 'acme_custom_payment_method_check'];
59+
5260
$this->methodList = $this->objectManager->getObject(
5361
\Magento\Payment\Model\MethodList::class,
5462
[
55-
'specificationFactory' => $this->specificationFactoryMock
63+
'specificationFactory' => $this->specificationFactoryMock,
64+
'additionalChecks' => $this->additionalChecks
5665
]
5766
);
5867

@@ -68,6 +77,9 @@ protected function setUp()
6877
);
6978
}
7079

80+
/**
81+
* Verify available payment methods
82+
*/
7183
public function testGetAvailableMethods()
7284
{
7385
$storeId = 1;
@@ -90,13 +102,17 @@ public function testGetAvailableMethods()
90102

91103
$this->specificationFactoryMock->expects($this->atLeastOnce())
92104
->method('create')
93-
->with([
94-
AbstractMethod::CHECK_USE_CHECKOUT,
95-
AbstractMethod::CHECK_USE_FOR_COUNTRY,
96-
AbstractMethod::CHECK_USE_FOR_CURRENCY,
97-
AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX
98-
])
99-
->will($this->returnValue($compositeMock));
105+
->with(
106+
array_merge(
107+
[
108+
AbstractMethod::CHECK_USE_CHECKOUT,
109+
AbstractMethod::CHECK_USE_FOR_COUNTRY,
110+
AbstractMethod::CHECK_USE_FOR_CURRENCY,
111+
AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX
112+
],
113+
$this->additionalChecks
114+
)
115+
)->will($this->returnValue($compositeMock));
100116

101117
$methodMock = $this->getMockForAbstractClass(\Magento\Payment\Api\Data\PaymentMethodInterface::class);
102118
$this->paymentMethodList->expects($this->once())

0 commit comments

Comments
 (0)