Skip to content

Commit 9936cb7

Browse files
author
Stanislav Idolov
committed
Merge remote-tracking branch 'mainline/develop' into bugfix
2 parents cec25e1 + 0c6227d commit 9936cb7

File tree

285 files changed

+6786
-2974
lines changed

Some content is hidden

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

285 files changed

+6786
-2974
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ atlassian*
2323
/lib/internal/flex/varien/.settings
2424
/node_modules
2525
/.grunt
26+
/Gruntfile.js
27+
/package.json
2628

2729
/pub/media/*.*
2830
!/pub/media/.htaccess
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Braintree\Model\Ui\Adminhtml\PayPal;
7+
8+
use Magento\Braintree\Gateway\Config\PayPal\Config;
9+
use Magento\Braintree\Model\Ui\ConfigProvider;
10+
use Magento\Braintree\Model\Ui\PayPal\ConfigProvider as PayPalConfigProvider;
11+
use Magento\Framework\UrlInterface;
12+
use Magento\Framework\View\Element\Template;
13+
use Magento\Vault\Api\Data\PaymentTokenInterface;
14+
use Magento\Vault\Model\Ui\TokenUiComponentInterfaceFactory;
15+
use Magento\Vault\Model\Ui\TokenUiComponentProviderInterface;
16+
17+
/**
18+
* Gets Ui component configuration for Braintree PayPal Vault
19+
*/
20+
class TokenUiComponentProvider implements TokenUiComponentProviderInterface
21+
{
22+
23+
/**
24+
* @var TokenUiComponentInterfaceFactory
25+
*/
26+
private $componentFactory;
27+
28+
/**
29+
* @var UrlInterface
30+
*/
31+
private $urlBuilder;
32+
33+
/**
34+
* @var Config
35+
*/
36+
private $config;
37+
38+
/**
39+
* @param TokenUiComponentInterfaceFactory $componentFactory
40+
* @param UrlInterface $urlBuilder
41+
* @param Config $config
42+
*/
43+
public function __construct(
44+
TokenUiComponentInterfaceFactory $componentFactory,
45+
UrlInterface $urlBuilder,
46+
Config $config
47+
) {
48+
$this->componentFactory = $componentFactory;
49+
$this->urlBuilder = $urlBuilder;
50+
$this->config = $config;
51+
}
52+
53+
/**
54+
* @inheritdoc
55+
*/
56+
public function getComponentForToken(PaymentTokenInterface $paymentToken)
57+
{
58+
$data = json_decode($paymentToken->getTokenDetails() ?: '{}', true);
59+
$data['icon'] = $this->config->getPayPalIcon();
60+
$component = $this->componentFactory->create(
61+
[
62+
'config' => [
63+
'code' => PayPalConfigProvider::PAYPAL_VAULT_CODE,
64+
'nonceUrl' => $this->getNonceRetrieveUrl(),
65+
TokenUiComponentProviderInterface::COMPONENT_DETAILS => $data,
66+
TokenUiComponentProviderInterface::COMPONENT_PUBLIC_HASH => $paymentToken->getPublicHash(),
67+
'template' => 'Magento_Braintree::form/paypal/vault.phtml'
68+
],
69+
'name' => Template::class
70+
]
71+
);
72+
73+
return $component;
74+
}
75+
76+
/**
77+
* Get url to retrieve payment method nonce
78+
* @return string
79+
*/
80+
private function getNonceRetrieveUrl()
81+
{
82+
return $this->urlBuilder->getUrl(ConfigProvider::CODE . '/payment/getnonce', ['_secure' => true]);
83+
}
84+
}

Diff for: app/code/Magento/Braintree/Model/Ui/Adminhtml/TokenUiComponentProvider.php

+1
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 => $data,
5455
TokenUiComponentProviderInterface::COMPONENT_PUBLIC_HASH => $paymentToken->getPublicHash(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Braintree\Test\Unit\Model\Ui\Adminhtml\PayPal;
7+
8+
use Magento\Braintree\Gateway\Config\PayPal\Config;
9+
use Magento\Braintree\Model\Ui\Adminhtml\PayPal\TokenUiComponentProvider;
10+
use Magento\Framework\UrlInterface;
11+
use Magento\Vault\Api\Data\PaymentTokenInterface;
12+
use Magento\Vault\Model\Ui\TokenUiComponentInterface;
13+
use Magento\Vault\Model\Ui\TokenUiComponentInterfaceFactory;
14+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
15+
16+
/**
17+
* Contains methods to test PayPal token Ui component provider
18+
*/
19+
class TokenUiComponentProviderTest extends \PHPUnit_Framework_TestCase
20+
{
21+
/**
22+
* @var TokenUiComponentInterfaceFactory|MockObject
23+
*/
24+
private $componentFactory;
25+
26+
/**
27+
* @var UrlInterface|MockObject
28+
*/
29+
private $urlBuilder;
30+
31+
/**
32+
* @var Config|MockObject
33+
*/
34+
private $config;
35+
36+
/**
37+
* @var TokenUiComponentProvider
38+
*/
39+
private $tokenUiComponentProvider;
40+
41+
protected function setUp()
42+
{
43+
$this->componentFactory = $this->getMockBuilder(TokenUiComponentInterfaceFactory::class)
44+
->disableOriginalConstructor()
45+
->setMethods(['create'])
46+
->getMock();
47+
48+
$this->urlBuilder = $this->getMock(UrlInterface::class);
49+
50+
$this->config = $this->getMockBuilder(Config::class)
51+
->disableOriginalConstructor()
52+
->setMethods(['getPayPalIcon'])
53+
->getMock();
54+
55+
$this->tokenUiComponentProvider = new TokenUiComponentProvider(
56+
$this->componentFactory,
57+
$this->urlBuilder,
58+
$this->config
59+
);
60+
}
61+
62+
/**
63+
* @covers \Magento\Braintree\Model\Ui\Adminhtml\PayPal\TokenUiComponentProvider::getComponentForToken
64+
*/
65+
public function testGetComponentForToken()
66+
{
67+
$nonceUrl = 'https://payment/adminhtml/nonce/url';
68+
$payerEmail = 'john.doe@test.com';
69+
$icon = [
70+
'url' => 'https://payment/adminhtml/icon.png',
71+
'width' => 48,
72+
'height' => 32
73+
];
74+
75+
$expected = [
76+
'code' => 'vault',
77+
'nonceUrl' => $nonceUrl,
78+
'details' => [
79+
'payerEmail' => $payerEmail,
80+
'icon' => $icon
81+
],
82+
'template' => 'vault.phtml'
83+
];
84+
85+
$this->config->expects(static::once())
86+
->method('getPayPalIcon')
87+
->willReturn($icon);
88+
89+
$paymentToken = $this->getMock(PaymentTokenInterface::class);
90+
$paymentToken->expects(static::once())
91+
->method('getTokenDetails')
92+
->willReturn('{"payerEmail":" ' . $payerEmail . '"}');
93+
$paymentToken->expects(static::once())
94+
->method('getPublicHash')
95+
->willReturn('cmk32dl21l');
96+
97+
$this->urlBuilder->expects(static::once())
98+
->method('getUrl')
99+
->willReturn($nonceUrl);
100+
101+
$tokenComponent = $this->getMock(TokenUiComponentInterface::class);
102+
$tokenComponent->expects(static::once())
103+
->method('getConfig')
104+
->willReturn($expected);
105+
106+
$this->componentFactory->expects(static::once())
107+
->method('create')
108+
->willReturn($tokenComponent);
109+
110+
$component = $this->tokenUiComponentProvider->getComponentForToken($paymentToken);
111+
static::assertEquals($tokenComponent, $component);
112+
static::assertEquals($expected, $component->getConfig());
113+
}
114+
}

Diff for: app/code/Magento/Braintree/Test/Unit/Model/Ui/Adminhtml/TokenUiComponentProviderTest.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
use Magento\Braintree\Model\Ui\Adminhtml\TokenUiComponentProvider;
99
use Magento\Framework\UrlInterface;
10-
use Magento\Framework\View\Element\Template;
1110
use Magento\Vault\Api\Data\PaymentTokenInterface;
1211
use Magento\Vault\Model\Ui\TokenUiComponentInterface;
1312
use Magento\Vault\Model\Ui\TokenUiComponentInterfaceFactory;
13+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
1414

1515
/**
1616
* Class TokenUiComponentProviderTest
@@ -19,12 +19,12 @@ class TokenUiComponentProviderTest extends \PHPUnit_Framework_TestCase
1919
{
2020

2121
/**
22-
* @var TokenUiComponentInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject
22+
* @var TokenUiComponentInterfaceFactory|MockObject
2323
*/
2424
private $componentFactory;
2525

2626
/**
27-
* @var UrlInterface|\PHPUnit_Framework_MockObject_MockObject
27+
* @var UrlInterface|MockObject
2828
*/
2929
private $urlBuilder;
3030

@@ -59,6 +59,7 @@ public function testGetComponentForToken()
5959
$expirationDate = '12/2015';
6060

6161
$expected = [
62+
'code' => 'vault',
6263
'nonceUrl' => $nonceUrl,
6364
'details' => [
6465
'type' => $type,

Diff for: app/code/Magento/Braintree/etc/adminhtml/di.xml

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<arguments>
4848
<argument name="tokenUiComponentProviders" xsi:type="array">
4949
<item name="braintree" xsi:type="object">Magento\Braintree\Model\Ui\Adminhtml\TokenUiComponentProvider</item>
50+
<item name="braintree_paypal" xsi:type="object">Magento\Braintree\Model\Ui\Adminhtml\PayPal\TokenUiComponentProvider</item>
5051
</argument>
5152
</arguments>
5253
</type>

Diff for: app/code/Magento/Braintree/etc/config.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
</braintree_cc_vault>
7272
<braintree_paypal_vault>
7373
<model>BraintreePayPalVaultFacade</model>
74-
<title>Vault Token (Braintree PayPal)</title>
74+
<title>Stored Accounts (Braintree PayPal)</title>
75+
<can_use_internal>1</can_use_internal>
7576
</braintree_paypal_vault>
7677
</payment>
7778
</default>

Diff for: app/code/Magento/Braintree/view/adminhtml/layout/sales_order_create_index.xml

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
<argument name="method" xsi:type="string">braintree_cc_vault</argument>
1919
<argument name="template" xsi:type="string">Magento_Vault::form/vault.phtml</argument>
2020
</action>
21+
<action method="setMethodFormTemplate">
22+
<argument name="method" xsi:type="string">braintree_paypal_vault</argument>
23+
<argument name="template" xsi:type="string">Magento_Vault::form/vault.phtml</argument>
24+
</action>
2125
</referenceBlock>
2226
<referenceBlock name="content">
2327
<block name="braintree_payment_script"

Diff for: app/code/Magento/Braintree/view/adminhtml/layout/sales_order_create_load_block_billing_method.xml

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
<argument name="method" xsi:type="string">braintree_cc_vault</argument>
1919
<argument name="template" xsi:type="string">Magento_Vault::form/vault.phtml</argument>
2020
</action>
21+
<action method="setMethodFormTemplate">
22+
<argument name="method" xsi:type="string">braintree_paypal_vault</argument>
23+
<argument name="template" xsi:type="string">Magento_Vault::form/vault.phtml</argument>
24+
</action>
2125
</referenceBlock>
2226
</body>
2327
</page>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
use Magento\Vault\Model\Ui\TokenUiComponentProviderInterface;
3+
/**
4+
* Copyright © 2016 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
// @codingStandardsIgnoreFile
8+
9+
/** @var \Magento\Framework\View\Element\Template $block */
10+
$details = $block->getData(TokenUiComponentProviderInterface::COMPONENT_DETAILS);
11+
$icon = $details['icon'];
12+
$id = $block->escapeHtml($block->getData('id'));
13+
?>
14+
<div data-mage-init='{
15+
"Magento_Braintree/js/vault": {
16+
"container": "payment_<?php /* @noEscape */ echo $id; ?>",
17+
"publicHash": "<?php echo $block->escapeHtml($block->getData(TokenUiComponentProviderInterface::COMPONENT_PUBLIC_HASH)); ?>",
18+
"code": "<?php echo $block->escapeHtml($block->getData('code')); ?>",
19+
"nonceUrl": "<?php echo $block->escapeUrl($block->getData('nonceUrl')); ?>"
20+
}
21+
}' id="payment_<?php /* @noEscape */ echo $id;?>" class="admin__field">
22+
<div class="admin__field-control control">
23+
<input type="radio" id="token_switcher_<?php /* @noEscape */ echo $id; ?>" name="payment[token_switcher]"/>
24+
<img src="<?php echo $block->escapeUrl($icon['url']); ?>"
25+
width="<?php echo $block->escapeHtml($icon['width']); ?>"
26+
height="<?php echo $block->escapeHtml($icon['height']); ?>"
27+
class="payment-icon" >
28+
<span><?php echo $block->escapeHtml($details['payerEmail']); ?></span>
29+
</div>
30+
</div>

Diff for: app/code/Magento/Braintree/view/adminhtml/templates/form/vault.phtml

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ use Magento\Vault\Model\Ui\TokenUiComponentProviderInterface;
77
// @codingStandardsIgnoreFile
88

99
/** @var \Magento\Framework\View\Element\Template $block */
10-
$details = $block->getData('details');
10+
$details = $block->getData(TokenUiComponentProviderInterface::COMPONENT_DETAILS);
1111
$icon = $block->getData('icons')[$details['type']];
1212
$id = $block->escapeHtml($block->getData('id'));
1313
?>
1414
<div data-mage-init='{
1515
"Magento_Braintree/js/vault": {
1616
"container": "payment_<?php /* @noEscape */ echo $id; ?>",
1717
"publicHash": "<?php echo $block->escapeHtml($block->getData(TokenUiComponentProviderInterface::COMPONENT_PUBLIC_HASH)); ?>",
18+
"code": "<?php echo $block->escapeHtml($block->getData('code')); ?>",
1819
"nonceUrl": "<?php echo $block->escapeUrl($block->getData('nonceUrl')); ?>"
1920
}
2021
}' id="payment_<?php /* @noEscape */ echo $id;?>" class="admin__field">

0 commit comments

Comments
 (0)