diff --git a/app/code/Magento/Authorizenet/Model/Source/Cctype.php b/app/code/Magento/Authorizenet/Model/Source/Cctype.php index c6a83e19bd32733781228f873bd964558bd894be..a6e173474ae869f2ed40520ed2ccf8197f752e4d 100644 --- a/app/code/Magento/Authorizenet/Model/Source/Cctype.php +++ b/app/code/Magento/Authorizenet/Model/Source/Cctype.php @@ -17,6 +17,6 @@ class Cctype extends PaymentCctype */ public function getAllowedTypes() { - return ['VI', 'MC', 'AE', 'DI']; + return ['VI', 'MC', 'AE', 'DI', 'JCB', 'DN']; } } diff --git a/app/code/Magento/Authorizenet/etc/config.xml b/app/code/Magento/Authorizenet/etc/config.xml index 70b413b5c1a3936c4efe3542f992b1dfead63999..5c48b88e0829965dd6f9a7d2d66f7373a7bb6990 100644 --- a/app/code/Magento/Authorizenet/etc/config.xml +++ b/app/code/Magento/Authorizenet/etc/config.xml @@ -10,7 +10,7 @@ <payment> <authorizenet_directpost> <active>0</active> - <cctypes>AE,VI,MC,DI</cctypes> + <cctypes>AE,VI,MC,DI,JCB,DN</cctypes> <debug>0</debug> <email_customer>0</email_customer> <login backend_model="Magento\Config\Model\Config\Backend\Encrypted" /> diff --git a/app/code/Magento/Paypal/view/frontend/web/js/view/payment/method-renderer/in-context/checkout-express.js b/app/code/Magento/Paypal/view/frontend/web/js/view/payment/method-renderer/in-context/checkout-express.js index 97dbf0e81b9da0003018ab6c6975aea3216501b4..8a29f0c3a6ea4f774ffc38c9eeb5e65dd34b9657 100644 --- a/app/code/Magento/Paypal/view/frontend/web/js/view/payment/method-renderer/in-context/checkout-express.js +++ b/app/code/Magento/Paypal/view/frontend/web/js/view/payment/method-renderer/in-context/checkout-express.js @@ -25,6 +25,9 @@ define( ) { 'use strict'; + // State of PayPal module initialization + var clientInit = false; + return Component.extend({ defaults: { @@ -93,15 +96,26 @@ define( * @returns {Object} */ initClient: function () { + var selector = '#' + this.getButtonId(); + _.each(this.clientConfig, function (fn, name) { if (typeof fn === 'function') { this.clientConfig[name] = fn.bind(this); } }, this); - domObserver.get('#' + this.getButtonId(), function () { - paypalExpressCheckout.checkout.setup(this.merchantId, this.clientConfig); - }.bind(this)); + if (!clientInit) { + domObserver.get(selector, function () { + paypalExpressCheckout.checkout.setup(this.merchantId, this.clientConfig); + clientInit = true; + domObserver.off(selector); + }.bind(this)); + } else { + domObserver.get(selector, function () { + $(selector).on('click', this.clientConfig.click); + domObserver.off(selector); + }.bind(this)); + } return this; }, diff --git a/app/code/Magento/Vault/Api/PaymentMethodListInterface.php b/app/code/Magento/Vault/Api/PaymentMethodListInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..f9d3e628594ef0f809429f39564271e6f52e7b23 --- /dev/null +++ b/app/code/Magento/Vault/Api/PaymentMethodListInterface.php @@ -0,0 +1,30 @@ +<?php +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Vault\Api; + +use Magento\Vault\Model\VaultPaymentInterface; + +/** + * Contains methods to retrieve vault payment methods + * This interface is consistent with \Magento\Payment\Api\PaymentMethodListInterface + * @api + */ +interface PaymentMethodListInterface +{ + /** + * Get list of available vault payments + * @param int $storeId + * @return VaultPaymentInterface[] + */ + public function getList($storeId); + + /** + * Get list of enabled in the configuration vault payments + * @param int $storeId + * @return VaultPaymentInterface[] + */ + public function getActiveList($storeId); +} diff --git a/app/code/Magento/Vault/Model/PaymentMethodList.php b/app/code/Magento/Vault/Model/PaymentMethodList.php new file mode 100644 index 0000000000000000000000000000000000000000..bec073df7971154ee74cd0b794d4cd11d347c832 --- /dev/null +++ b/app/code/Magento/Vault/Model/PaymentMethodList.php @@ -0,0 +1,78 @@ +<?php +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Vault\Model; + +use Magento\Payment\Api\Data\PaymentMethodInterface; +use Magento\Payment\Api\PaymentMethodListInterface; +use Magento\Payment\Model\Method\InstanceFactory; +use Magento\Payment\Model\MethodInterface; +use Magento\Vault\Api\PaymentMethodListInterface as VaultPaymentMethodListInterface; + +/** + * Contains methods to retrieve configured vault payments + */ +class PaymentMethodList implements VaultPaymentMethodListInterface +{ + /** + * @var InstanceFactory + */ + private $instanceFactory; + + /** + * @var PaymentMethodListInterface + */ + private $paymentMethodList; + + /** + * PaymentMethodList constructor. + * @param PaymentMethodListInterface $paymentMethodList + * @param InstanceFactory $instanceFactory + */ + public function __construct(PaymentMethodListInterface $paymentMethodList, InstanceFactory $instanceFactory) + { + $this->instanceFactory = $instanceFactory; + $this->paymentMethodList = $paymentMethodList; + } + + /** + * @inheritdoc + */ + public function getList($storeId) + { + return $this->filterList($this->paymentMethodList->getList($storeId)); + } + + /** + * @inheritdoc + */ + public function getActiveList($storeId) + { + return $this->filterList($this->paymentMethodList->getActiveList($storeId)); + } + + /** + * Filter vault methods from payments + * @param PaymentMethodInterface[] $list + * @return VaultPaymentInterface[] + */ + private function filterList(array $list) + { + $paymentMethods = array_map( + function (PaymentMethodInterface $paymentMethod) { + return $this->instanceFactory->create($paymentMethod); + }, + $list + ); + + $availableMethods = array_filter( + $paymentMethods, + function (MethodInterface $methodInstance) { + return $methodInstance instanceof VaultPaymentInterface; + } + ); + return array_values($availableMethods); + } +} diff --git a/app/code/Magento/Vault/Model/Ui/TokensConfigProvider.php b/app/code/Magento/Vault/Model/Ui/TokensConfigProvider.php index 060e16d1c3f1aa14e909dc3662315a35f4da680d..40343c29620e1a5c9ecc6e9779baf77336a09481 100644 --- a/app/code/Magento/Vault/Model/Ui/TokensConfigProvider.php +++ b/app/code/Magento/Vault/Model/Ui/TokensConfigProvider.php @@ -7,10 +7,9 @@ namespace Magento\Vault\Model\Ui; use Magento\Checkout\Model\ConfigProviderInterface; use Magento\Framework\App\ObjectManager; -use Magento\Payment\Api\Data\PaymentMethodInterface; use Magento\Store\Model\StoreManagerInterface; +use Magento\Vault\Api\PaymentMethodListInterface; use Magento\Vault\Model\CustomerTokenManagement; -use Magento\Vault\Model\VaultPaymentInterface; /** * Class ConfigProvider @@ -39,14 +38,9 @@ final class TokensConfigProvider implements ConfigProviderInterface private $customerTokenManagement; /** - * @var \Magento\Payment\Api\PaymentMethodListInterface + * @var PaymentMethodListInterface */ - private $paymentMethodList; - - /** - * @var \Magento\Payment\Model\Method\InstanceFactory - */ - private $paymentMethodInstanceFactory; + private $vaultPaymentList; /** * Constructor @@ -112,7 +106,8 @@ final class TokensConfigProvider implements ConfigProviderInterface private function getComponentProviders() { $providers = []; - $vaultPaymentMethods = $this->getVaultPaymentMethodList(); + $storeId = $this->storeManager->getStore()->getId(); + $vaultPaymentMethods = $this->getVaultPaymentList()->getActiveList($storeId); foreach ($vaultPaymentMethods as $method) { $providerCode = $method->getProviderCode(); @@ -141,60 +136,15 @@ final class TokensConfigProvider implements ConfigProviderInterface } /** - * Get list of active Vault payment methods. - * - * @return VaultPaymentInterface[] - */ - private function getVaultPaymentMethodList() - { - $storeId = $this->storeManager->getStore()->getId(); - - $paymentMethods = array_map( - function (PaymentMethodInterface $paymentMethod) { - return $this->getPaymentMethodInstanceFactory()->create($paymentMethod); - }, - $this->getPaymentMethodList()->getActiveList($storeId) - ); - - $availableMethods = array_filter( - $paymentMethods, - function (\Magento\Payment\Model\MethodInterface $methodInstance) { - return $methodInstance instanceof VaultPaymentInterface; - } - ); - - return $availableMethods; - } - - /** - * Get payment method list. - * - * @return \Magento\Payment\Api\PaymentMethodListInterface - * @deprecated - */ - private function getPaymentMethodList() - { - if ($this->paymentMethodList === null) { - $this->paymentMethodList = ObjectManager::getInstance()->get( - \Magento\Payment\Api\PaymentMethodListInterface::class - ); - } - return $this->paymentMethodList; - } - - /** - * Get payment method instance factory. - * - * @return \Magento\Payment\Model\Method\InstanceFactory + * Get instance of vault payment list instance + * @return PaymentMethodListInterface * @deprecated */ - private function getPaymentMethodInstanceFactory() + private function getVaultPaymentList() { - if ($this->paymentMethodInstanceFactory === null) { - $this->paymentMethodInstanceFactory = ObjectManager::getInstance()->get( - \Magento\Payment\Model\Method\InstanceFactory::class - ); + if ($this->vaultPaymentList === null) { + $this->vaultPaymentList = ObjectManager::getInstance()->get(PaymentMethodListInterface::class); } - return $this->paymentMethodInstanceFactory; + return $this->vaultPaymentList; } } diff --git a/app/code/Magento/Vault/Model/Ui/VaultConfigProvider.php b/app/code/Magento/Vault/Model/Ui/VaultConfigProvider.php index 9cd7b97562df98e309b9ddd182a5ced144b2e555..bc3110a101452b40deb5506bc659d88a5f4e34a1 100644 --- a/app/code/Magento/Vault/Model/Ui/VaultConfigProvider.php +++ b/app/code/Magento/Vault/Model/Ui/VaultConfigProvider.php @@ -8,9 +8,8 @@ namespace Magento\Vault\Model\Ui; use Magento\Checkout\Model\ConfigProviderInterface; use Magento\Framework\App\ObjectManager; use Magento\Framework\Session\SessionManagerInterface; -use Magento\Payment\Api\Data\PaymentMethodInterface; use Magento\Store\Model\StoreManagerInterface; -use Magento\Vault\Model\VaultPaymentInterface; +use Magento\Vault\Api\PaymentMethodListInterface; class VaultConfigProvider implements ConfigProviderInterface { @@ -32,14 +31,9 @@ class VaultConfigProvider implements ConfigProviderInterface private $session; /** - * @var \Magento\Payment\Api\PaymentMethodListInterface + * @var PaymentMethodListInterface */ - private $paymentMethodList; - - /** - * @var \Magento\Payment\Model\Method\InstanceFactory - */ - private $paymentMethodInstanceFactory; + private $vaultPaymentList; /** * VaultConfigProvider constructor. @@ -62,9 +56,9 @@ class VaultConfigProvider implements ConfigProviderInterface public function getConfig() { $availableMethods = []; - $vaultPayments = $this->getVaultPaymentMethodList(); - $customerId = $this->session->getCustomerId(); $storeId = $this->storeManager->getStore()->getId(); + $vaultPayments = $this->getVaultPaymentList()->getActiveList($storeId); + $customerId = $this->session->getCustomerId(); foreach ($vaultPayments as $method) { $availableMethods[$method->getCode()] = [ @@ -78,60 +72,15 @@ class VaultConfigProvider implements ConfigProviderInterface } /** - * Get list of active Vault payment methods. - * - * @return VaultPaymentInterface[] - */ - private function getVaultPaymentMethodList() - { - $storeId = $this->storeManager->getStore()->getId(); - - $paymentMethods = array_map( - function (PaymentMethodInterface $paymentMethod) { - return $this->getPaymentMethodInstanceFactory()->create($paymentMethod); - }, - $this->getPaymentMethodList()->getActiveList($storeId) - ); - - $availableMethods = array_filter( - $paymentMethods, - function (\Magento\Payment\Model\MethodInterface $methodInstance) { - return $methodInstance instanceof VaultPaymentInterface; - } - ); - - return $availableMethods; - } - - /** - * Get payment method list. - * - * @return \Magento\Payment\Api\PaymentMethodListInterface - * @deprecated - */ - private function getPaymentMethodList() - { - if ($this->paymentMethodList === null) { - $this->paymentMethodList = ObjectManager::getInstance()->get( - \Magento\Payment\Api\PaymentMethodListInterface::class - ); - } - return $this->paymentMethodList; - } - - /** - * Get payment method instance factory. - * - * @return \Magento\Payment\Model\Method\InstanceFactory + * Get vault payment list instance + * @return PaymentMethodListInterface * @deprecated */ - private function getPaymentMethodInstanceFactory() + private function getVaultPaymentList() { - if ($this->paymentMethodInstanceFactory === null) { - $this->paymentMethodInstanceFactory = ObjectManager::getInstance()->get( - \Magento\Payment\Model\Method\InstanceFactory::class - ); + if ($this->vaultPaymentList === null) { + $this->vaultPaymentList = ObjectManager::getInstance()->get(PaymentMethodListInterface::class); } - return $this->paymentMethodInstanceFactory; + return $this->vaultPaymentList; } } diff --git a/app/code/Magento/Vault/Test/Unit/Model/PaymentMethodListTest.php b/app/code/Magento/Vault/Test/Unit/Model/PaymentMethodListTest.php new file mode 100644 index 0000000000000000000000000000000000000000..9e9d426fa8f3a487335f1f3fd0242833fbcc6e9d --- /dev/null +++ b/app/code/Magento/Vault/Test/Unit/Model/PaymentMethodListTest.php @@ -0,0 +1,74 @@ +<?php +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Vault\Test\Unit\Model; + +use Magento\Payment\Api\Data\PaymentMethodInterface; +use Magento\Payment\Api\PaymentMethodListInterface; +use Magento\Payment\Model\Method\InstanceFactory; +use Magento\Payment\Model\MethodInterface; +use Magento\Vault\Model\VaultPaymentInterface; +use Magento\Vault\Model\PaymentMethodList; +use PHPUnit_Framework_MockObject_MockObject as MockObject; + +class PaymentMethodListTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var PaymentMethodListInterface|MockObject + */ + private $paymentMethodList; + + /** + * @var InstanceFactory|MockObject + */ + private $instanceFactory; + + /** + * @var PaymentMethodList + */ + private $vaultPaymentList; + + protected function setUp() + { + $this->paymentMethodList = $this->getMock(PaymentMethodListInterface::class); + $this->instanceFactory = $this->getMockBuilder(InstanceFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + + $this->vaultPaymentList = new PaymentMethodList($this->paymentMethodList, $this->instanceFactory); + } + + /** + * @covers \Magento\Vault\Model\PaymentMethodList::getActiveList + */ + public function testGetActivePaymentList() + { + $storeId = 1; + $vaultPayment = $this->getMock(VaultPaymentInterface::class); + $paymentMethodInterface1 = $this->getMock(PaymentMethodInterface::class); + $paymentMethodInterface2 = $this->getMock(PaymentMethodInterface::class); + $activePayments = [ + $paymentMethodInterface1, + $paymentMethodInterface2 + ]; + + $this->paymentMethodList->expects(static::once()) + ->method('getActiveList') + ->with($storeId) + ->willReturn($activePayments); + + $this->instanceFactory->expects(static::exactly(2)) + ->method('create') + ->willReturnMap([ + [$paymentMethodInterface1, $this->getMock(MethodInterface::class)], + [$paymentMethodInterface2, $vaultPayment] + ]); + + $vaultPayments = $this->vaultPaymentList->getActiveList($storeId); + static::assertCount(1, $vaultPayments); + static::assertInstanceOf(VaultPaymentInterface::class, $vaultPayment); + } +} diff --git a/app/code/Magento/Vault/Test/Unit/Model/Ui/TokensConfigProviderTest.php b/app/code/Magento/Vault/Test/Unit/Model/Ui/TokensConfigProviderTest.php index d5ac3cac9563d4a8d8d4f294eca2dfaab8f44374..34b7c5240497164327cadac60fc00a33eb390c58 100644 --- a/app/code/Magento/Vault/Test/Unit/Model/Ui/TokensConfigProviderTest.php +++ b/app/code/Magento/Vault/Test/Unit/Model/Ui/TokensConfigProviderTest.php @@ -5,11 +5,11 @@ */ namespace Magento\Vault\Test\Unit\Model\Ui; -use Magento\Customer\Model\Session; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Store\Api\Data\StoreInterface; use Magento\Store\Model\StoreManagerInterface; use Magento\Vault\Api\Data\PaymentTokenInterface; +use Magento\Vault\Api\PaymentMethodListInterface; use Magento\Vault\Model\CustomerTokenManagement; use Magento\Vault\Model\Ui\TokensConfigProvider; use Magento\Vault\Model\Ui\TokenUiComponentInterface; @@ -31,25 +31,10 @@ class TokensConfigProviderTest extends \PHPUnit_Framework_TestCase */ private $storeManager; - /** - * @var \Magento\Payment\Api\PaymentMethodListInterface|MockObject - */ - private $paymentMethodList; - - /** - * @var \Magento\Payment\Model\Method\InstanceFactory|MockObject - */ - private $paymentMethodInstanceFactory; - - /** - * @var \Magento\Payment\Api\Data\PaymentMethodInterface|MockObject - */ - private $vaultPayment; - /** * @var VaultPaymentInterface|MockObject */ - private $vaultPaymentInstance; + private $vaultPayment; /** * @var StoreInterface|MockObject @@ -61,6 +46,11 @@ class TokensConfigProviderTest extends \PHPUnit_Framework_TestCase */ private $customerTokenManagement; + /** + * @var PaymentMethodListInterface|MockObject + */ + private $vaultPaymentList; + /** * @var ObjectManager */ @@ -68,20 +58,12 @@ class TokensConfigProviderTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $this->paymentMethodList = $this->getMockBuilder(\Magento\Payment\Api\PaymentMethodListInterface::class) - ->disableOriginalConstructor() - ->getMockForAbstractClass(); - - $this->paymentMethodInstanceFactory = $this->getMockBuilder( - \Magento\Payment\Model\Method\InstanceFactory::class - )->disableOriginalConstructor()->getMock(); - - $this->vaultPayment = $this->getMockForAbstractClass(\Magento\Payment\Api\Data\PaymentMethodInterface::class); - $this->vaultPaymentInstance = $this->getMockForAbstractClass(VaultPaymentInterface::class); + $this->objectManager = new ObjectManager($this); + $this->vaultPaymentList = $this->getMock(PaymentMethodListInterface::class); + $this->vaultPayment = $this->getMockForAbstractClass(VaultPaymentInterface::class); $this->storeManager = $this->getMock(StoreManagerInterface::class); $this->store = $this->getMock(StoreInterface::class); - $this->objectManager = new ObjectManager($this); $this->customerTokenManagement = $this->getMockBuilder(CustomerTokenManagement::class) ->disableOriginalConstructor() ->getMock(); @@ -114,16 +96,12 @@ class TokensConfigProviderTest extends \PHPUnit_Framework_TestCase ->method('getId') ->willReturn($storeId); - $this->paymentMethodList->expects(static::once()) + $this->vaultPaymentList->expects(static::once()) ->method('getActiveList') ->with($storeId) ->willReturn([$this->vaultPayment]); - - $this->paymentMethodInstanceFactory->expects($this->once()) - ->method('create') - ->willReturn($this->vaultPaymentInstance); - $this->vaultPaymentInstance->expects(static::once()) + $this->vaultPayment->expects(static::once()) ->method('getProviderCode') ->willReturn($vaultProviderCode); @@ -153,16 +131,10 @@ class TokensConfigProviderTest extends \PHPUnit_Framework_TestCase $vaultProviderCode => $tokenUiComponentProvider ] ); - - $this->objectManager->setBackwardCompatibleProperty( - $configProvider, - 'paymentMethodList', - $this->paymentMethodList - ); $this->objectManager->setBackwardCompatibleProperty( $configProvider, - 'paymentMethodInstanceFactory', - $this->paymentMethodInstanceFactory + 'vaultPaymentList', + $this->vaultPaymentList ); static::assertEquals($expectedConfig, $configProvider->getConfig()); diff --git a/app/code/Magento/Vault/Test/Unit/Model/Ui/VaultConfigProviderTest.php b/app/code/Magento/Vault/Test/Unit/Model/Ui/VaultConfigProviderTest.php index d00531637b86d4e509662a31ce2da32752ba4a8b..e9d6af3bec356f518fbea6b1ce8be5ab841f78d4 100644 --- a/app/code/Magento/Vault/Test/Unit/Model/Ui/VaultConfigProviderTest.php +++ b/app/code/Magento/Vault/Test/Unit/Model/Ui/VaultConfigProviderTest.php @@ -9,35 +9,20 @@ use Magento\Customer\Model\Session; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Store\Api\Data\StoreInterface; use Magento\Store\Model\StoreManagerInterface; +use Magento\Vault\Api\PaymentMethodListInterface; use Magento\Vault\Model\Ui\VaultConfigProvider; use Magento\Vault\Model\VaultPaymentInterface; use PHPUnit_Framework_MockObject_MockObject as MockObject; /** * Class VaultConfigProviderTest - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class VaultConfigProviderTest extends \PHPUnit_Framework_TestCase { - /** - * @var \Magento\Payment\Api\PaymentMethodListInterface|MockObject - */ - private $paymentMethodList; - - /** - * @var \Magento\Payment\Model\Method\InstanceFactory|MockObject - */ - private $paymentMethodInstanceFactory; - - /** - * @var \Magento\Payment\Api\Data\PaymentMethodInterface|MockObject - */ - private $vaultPayment; - /** * @var VaultPaymentInterface|MockObject */ - private $vaultPaymentInstance; + private $vaultPayment; /** * @var Session|MockObject @@ -54,6 +39,11 @@ class VaultConfigProviderTest extends \PHPUnit_Framework_TestCase */ private $storeManager; + /** + * @var PaymentMethodListInterface|MockObject + */ + private $vaultPaymentList; + /** * @var VaultConfigProvider */ @@ -61,33 +51,20 @@ class VaultConfigProviderTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $this->paymentMethodList = $this->getMockBuilder(\Magento\Payment\Api\PaymentMethodListInterface::class) - ->disableOriginalConstructor() - ->getMockForAbstractClass(); - - $this->paymentMethodInstanceFactory = $this->getMockBuilder( - \Magento\Payment\Model\Method\InstanceFactory::class - )->disableOriginalConstructor()->getMock(); - - $this->vaultPayment = $this->getMockForAbstractClass(\Magento\Payment\Api\Data\PaymentMethodInterface::class); - $this->vaultPaymentInstance = $this->getMockForAbstractClass(VaultPaymentInterface::class); + $this->vaultPayment = $this->getMockForAbstractClass(VaultPaymentInterface::class); $this->storeManager = $this->getMockForAbstractClass(StoreManagerInterface::class); $this->store = $this->getMockForAbstractClass(StoreInterface::class); $this->session = $this->getMockBuilder(Session::class) ->disableOriginalConstructor() ->getMock(); + $this->vaultPaymentList = $this->getMock(PaymentMethodListInterface::class); $objectManager = new ObjectManager($this); $this->vaultConfigProvider = new VaultConfigProvider($this->storeManager, $this->session); $objectManager->setBackwardCompatibleProperty( $this->vaultConfigProvider, - 'paymentMethodList', - $this->paymentMethodList - ); - $objectManager->setBackwardCompatibleProperty( - $this->vaultConfigProvider, - 'paymentMethodInstanceFactory', - $this->paymentMethodInstanceFactory + 'vaultPaymentList', + $this->vaultPaymentList ); } @@ -112,26 +89,21 @@ class VaultConfigProviderTest extends \PHPUnit_Framework_TestCase $this->session->expects(static::once()) ->method('getCustomerId') ->willReturn($customerId); - $this->storeManager->expects(static::exactly(2)) + $this->storeManager->expects(static::once()) ->method('getStore') ->willReturn($this->store); - $this->store->expects(static::exactly(2)) + $this->store->expects(static::once()) ->method('getId') ->willReturn($storeId); - $this->paymentMethodList->expects(static::once()) + $this->vaultPaymentList->expects(static::once()) ->method('getActiveList') - ->with($storeId) ->willReturn([$this->vaultPayment]); - $this->paymentMethodInstanceFactory->expects($this->once()) - ->method('create') - ->willReturn($this->vaultPaymentInstance); - - $this->vaultPaymentInstance->expects(static::once()) + $this->vaultPayment->expects(static::once()) ->method('getCode') ->willReturn($vaultPaymentCode); - $this->vaultPaymentInstance->expects($customerId !== null ? static::once() : static::never()) + $this->vaultPayment->expects($customerId !== null ? static::once() : static::never()) ->method('isActive') ->with($storeId) ->willReturn($vaultEnabled); diff --git a/app/code/Magento/Vault/etc/di.xml b/app/code/Magento/Vault/etc/di.xml index e44e1da3e3d61f3c5d230c978b798fa05e84db7e..14354da7e2c528e910a0af6bd15706f25dbeadb4 100644 --- a/app/code/Magento/Vault/etc/di.xml +++ b/app/code/Magento/Vault/etc/di.xml @@ -11,6 +11,7 @@ <preference for="Magento\Vault\Api\Data\PaymentTokenInterface" type="Magento\Vault\Model\PaymentToken"/> <preference for="Magento\Vault\Api\PaymentTokenRepositoryInterface" type="Magento\Vault\Model\PaymentTokenRepository" /> <preference for="Magento\Vault\Api\PaymentTokenManagementInterface" type="Magento\Vault\Model\PaymentTokenManagement" /> + <preference for="Magento\Vault\Api\PaymentMethodListInterface" type="Magento\Vault\Model\PaymentMethodList" /> <preference for="Magento\Vault\Api\Data\PaymentTokenSearchResultsInterface" type="Magento\Framework\Api\SearchResults" /> <preference for="Magento\Vault\Model\Ui\TokenUiComponentInterface" type="Magento\Vault\Model\Ui\TokenUiComponent" /> diff --git a/dev/tests/functional/tests/app/Magento/Usps/Test/TestCase/OnePageCheckoutTest.xml b/dev/tests/functional/tests/app/Magento/Usps/Test/TestCase/OnePageCheckoutTest.xml index 6170b8bbe0616f70fa14cdf50722a96199cf92c3..28c2b0f16239c735c927a8d3f7ef8eb0ebc1b01b 100644 --- a/dev/tests/functional/tests/app/Magento/Usps/Test/TestCase/OnePageCheckoutTest.xml +++ b/dev/tests/functional/tests/app/Magento/Usps/Test/TestCase/OnePageCheckoutTest.xml @@ -28,15 +28,13 @@ </variation> <variation name="OnePageCheckoutUspsTestVariation2" summary="Check Out as Guest using USPS with US shipping origin and UK customer"> <data name="products/0" xsi:type="string">catalogProductSimple::default</data> - <data name="products/1" xsi:type="string">configurableProduct::default</data> - <data name="products/2" xsi:type="string">bundleProduct::bundle_fixed_product</data> <data name="checkoutMethod" xsi:type="string">guest</data> <data name="customer/dataset" xsi:type="string">default</data> <data name="address/dataset" xsi:type="string">UK_address</data> <data name="shippingAddress/dataset" xsi:type="string">UK_address</data> <data name="shipping/shipping_service" xsi:type="string">United States Postal Service</data> - <data name="shipping/shipping_method" xsi:type="string">Priority Mail International</data> - <data name="cart/data/shipping_method" xsi:type="string">Priority Mail International</data> + <data name="shipping/shipping_method" xsi:type="string">Priority Mail Express International Flat Rate Envelope</data> + <data name="cart/data/shipping_method" xsi:type="string">Priority Mail Express International Flat Rate Envelope</data> <data name="payment/method" xsi:type="string">checkmo</data> <data name="configData" xsi:type="string">checkmo, usps, shipping_origin_US_CA</data> <data name="tag" xsi:type="string">test_type:3rd_party_test</data> diff --git a/dev/tests/integration/testsuite/Magento/Braintree/Model/PaymentMethodListTest.php b/dev/tests/integration/testsuite/Magento/Braintree/Model/PaymentMethodListTest.php new file mode 100644 index 0000000000000000000000000000000000000000..0e38adda5498facd9f6213193f536128f2b20c8f --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Braintree/Model/PaymentMethodListTest.php @@ -0,0 +1,71 @@ +<?php +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Braintree\Model; + +use Magento\Braintree\Model\Ui\ConfigProvider; +use Magento\Braintree\Model\Ui\PayPal\ConfigProvider as PayPalConfigProvider; +use Magento\Store\Model\StoreManagerInterface; +use Magento\TestFramework\Helper\Bootstrap; +use Magento\Vault\Api\PaymentMethodListInterface; +use Magento\Vault\Model\VaultPaymentInterface; + +/** + * Contains tests for vault payment list methods + */ +class PaymentMethodListTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var PaymentMethodListInterface + */ + private $paymentMethodList; + + /** + * @var int + */ + private $storeId; + + protected function setUp() + { + $objectManager = Bootstrap::getObjectManager(); + $this->storeId = $objectManager->get(StoreManagerInterface::class) + ->getStore() + ->getId(); + $this->paymentMethodList = $objectManager->get(PaymentMethodListInterface::class); + } + + /** + * @magentoDataFixture Magento/Braintree/_files/payments.php + */ + public function testGetList() + { + $vaultPayments = $this->paymentMethodList->getList($this->storeId); + + static::assertNotEmpty($vaultPayments); + + $paymentCodes = array_map(function (VaultPaymentInterface $payment) { + return $payment->getCode(); + }, $vaultPayments); + + $expectedCodes = [ + PayPalConfigProvider::PAYPAL_VAULT_CODE, + ConfigProvider::CC_VAULT_CODE + ]; + static::assertNotEmpty(array_intersect($expectedCodes, $paymentCodes)); + } + + /** + * @magentoDataFixture Magento/Braintree/_files/payments.php + */ + public function testGetActiveList() + { + $vaultPayments = $this->paymentMethodList->getActiveList($this->storeId); + + static::assertNotEmpty($vaultPayments); + static::assertCount(1, $vaultPayments); + $payment = array_pop($vaultPayments); + static::assertEquals(PayPalConfigProvider::PAYPAL_VAULT_CODE, $payment->getCode()); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Braintree/_files/payments.php b/dev/tests/integration/testsuite/Magento/Braintree/_files/payments.php new file mode 100644 index 0000000000000000000000000000000000000000..99ff4481f2982f5076282161931017893380e491 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Braintree/_files/payments.php @@ -0,0 +1,16 @@ +<?php +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +use Magento\Braintree\Model\Ui\PayPal\ConfigProvider; +use Magento\Config\Model\Config; +use Magento\TestFramework\Helper\Bootstrap; + +$objectManager = Bootstrap::getObjectManager(); +/** @var Config $config */ +$config = $objectManager->get(Config::class); +$config->setDataByPath('payment/' . ConfigProvider::PAYPAL_CODE . '/active', 1); +$config->save(); +$config->setDataByPath('payment/' . ConfigProvider::PAYPAL_VAULT_CODE . '/active', 1); +$config->save();