Skip to content

Commit e5f266d

Browse files
committed
MAGETWO-59197: Create UI component and server structure for Vault
- Added more flexible configuration for Vault internal usage
1 parent b6cc007 commit e5f266d

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

app/code/Magento/Vault/Model/Method/Vault.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@
55
*/
66
namespace Magento\Vault\Model\Method;
77

8-
use Magento\Framework\DataObject;
98
use Magento\Framework\Event\ManagerInterface;
109
use Magento\Framework\ObjectManagerInterface;
1110
use Magento\Payment\Gateway\Command;
12-
use Magento\Sales\Api\Data\OrderPaymentExtensionInterfaceFactory;
1311
use Magento\Payment\Gateway\Config\ValueHandlerPoolInterface;
1412
use Magento\Payment\Gateway\ConfigFactoryInterface;
1513
use Magento\Payment\Gateway\ConfigInterface;
1614
use Magento\Payment\Model\InfoInterface;
1715
use Magento\Payment\Model\MethodInterface;
1816
use Magento\Payment\Observer\AbstractDataAssignObserver;
17+
use Magento\Sales\Api\Data\OrderPaymentExtensionInterfaceFactory;
1918
use Magento\Sales\Api\Data\OrderPaymentInterface;
2019
use Magento\Sales\Model\Order\Payment;
2120
use Magento\Vault\Api\Data\PaymentTokenInterface;
@@ -275,8 +274,12 @@ public function canVoid()
275274
*/
276275
public function canUseInternal()
277276
{
278-
return $this->config->getValue('can_use_internal', $this->getStore())
279-
|| $this->getVaultProvider()->canUseInternal();
277+
$isInternalAllowed = $this->getConfiguredValue('can_use_internal');
278+
// if config has't been specified for Vault, need to check payment provider option
279+
if ($isInternalAllowed === null) {
280+
return $this->getVaultProvider()->canUseInternal();
281+
}
282+
return (bool) $isInternalAllowed;
280283
}
281284

282285
/**

app/code/Magento/Vault/Test/Unit/Model/Method/VaultTest.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
99
use Magento\Payment\Gateway\Command\CommandManagerInterface;
1010
use Magento\Payment\Gateway\Command\CommandManagerPoolInterface;
11+
use Magento\Payment\Gateway\Config\ValueHandlerInterface;
12+
use Magento\Payment\Gateway\Config\ValueHandlerPoolInterface;
1113
use Magento\Payment\Gateway\ConfigInterface;
1214
use Magento\Payment\Model\InfoInterface;
1315
use Magento\Payment\Model\MethodInterface;
@@ -314,11 +316,17 @@ public function testIsAvailableWithoutQuote()
314316
*/
315317
public function testCanUseInternal($configValue, $paymentValue, $expected)
316318
{
317-
$config = $this->getMock(ConfigInterface::class);
319+
$handlerPool = $this->getMock(ValueHandlerPoolInterface::class);
320+
$handler = $this->getMock(ValueHandlerInterface::class);
318321

319-
$config->expects(static::once())
320-
->method('getValue')
321-
->with('can_use_internal', null)
322+
$handlerPool->expects(static::once())
323+
->method('get')
324+
->with('can_use_internal')
325+
->willReturn($handler);
326+
327+
$handler->expects(static::once())
328+
->method('handle')
329+
->with(['field' => 'can_use_internal'], null)
322330
->willReturn($configValue);
323331

324332
$this->vaultProvider->expects(static::any())
@@ -327,8 +335,8 @@ public function testCanUseInternal($configValue, $paymentValue, $expected)
327335

328336
/** @var Vault $model */
329337
$model = $this->objectManager->getObject(Vault::class, [
330-
'config' => $config,
331-
'vaultProvider' => $this->vaultProvider
338+
'vaultProvider' => $this->vaultProvider,
339+
'valueHandlerPool' => $handlerPool,
332340
]);
333341
static::assertEquals($expected, $model->canUseInternal());
334342
}
@@ -343,7 +351,7 @@ public function internalUsageDataProvider()
343351
['configValue' => true, 'paymentValue' => true, 'expected' => true],
344352
['configValue' => true, 'paymentValue' => null, 'expected' => true],
345353
['configValue' => true, 'paymentValue' => false, 'expected' => true],
346-
['configValue' => false, 'paymentValue' => true, 'expected' => true],
354+
['configValue' => false, 'paymentValue' => true, 'expected' => false],
347355
['configValue' => false, 'paymentValue' => false, 'expected' => false],
348356
['configValue' => null, 'paymentValue' => true, 'expected' => true],
349357
['configValue' => null, 'paymentValue' => false, 'expected' => false],

0 commit comments

Comments
 (0)