Skip to content

Commit a940fe6

Browse files
committed
Merge remote-tracking branch 'remotes/origin/MAGETWO-68936' into MPI-PR-Bugfixes
2 parents 9d52917 + b8c9433 commit a940fe6

File tree

3 files changed

+54
-14
lines changed

3 files changed

+54
-14
lines changed

app/code/Magento/Paypal/Helper/Data.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
namespace Magento\Paypal\Helper;
77

88
use Magento\Framework\App\ObjectManager;
9-
use Magento\Payment\Model\Method\AbstractMethod;
10-
use Magento\Paypal\Model\Billing\Agreement\MethodInterface;
9+
use Magento\Payment\Api\Data\PaymentMethodInterface;
10+
use Magento\Payment\Api\PaymentMethodListInterface;
11+
use Magento\Payment\Model\Method\InstanceFactory;
12+
use Magento\Payment\Model\MethodInterface;
13+
use Magento\Paypal\Model\Billing\Agreement\MethodInterface as BillingAgreementMethodInterface;
1114

1215
/**
1316
* Paypal Data helper
@@ -45,12 +48,12 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
4548
private $configFactory;
4649

4750
/**
48-
* @var \Magento\Payment\Api\PaymentMethodListInterface
51+
* @var PaymentMethodListInterface
4952
*/
5053
private $paymentMethodList;
5154

5255
/**
53-
* @var \Magento\Payment\Model\Method\InstanceFactory
56+
* @var InstanceFactory
5457
*/
5558
private $paymentMethodInstanceFactory;
5659

@@ -100,21 +103,21 @@ public function shouldAskToCreateBillingAgreement(\Magento\Paypal\Model\Config $
100103
*
101104
* @param null|string|bool|int|\Magento\Store\Model\Store $store
102105
* @param \Magento\Quote\Model\Quote|null $quote
103-
* @return MethodInterface[]
106+
* @return BillingAgreementMethodInterface[]
104107
*/
105108
public function getBillingAgreementMethods($store = null, $quote = null)
106109
{
107110
$activeMethods = array_map(
108-
function (\Magento\Payment\Api\Data\PaymentMethodInterface $method) {
111+
function (PaymentMethodInterface $method) {
109112
return $this->getPaymentMethodInstanceFactory()->create($method);
110113
},
111114
$this->getPaymentMethodList()->getActiveList($store)
112115
);
113116

114117
$result = array_filter(
115118
$activeMethods,
116-
function (AbstractMethod $method) use ($quote) {
117-
return $method->isAvailable($quote) && $method instanceof MethodInterface;
119+
function (MethodInterface $method) use ($quote) {
120+
return $method instanceof BillingAgreementMethodInterface && $method->isAvailable($quote);
118121
}
119122
);
120123

@@ -142,14 +145,14 @@ public function getHtmlTransactionId($methodCode, $txnId)
142145
/**
143146
* Get payment method list.
144147
*
145-
* @return \Magento\Payment\Api\PaymentMethodListInterface
148+
* @return PaymentMethodListInterface
146149
* @deprecated
147150
*/
148151
private function getPaymentMethodList()
149152
{
150153
if ($this->paymentMethodList === null) {
151154
$this->paymentMethodList = ObjectManager::getInstance()->get(
152-
\Magento\Payment\Api\PaymentMethodListInterface::class
155+
PaymentMethodListInterface::class
153156
);
154157
}
155158
return $this->paymentMethodList;
@@ -158,14 +161,14 @@ private function getPaymentMethodList()
158161
/**
159162
* Get payment method instance factory.
160163
*
161-
* @return \Magento\Payment\Model\Method\InstanceFactory
164+
* @return InstanceFactory
162165
* @deprecated
163166
*/
164167
private function getPaymentMethodInstanceFactory()
165168
{
166169
if ($this->paymentMethodInstanceFactory === null) {
167170
$this->paymentMethodInstanceFactory = ObjectManager::getInstance()->get(
168-
\Magento\Payment\Model\Method\InstanceFactory::class
171+
InstanceFactory::class
169172
);
170173
}
171174
return $this->paymentMethodInstanceFactory;

app/code/Magento/Paypal/Test/Unit/Helper/DataTest.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,14 @@ public function getBillingAgreementMethodsDataProvider()
121121
->method('isAvailable')
122122
->willReturn(true);
123123

124-
$methodInstanceMock = $this->getMockBuilder(
124+
$abstractMethodInstanceMock = $this->getMockBuilder(
125125
\Magento\Payment\Model\Method\Cc::class
126126
)->disableOriginalConstructor()->getMock();
127127

128+
$adapterMethodInstanceMock = $this->getMockBuilder(
129+
\Magento\Payment\Model\Method\Adapter::class
130+
)->disableOriginalConstructor()->getMock();
131+
128132
return [
129133
[
130134
'1',
@@ -138,7 +142,15 @@ public function getBillingAgreementMethodsDataProvider()
138142
'1',
139143
$quoteMock,
140144
[
141-
[$methodMock, $methodInstanceMock]
145+
[$methodMock, $abstractMethodInstanceMock]
146+
],
147+
[]
148+
],
149+
[
150+
'1',
151+
$quoteMock,
152+
[
153+
[$methodMock, $adapterMethodInstanceMock]
142154
],
143155
[]
144156
]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Paypal\Helper;
7+
8+
use Magento\TestFramework\Helper\Bootstrap;
9+
10+
class DataTest extends \PHPUnit_Framework_TestCase
11+
{
12+
/**
13+
* Tests if method executes without fatal error when some vault payment method is enabled.
14+
*
15+
* @magentoConfigFixture current_store payment/payflowpro/active 1
16+
* @magentoConfigFixture current_store payment/payflowpro_cc_vault/active 1
17+
*/
18+
public function testGetBillingAgreementMethodsWithVaultEnabled()
19+
{
20+
/** @var Data $model */
21+
$model = Bootstrap::getObjectManager()->create(Data::class);
22+
23+
$this->assertEmpty($model->getBillingAgreementMethods());
24+
}
25+
}

0 commit comments

Comments
 (0)