Skip to content

Commit 946f1fb

Browse files
committed
Merge branch 'develop' into MAGETWO-53424
2 parents 9eb120d + e7d6678 commit 946f1fb

File tree

109 files changed

+1852
-1467
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+1852
-1467
lines changed

app/code/Magento/Backend/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,3 +456,4 @@ Pagination,Pagination
456456
"Anchor Text for Next","Anchor Text for Next"
457457
"Alternative text for the next pages link in the pagination menu. If empty, default arrow image is used.","Alternative text for the next pages link in the pagination menu. If empty, default arrow image is used."
458458
"Theme Name","Theme Name"
459+
"Deployment config file %1 is not writable.","Deployment config file %1 is not writable."

app/code/Magento/Braintree/Block/Form.php

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
use Magento\Braintree\Gateway\Config\Config as GatewayConfig;
1010
use Magento\Braintree\Model\Adminhtml\Source\CcType;
1111
use Magento\Braintree\Model\Ui\ConfigProvider;
12+
use Magento\Framework\App\ObjectManager;
1213
use Magento\Framework\View\Element\Template\Context;
1314
use Magento\Payment\Block\Form\Cc;
15+
use Magento\Payment\Helper\Data;
1416
use Magento\Payment\Model\Config;
1517
use Magento\Vault\Model\VaultPaymentInterface;
1618

@@ -36,17 +38,16 @@ class Form extends Cc
3638
protected $ccType;
3739

3840
/**
39-
* @var VaultPaymentInterface
41+
* @var Data
4042
*/
41-
protected $vaultService;
43+
private $paymentDataHelper;
4244

4345
/**
4446
* @param Context $context
4547
* @param Config $paymentConfig
4648
* @param Quote $sessionQuote
4749
* @param GatewayConfig $gatewayConfig
4850
* @param CcType $ccType
49-
* @param VaultPaymentInterface $vaultService
5051
* @param array $data
5152
*/
5253
public function __construct(
@@ -55,14 +56,12 @@ public function __construct(
5556
Quote $sessionQuote,
5657
GatewayConfig $gatewayConfig,
5758
CcType $ccType,
58-
VaultPaymentInterface $vaultService,
5959
array $data = []
6060
) {
6161
parent::__construct($context, $paymentConfig, $data);
6262
$this->sessionQuote = $sessionQuote;
6363
$this->gatewayConfig = $gatewayConfig;
6464
$this->ccType = $ccType;
65-
$this->vaultService = $vaultService;
6665
}
6766

6867
/**
@@ -91,7 +90,9 @@ public function useCvv()
9190
*/
9291
public function isVaultEnabled()
9392
{
94-
return $this->vaultService->isActiveForPayment(ConfigProvider::CODE);
93+
$storeId = $this->_storeManager->getStore()->getId();
94+
$vaultPayment = $this->getVaultPayment();
95+
return $vaultPayment->isActive($storeId);
9596
}
9697

9798
/**
@@ -123,4 +124,26 @@ private function filterCardTypesForCountry(array $configCardTypes, $countryId)
123124
}
124125
return $filtered;
125126
}
127+
128+
/**
129+
* Get configured vault payment for Braintree
130+
* @return VaultPaymentInterface
131+
*/
132+
private function getVaultPayment()
133+
{
134+
return $this->getPaymentDataHelper()->getMethodInstance(ConfigProvider::CC_VAULT_CODE);
135+
}
136+
137+
/**
138+
* Get payment data helper instance
139+
* @return Data
140+
* @deprecated
141+
*/
142+
private function getPaymentDataHelper()
143+
{
144+
if ($this->paymentDataHelper === null) {
145+
$this->paymentDataHelper = ObjectManager::getInstance()->get(Data::class);
146+
}
147+
return $this->paymentDataHelper;
148+
}
126149
}

app/code/Magento/Braintree/Model/Ui/ConfigProvider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ final class ConfigProvider implements ConfigProviderInterface
2020

2121
const PAYPAL_CODE = 'braintree_paypal';
2222

23+
const CC_VAULT_CODE = 'braintree_cc_vault';
24+
2325
/**
2426
* @var ResolverInterface
2527
*/
@@ -88,6 +90,7 @@ public function getConfig()
8890
'kountMerchantId' => $this->config->getKountMerchantId(),
8991
'hasFraudProtection' => $this->config->hasFraudProtection(),
9092
'merchantId' => $this->config->getMerchantId(),
93+
'ccVaultCode' => static::CC_VAULT_CODE
9194
],
9295
Config::CODE_3DSECURE => [
9396
'enabled' => $this->config->isVerify3DSecure(),

app/code/Magento/Braintree/Model/Ui/TokenUiComponentProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public function getComponentForToken(PaymentTokenInterface $paymentToken)
4949
$component = $this->componentFactory->create(
5050
[
5151
'config' => [
52+
'code' => ConfigProvider::CC_VAULT_CODE,
5253
'nonceUrl' => $this->getNonceRetrieveUrl(),
5354
TokenUiComponentProviderInterface::COMPONENT_DETAILS => $jsonDetails,
5455
TokenUiComponentProviderInterface::COMPONENT_PUBLIC_HASH => $paymentToken->getPublicHash()

app/code/Magento/Braintree/Test/Unit/Block/FormTest.php

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@
1111
use Magento\Braintree\Model\Adminhtml\Source\CcType;
1212
use Magento\Braintree\Model\Ui\ConfigProvider;
1313
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
14+
use Magento\Payment\Helper\Data;
1415
use Magento\Payment\Model\Config;
15-
use Magento\Vault\Model\Ui\VaultConfigProvider;
16+
use Magento\Store\Api\Data\StoreInterface;
17+
use Magento\Store\Model\StoreManagerInterface;
1618
use Magento\Vault\Model\VaultPaymentInterface;
19+
use OAuthTest\Mocks\Common\Service\Mock;
20+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
1721

1822
/**
1923
* Class FormTest
@@ -40,41 +44,52 @@ class FormTest extends \PHPUnit_Framework_TestCase
4044
private $block;
4145

4246
/**
43-
* @var Quote|\PHPUnit_Framework_MockObject_MockObject
47+
* @var Quote|MockObject
4448
*/
4549
private $sessionQuote;
4650

4751
/**
48-
* @var Config|\PHPUnit_Framework_MockObject_MockObject
52+
* @var Config|MockObject
4953
*/
5054
private $gatewayConfig;
5155

5256
/**
53-
* @var CcType|\PHPUnit_Framework_MockObject_MockObject
57+
* @var CcType|MockObject
5458
*/
5559
private $ccType;
5660

5761
/**
58-
* @var VaultPaymentInterface|\PHPUnit_Framework_MockObject_MockObject
62+
* @var StoreManagerInterface|MockObject
5963
*/
60-
private $vaultService;
64+
private $storeManager;
65+
66+
/**
67+
* @var Data|MockObject
68+
*/
69+
private $paymentDataHelper;
6170

6271
protected function setUp()
6372
{
6473
$this->initCcTypeMock();
6574
$this->initSessionQuoteMock();
6675
$this->initGatewayConfigMock();
67-
68-
$this->vaultService = $this->getMock(VaultPaymentInterface::class);
76+
77+
$this->storeManager = $this->getMockForAbstractClass(StoreManagerInterface::class);
78+
$this->paymentDataHelper = $this->getMockBuilder(Data::class)
79+
->disableOriginalConstructor()
80+
->setMethods(['getMethodInstance'])
81+
->getMock();
6982

7083
$managerHelper = new ObjectManager($this);
7184
$this->block = $managerHelper->getObject(Form::class, [
7285
'paymentConfig' => $managerHelper->getObject(Config::class),
7386
'sessionQuote' => $this->sessionQuote,
7487
'gatewayConfig' => $this->gatewayConfig,
7588
'ccType' => $this->ccType,
76-
'vaultService' => $this->vaultService
89+
'storeManager' => $this->storeManager
7790
]);
91+
92+
$managerHelper->setBackwardCompatibleProperty($this->block, 'paymentDataHelper', $this->paymentDataHelper);
7893
}
7994

8095
/**
@@ -117,11 +132,30 @@ public function countryCardTypesDataProvider()
117132
];
118133
}
119134

135+
/**
136+
* @covers \Magento\Braintree\Block\Form::isVaultEnabled
137+
*/
120138
public function testIsVaultEnabled()
121139
{
122-
$this->vaultService->expects(static::once())
123-
->method('isActiveForPayment')
124-
->with(ConfigProvider::CODE)
140+
$storeId = 1;
141+
$store = $this->getMockForAbstractClass(StoreInterface::class);
142+
$this->storeManager->expects(static::once())
143+
->method('getStore')
144+
->willReturn($store);
145+
146+
$store->expects(static::once())
147+
->method('getId')
148+
->willReturn($storeId);
149+
150+
$vaultPayment = $this->getMockForAbstractClass(VaultPaymentInterface::class);
151+
$this->paymentDataHelper->expects(static::once())
152+
->method('getMethodInstance')
153+
->with(ConfigProvider::CC_VAULT_CODE)
154+
->willReturn($vaultPayment);
155+
156+
$vaultPayment->expects(static::once())
157+
->method('isActive')
158+
->with($storeId)
125159
->willReturn(true);
126160

127161
static::assertTrue($this->block->isVaultEnabled());

app/code/Magento/Braintree/Test/Unit/Model/Ui/ConfigProviderTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public function getConfigDataProvider()
148148
'getEnvironment' => 'test-environment',
149149
'getKountMerchantId' => 'test-kount-merchant-id',
150150
'getMerchantId' => 'test-merchant-id',
151-
'hasFraudProtection' => true
151+
'hasFraudProtection' => true,
152152
],
153153
'expected' => [
154154
'payment' => [
@@ -167,7 +167,8 @@ public function getConfigDataProvider()
167167
'environment' => 'test-environment',
168168
'kountMerchantId' => 'test-kount-merchant-id',
169169
'merchantId' => 'test-merchant-id',
170-
'hasFraudProtection' => true
170+
'hasFraudProtection' => true,
171+
'ccVaultCode' => ConfigProvider::CC_VAULT_CODE
171172
],
172173
Config::CODE_3DSECURE => [
173174
'enabled' => true,

app/code/Magento/Braintree/etc/adminhtml/di.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@
1919
</arguments>
2020
</type>
2121

22-
<type name="Magento\Vault\Model\Adminhtml\Source\VaultProvidersMap">
23-
<arguments>
24-
<argument name="options" xsi:type="array">
25-
<item xsi:type="object" name="braintree">BraintreeFacade</item>
26-
</argument>
27-
</arguments>
28-
</type>
2922
<virtualType name="BraintreeAuthorizeDataBuilder" type="Magento\Payment\Gateway\Request\BuilderComposite">
3023
<arguments>
3124
<argument name="builders" xsi:type="array">

app/code/Magento/Braintree/etc/adminhtml/system.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@
3434
<group id="braintree_required"/>
3535
</requires>
3636
</field>
37+
<field id="braintree_cc_vault_active" translate="label" type="select" sortOrder="12" showInDefault="1" showInWebsite="1" showInStore="0">
38+
<label>Vault enabled</label>
39+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
40+
<config_path>payment/braintree_cc_vault/active</config_path>
41+
<requires>
42+
<group id="braintree_required"/>
43+
</requires>
44+
</field>
3745
<group id="braintree_required" translate="label" showInDefault="1" showInWebsite="1" sortOrder="5">
3846
<comment><![CDATA[<a href="https://www.braintreegateway.com/login" target="_blank">Click here to login to your existing Braintree account</a>. Or to setup a new account and accept payments on your website, <a href="https://apply.braintreegateway.com/signup/us" target="_blank">click here to signup for a Braintree account</a>.]]></comment>
3947
<label>Basic Braintree Settings</label>
@@ -71,6 +79,10 @@
7179
<group id="braintree_advanced" translate="label" showInDefault="1" showInWebsite="1" sortOrder="20">
7280
<label>Advanced Braintree Settings</label>
7381
<frontend_model>Magento\Config\Block\System\Config\Form\Fieldset</frontend_model>
82+
<field id="braintree_cc_vault_title" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="0">
83+
<label>Vault Title</label>
84+
<config_path>payment/braintree_cc_vault/title</config_path>
85+
</field>
7486
<field id="merchant_account_id" translate="label" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="0">
7587
<label>Merchant Account ID</label>
7688
<comment>If you don't specify the merchant account to use to process a transaction, Braintree will process it using your default merchant account.</comment>

app/code/Magento/Braintree/etc/config.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@
6060
<privateInfoKeys>processorResponseCode,processorResponseText,paymentId</privateInfoKeys>
6161
<paymentInfoKeys>processorResponseCode,processorResponseText,paymentId,payerEmail</paymentInfoKeys>
6262
</braintree_paypal>
63+
<braintree_cc_vault>
64+
<model>BraintreeCreditCardVaultFacade</model>
65+
<title>Stored Cards (Braintree)</title>
66+
</braintree_cc_vault>
6367
</payment>
6468
</default>
6569
</config>

app/code/Magento/Braintree/etc/di.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,32 @@
2525
<argument name="commandPool" xsi:type="object">BraintreePayPalCommandPool</argument>
2626
</arguments>
2727
</virtualType>
28+
<!-- Configuration for Braintree Vault payment -->
29+
<virtualType name="BraintreeVaultPaymentConfig" type="Magento\Payment\Gateway\Config\Config">
30+
<arguments>
31+
<argument name="methodCode" xsi:type="const">Magento\Braintree\Model\Ui\ConfigProvider::CC_VAULT_CODE</argument>
32+
</arguments>
33+
</virtualType>
34+
<virtualType name="BraintreeVaultPaymentValueHandler" type="VaultPaymentDefaultValueHandler">
35+
<arguments>
36+
<argument name="configInterface" xsi:type="object">BraintreeVaultPaymentConfig</argument>
37+
</arguments>
38+
</virtualType>
39+
<virtualType name="BraintreeVaultPaymentValueHandlerPool" type="VaultPaymentValueHandlerPool">
40+
<arguments>
41+
<argument name="handlers" xsi:type="array">
42+
<item name="default" xsi:type="string">BraintreeVaultPaymentValueHandler</item>
43+
</argument>
44+
</arguments>
45+
</virtualType>
46+
<virtualType name="BraintreeCreditCardVaultFacade" type="Magento\Vault\Model\Method\Vault">
47+
<arguments>
48+
<argument name="config" xsi:type="object">BraintreeVaultPaymentConfig</argument>
49+
<argument name="valueHandlerPool" xsi:type="object">BraintreeVaultPaymentValueHandlerPool</argument>
50+
<argument name="vaultProvider" xsi:type="object">BraintreeFacade</argument>
51+
<argument name="code" xsi:type="const">Magento\Braintree\Model\Ui\ConfigProvider::CC_VAULT_CODE</argument>
52+
</arguments>
53+
</virtualType>
2854

2955
<!-- Configuration reader -->
3056
<type name="Magento\Braintree\Gateway\Config\Config">

0 commit comments

Comments
 (0)