Skip to content

Commit e4d858b

Browse files
author
Hayder Sharhan
committed
Merge remote-tracking branch 'remotes/mainline/develop' into MAGETWO-54051-Inline-Prevents-Frontend-Login
2 parents 4dc358d + a27a846 commit e4d858b

File tree

90 files changed

+1452
-1369
lines changed

Some content is hidden

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

90 files changed

+1452
-1369
lines changed

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
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Braintree\Gateway\Request;
7+
8+
use Magento\Payment\Gateway\Request\BuilderInterface;
9+
use Magento\Framework\App\ProductMetadataInterface;
10+
11+
/**
12+
* Class BnCodeDataBuilder
13+
*/
14+
class ChannelDataBuilder implements BuilderInterface
15+
{
16+
/**
17+
* @var ProductMetadataInterface
18+
*/
19+
private $productMetadata;
20+
21+
/**
22+
* @var string
23+
*/
24+
private static $channel = 'channel';
25+
26+
/**
27+
* @var string
28+
*/
29+
private static $channelValue = 'Magento2_Cart_%s_BT';
30+
31+
/**
32+
* Constructor
33+
*
34+
* @param ProductMetadataInterface $productMetadata
35+
*/
36+
public function __construct(ProductMetadataInterface $productMetadata)
37+
{
38+
$this->productMetadata = $productMetadata;
39+
}
40+
41+
/**
42+
* @inheritdoc
43+
*/
44+
public function build(array $buildSubject)
45+
{
46+
return [
47+
self::$channel => sprintf(self::$channelValue, $this->productMetadata->getEdition())
48+
];
49+
}
50+
}

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());
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Braintree\Test\Unit\Gateway\Request;
7+
8+
use Magento\Braintree\Gateway\Request\ChannelDataBuilder;
9+
use Magento\Framework\App\ProductMetadataInterface;
10+
11+
/**
12+
* Class PaymentDataBuilderTest
13+
*
14+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
15+
*/
16+
class ChannelDataBuilderTest extends \PHPUnit_Framework_TestCase
17+
{
18+
/**
19+
* @var ProductMetadataInterface|\PHPUnit_Framework_MockObject_MockObject
20+
*/
21+
private $productMetadataMock;
22+
23+
/**
24+
* @var ChannelDataBuilder
25+
*/
26+
private $builder;
27+
28+
protected function setUp()
29+
{
30+
$this->productMetadataMock = $this->getMock(ProductMetadataInterface::class);
31+
$this->builder = new ChannelDataBuilder($this->productMetadataMock);
32+
}
33+
34+
/**
35+
* @param string $edition
36+
* @param array $expected
37+
* @covers \Magento\Braintree\Gateway\Request\ChannelDataBuilder::build
38+
* @dataProvider buildDataProvider
39+
*/
40+
public function testBuild($edition, array $expected)
41+
{
42+
$buildSubject = [];
43+
$this->productMetadataMock->expects(static::once())
44+
->method('getEdition')
45+
->willReturn($edition);
46+
47+
$this->assertEquals($expected, $this->builder->build($buildSubject));
48+
}
49+
50+
/**
51+
* Get list of variations for build test
52+
* @return array
53+
*/
54+
public function buildDataProvider()
55+
{
56+
return [
57+
['FirstEdition', ['channel' => 'Magento2_Cart_FirstEdition_BT']],
58+
['SecondEdition', ['channel' => 'Magento2_Cart_SecondEdition_BT']],
59+
];
60+
}
61+
}

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: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,12 @@
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">
3225
<item name="customer" xsi:type="string">Magento\Braintree\Gateway\Request\CustomerDataBuilder</item>
3326
<item name="payment" xsi:type="string">Magento\Braintree\Gateway\Request\PaymentDataBuilder</item>
27+
<item name="channel" xsi:type="string">Magento\Braintree\Gateway\Request\ChannelDataBuilder</item>
3428
<item name="address" xsi:type="string">Magento\Braintree\Gateway\Request\AddressDataBuilder</item>
3529
<item name="vault" xsi:type="string">Magento\Braintree\Gateway\Request\VaultDataBuilder</item>
3630
</argument>
@@ -41,6 +35,7 @@
4135
<argument name="builders" xsi:type="array">
4236
<item name="customer" xsi:type="string">Magento\Braintree\Gateway\Request\CustomerDataBuilder</item>
4337
<item name="payment" xsi:type="string">Magento\Braintree\Gateway\Request\PaymentDataBuilder</item>
38+
<item name="channel" xsi:type="string">Magento\Braintree\Gateway\Request\ChannelDataBuilder</item>
4439
<item name="address" xsi:type="string">Magento\Braintree\Gateway\Request\AddressDataBuilder</item>
4540
</argument>
4641
</arguments>

0 commit comments

Comments
 (0)