diff --git a/app/code/Magento/Braintree/Block/Form.php b/app/code/Magento/Braintree/Block/Form.php
index dc0071f175fb1..cefc0a8418243 100644
--- a/app/code/Magento/Braintree/Block/Form.php
+++ b/app/code/Magento/Braintree/Block/Form.php
@@ -9,8 +9,10 @@
use Magento\Braintree\Gateway\Config\Config as GatewayConfig;
use Magento\Braintree\Model\Adminhtml\Source\CcType;
use Magento\Braintree\Model\Ui\ConfigProvider;
+use Magento\Framework\App\ObjectManager;
use Magento\Framework\View\Element\Template\Context;
use Magento\Payment\Block\Form\Cc;
+use Magento\Payment\Helper\Data;
use Magento\Payment\Model\Config;
use Magento\Vault\Model\VaultPaymentInterface;
@@ -36,9 +38,9 @@ class Form extends Cc
protected $ccType;
/**
- * @var VaultPaymentInterface
+ * @var Data
*/
- protected $vaultService;
+ private $paymentDataHelper;
/**
* @param Context $context
@@ -46,7 +48,6 @@ class Form extends Cc
* @param Quote $sessionQuote
* @param GatewayConfig $gatewayConfig
* @param CcType $ccType
- * @param VaultPaymentInterface $vaultService
* @param array $data
*/
public function __construct(
@@ -55,14 +56,12 @@ public function __construct(
Quote $sessionQuote,
GatewayConfig $gatewayConfig,
CcType $ccType,
- VaultPaymentInterface $vaultService,
array $data = []
) {
parent::__construct($context, $paymentConfig, $data);
$this->sessionQuote = $sessionQuote;
$this->gatewayConfig = $gatewayConfig;
$this->ccType = $ccType;
- $this->vaultService = $vaultService;
}
/**
@@ -91,7 +90,9 @@ public function useCvv()
*/
public function isVaultEnabled()
{
- return $this->vaultService->isActiveForPayment(ConfigProvider::CODE);
+ $storeId = $this->_storeManager->getStore()->getId();
+ $vaultPayment = $this->getVaultPayment();
+ return $vaultPayment->isActive($storeId);
}
/**
@@ -123,4 +124,26 @@ private function filterCardTypesForCountry(array $configCardTypes, $countryId)
}
return $filtered;
}
+
+ /**
+ * Get configured vault payment for Braintree
+ * @return VaultPaymentInterface
+ */
+ private function getVaultPayment()
+ {
+ return $this->getPaymentDataHelper()->getMethodInstance(ConfigProvider::CC_VAULT_CODE);
+ }
+
+ /**
+ * Get payment data helper instance
+ * @return Data
+ * @deprecated
+ */
+ private function getPaymentDataHelper()
+ {
+ if ($this->paymentDataHelper === null) {
+ $this->paymentDataHelper = ObjectManager::getInstance()->get(Data::class);
+ }
+ return $this->paymentDataHelper;
+ }
}
diff --git a/app/code/Magento/Braintree/Model/Ui/ConfigProvider.php b/app/code/Magento/Braintree/Model/Ui/ConfigProvider.php
index bba77b0fe9682..d720b748ba819 100644
--- a/app/code/Magento/Braintree/Model/Ui/ConfigProvider.php
+++ b/app/code/Magento/Braintree/Model/Ui/ConfigProvider.php
@@ -20,6 +20,8 @@ final class ConfigProvider implements ConfigProviderInterface
const PAYPAL_CODE = 'braintree_paypal';
+ const CC_VAULT_CODE = 'braintree_cc_vault';
+
/**
* @var ResolverInterface
*/
@@ -88,6 +90,7 @@ public function getConfig()
'kountMerchantId' => $this->config->getKountMerchantId(),
'hasFraudProtection' => $this->config->hasFraudProtection(),
'merchantId' => $this->config->getMerchantId(),
+ 'ccVaultCode' => static::CC_VAULT_CODE
],
Config::CODE_3DSECURE => [
'enabled' => $this->config->isVerify3DSecure(),
diff --git a/app/code/Magento/Braintree/Model/Ui/TokenUiComponentProvider.php b/app/code/Magento/Braintree/Model/Ui/TokenUiComponentProvider.php
index 5f511ebbf4e3d..1fe3fb24db8d8 100644
--- a/app/code/Magento/Braintree/Model/Ui/TokenUiComponentProvider.php
+++ b/app/code/Magento/Braintree/Model/Ui/TokenUiComponentProvider.php
@@ -49,6 +49,7 @@ public function getComponentForToken(PaymentTokenInterface $paymentToken)
$component = $this->componentFactory->create(
[
'config' => [
+ 'code' => ConfigProvider::CC_VAULT_CODE,
'nonceUrl' => $this->getNonceRetrieveUrl(),
TokenUiComponentProviderInterface::COMPONENT_DETAILS => $jsonDetails,
TokenUiComponentProviderInterface::COMPONENT_PUBLIC_HASH => $paymentToken->getPublicHash()
diff --git a/app/code/Magento/Braintree/Test/Unit/Block/FormTest.php b/app/code/Magento/Braintree/Test/Unit/Block/FormTest.php
index 6c07d2401d56c..f056ba0cefd36 100644
--- a/app/code/Magento/Braintree/Test/Unit/Block/FormTest.php
+++ b/app/code/Magento/Braintree/Test/Unit/Block/FormTest.php
@@ -11,9 +11,13 @@
use Magento\Braintree\Model\Adminhtml\Source\CcType;
use Magento\Braintree\Model\Ui\ConfigProvider;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
+use Magento\Payment\Helper\Data;
use Magento\Payment\Model\Config;
-use Magento\Vault\Model\Ui\VaultConfigProvider;
+use Magento\Store\Api\Data\StoreInterface;
+use Magento\Store\Model\StoreManagerInterface;
use Magento\Vault\Model\VaultPaymentInterface;
+use OAuthTest\Mocks\Common\Service\Mock;
+use PHPUnit_Framework_MockObject_MockObject as MockObject;
/**
* Class FormTest
@@ -40,32 +44,41 @@ class FormTest extends \PHPUnit_Framework_TestCase
private $block;
/**
- * @var Quote|\PHPUnit_Framework_MockObject_MockObject
+ * @var Quote|MockObject
*/
private $sessionQuote;
/**
- * @var Config|\PHPUnit_Framework_MockObject_MockObject
+ * @var Config|MockObject
*/
private $gatewayConfig;
/**
- * @var CcType|\PHPUnit_Framework_MockObject_MockObject
+ * @var CcType|MockObject
*/
private $ccType;
/**
- * @var VaultPaymentInterface|\PHPUnit_Framework_MockObject_MockObject
+ * @var StoreManagerInterface|MockObject
*/
- private $vaultService;
+ private $storeManager;
+
+ /**
+ * @var Data|MockObject
+ */
+ private $paymentDataHelper;
protected function setUp()
{
$this->initCcTypeMock();
$this->initSessionQuoteMock();
$this->initGatewayConfigMock();
-
- $this->vaultService = $this->getMock(VaultPaymentInterface::class);
+
+ $this->storeManager = $this->getMockForAbstractClass(StoreManagerInterface::class);
+ $this->paymentDataHelper = $this->getMockBuilder(Data::class)
+ ->disableOriginalConstructor()
+ ->setMethods(['getMethodInstance'])
+ ->getMock();
$managerHelper = new ObjectManager($this);
$this->block = $managerHelper->getObject(Form::class, [
@@ -73,8 +86,10 @@ protected function setUp()
'sessionQuote' => $this->sessionQuote,
'gatewayConfig' => $this->gatewayConfig,
'ccType' => $this->ccType,
- 'vaultService' => $this->vaultService
+ 'storeManager' => $this->storeManager
]);
+
+ $managerHelper->setBackwardCompatibleProperty($this->block, 'paymentDataHelper', $this->paymentDataHelper);
}
/**
@@ -117,11 +132,30 @@ public function countryCardTypesDataProvider()
];
}
+ /**
+ * @covers \Magento\Braintree\Block\Form::isVaultEnabled
+ */
public function testIsVaultEnabled()
{
- $this->vaultService->expects(static::once())
- ->method('isActiveForPayment')
- ->with(ConfigProvider::CODE)
+ $storeId = 1;
+ $store = $this->getMockForAbstractClass(StoreInterface::class);
+ $this->storeManager->expects(static::once())
+ ->method('getStore')
+ ->willReturn($store);
+
+ $store->expects(static::once())
+ ->method('getId')
+ ->willReturn($storeId);
+
+ $vaultPayment = $this->getMockForAbstractClass(VaultPaymentInterface::class);
+ $this->paymentDataHelper->expects(static::once())
+ ->method('getMethodInstance')
+ ->with(ConfigProvider::CC_VAULT_CODE)
+ ->willReturn($vaultPayment);
+
+ $vaultPayment->expects(static::once())
+ ->method('isActive')
+ ->with($storeId)
->willReturn(true);
static::assertTrue($this->block->isVaultEnabled());
diff --git a/app/code/Magento/Braintree/Test/Unit/Model/Ui/ConfigProviderTest.php b/app/code/Magento/Braintree/Test/Unit/Model/Ui/ConfigProviderTest.php
index 71f87f1ec398d..a787111fa93aa 100644
--- a/app/code/Magento/Braintree/Test/Unit/Model/Ui/ConfigProviderTest.php
+++ b/app/code/Magento/Braintree/Test/Unit/Model/Ui/ConfigProviderTest.php
@@ -148,7 +148,7 @@ public function getConfigDataProvider()
'getEnvironment' => 'test-environment',
'getKountMerchantId' => 'test-kount-merchant-id',
'getMerchantId' => 'test-merchant-id',
- 'hasFraudProtection' => true
+ 'hasFraudProtection' => true,
],
'expected' => [
'payment' => [
@@ -167,7 +167,8 @@ public function getConfigDataProvider()
'environment' => 'test-environment',
'kountMerchantId' => 'test-kount-merchant-id',
'merchantId' => 'test-merchant-id',
- 'hasFraudProtection' => true
+ 'hasFraudProtection' => true,
+ 'ccVaultCode' => ConfigProvider::CC_VAULT_CODE
],
Config::CODE_3DSECURE => [
'enabled' => true,
diff --git a/app/code/Magento/Braintree/etc/adminhtml/di.xml b/app/code/Magento/Braintree/etc/adminhtml/di.xml
index 5a2c4da5dcd8f..9cffa57abd6dc 100644
--- a/app/code/Magento/Braintree/etc/adminhtml/di.xml
+++ b/app/code/Magento/Braintree/etc/adminhtml/di.xml
@@ -19,13 +19,6 @@
-
-
-
- - BraintreeFacade
-
-
-
diff --git a/app/code/Magento/Braintree/etc/adminhtml/system.xml b/app/code/Magento/Braintree/etc/adminhtml/system.xml
index a3752db022111..3668cd7779fda 100644
--- a/app/code/Magento/Braintree/etc/adminhtml/system.xml
+++ b/app/code/Magento/Braintree/etc/adminhtml/system.xml
@@ -34,6 +34,14 @@
+
+
+ Magento\Config\Model\Config\Source\Yesno
+ payment/braintree_cc_vault/active
+
+
+
+
Click here to login to your existing Braintree account. Or to setup a new account and accept payments on your website, click here to signup for a Braintree account.]]>
@@ -71,6 +79,10 @@
Magento\Config\Block\System\Config\Form\Fieldset
+
+
+ payment/braintree_cc_vault/title
+
If you don't specify the merchant account to use to process a transaction, Braintree will process it using your default merchant account.
diff --git a/app/code/Magento/Braintree/etc/config.xml b/app/code/Magento/Braintree/etc/config.xml
index 5a1076eabf071..7511ec2ca1563 100644
--- a/app/code/Magento/Braintree/etc/config.xml
+++ b/app/code/Magento/Braintree/etc/config.xml
@@ -60,6 +60,10 @@
processorResponseCode,processorResponseText,paymentId
processorResponseCode,processorResponseText,paymentId,payerEmail
+
+ BraintreeCreditCardVaultFacade
+ Stored Cards (Braintree)
+
diff --git a/app/code/Magento/Braintree/etc/di.xml b/app/code/Magento/Braintree/etc/di.xml
index 359cb93b2d82a..def12ff4c8a7e 100644
--- a/app/code/Magento/Braintree/etc/di.xml
+++ b/app/code/Magento/Braintree/etc/di.xml
@@ -25,6 +25,32 @@
BraintreePayPalCommandPool
+
+
+
+ Magento\Braintree\Model\Ui\ConfigProvider::CC_VAULT_CODE
+
+
+
+
+ BraintreeVaultPaymentConfig
+
+
+
+
+
+ - BraintreeVaultPaymentValueHandler
+
+
+
+
+
+ BraintreeVaultPaymentConfig
+ BraintreeVaultPaymentValueHandlerPool
+ BraintreeFacade
+ Magento\Braintree\Model\Ui\ConfigProvider::CC_VAULT_CODE
+
+
diff --git a/app/code/Magento/Braintree/view/adminhtml/layout/sales_order_create_index.xml b/app/code/Magento/Braintree/view/adminhtml/layout/sales_order_create_index.xml
index c881e008dc24f..76f6b5a4d616c 100644
--- a/app/code/Magento/Braintree/view/adminhtml/layout/sales_order_create_index.xml
+++ b/app/code/Magento/Braintree/view/adminhtml/layout/sales_order_create_index.xml
@@ -13,6 +13,12 @@
Magento_Braintree::form/cc.phtml
+
+
+ braintree_cc_vault
+ Magento_Vault::form/vault.phtml
+
+
Magento_Braintree::form/cc.phtml
+
+
+ braintree_cc_vault
+ Magento_Vault::form/vault.phtml
+
+