-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #507 from magento-mpi/MPI-PR-PayPal
Bug - MAGETWO-59086 [GITHUB] Credit Card capture not associated with the Authorization since upgrade to 2.1.1 #6716 Story - MAGETWO-58251 PayPal Best Practice to Separate Saved Tokens - MAGETWO-59073 PayPal Team Comments After Demo: PayPal Vault Shown on Orders in Backend
- Loading branch information
Showing
34 changed files
with
864 additions
and
195 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
app/code/Magento/Braintree/Model/Ui/Adminhtml/PayPal/TokenUiComponentProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Braintree\Model\Ui\Adminhtml\PayPal; | ||
|
||
use Magento\Braintree\Gateway\Config\PayPal\Config; | ||
use Magento\Braintree\Model\Ui\ConfigProvider; | ||
use Magento\Braintree\Model\Ui\PayPal\ConfigProvider as PayPalConfigProvider; | ||
use Magento\Framework\UrlInterface; | ||
use Magento\Framework\View\Element\Template; | ||
use Magento\Vault\Api\Data\PaymentTokenInterface; | ||
use Magento\Vault\Model\Ui\TokenUiComponentInterfaceFactory; | ||
use Magento\Vault\Model\Ui\TokenUiComponentProviderInterface; | ||
|
||
/** | ||
* Gets Ui component configuration for Braintree PayPal Vault | ||
*/ | ||
class TokenUiComponentProvider implements TokenUiComponentProviderInterface | ||
{ | ||
|
||
/** | ||
* @var TokenUiComponentInterfaceFactory | ||
*/ | ||
private $componentFactory; | ||
|
||
/** | ||
* @var UrlInterface | ||
*/ | ||
private $urlBuilder; | ||
|
||
/** | ||
* @var Config | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* @param TokenUiComponentInterfaceFactory $componentFactory | ||
* @param UrlInterface $urlBuilder | ||
* @param Config $config | ||
*/ | ||
public function __construct( | ||
TokenUiComponentInterfaceFactory $componentFactory, | ||
UrlInterface $urlBuilder, | ||
Config $config | ||
) { | ||
$this->componentFactory = $componentFactory; | ||
$this->urlBuilder = $urlBuilder; | ||
$this->config = $config; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getComponentForToken(PaymentTokenInterface $paymentToken) | ||
{ | ||
$data = json_decode($paymentToken->getTokenDetails() ?: '{}', true); | ||
$data['icon'] = $this->config->getPayPalIcon(); | ||
$component = $this->componentFactory->create( | ||
[ | ||
'config' => [ | ||
'code' => PayPalConfigProvider::PAYPAL_VAULT_CODE, | ||
'nonceUrl' => $this->getNonceRetrieveUrl(), | ||
TokenUiComponentProviderInterface::COMPONENT_DETAILS => $data, | ||
TokenUiComponentProviderInterface::COMPONENT_PUBLIC_HASH => $paymentToken->getPublicHash(), | ||
'template' => 'Magento_Braintree::form/paypal/vault.phtml' | ||
], | ||
'name' => Template::class | ||
] | ||
); | ||
|
||
return $component; | ||
} | ||
|
||
/** | ||
* Get url to retrieve payment method nonce | ||
* @return string | ||
*/ | ||
private function getNonceRetrieveUrl() | ||
{ | ||
return $this->urlBuilder->getUrl(ConfigProvider::CODE . '/payment/getnonce', ['_secure' => true]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
...de/Magento/Braintree/Test/Unit/Model/Ui/Adminhtml/PayPal/TokenUiComponentProviderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Braintree\Test\Unit\Model\Ui\Adminhtml\PayPal; | ||
|
||
use Magento\Braintree\Gateway\Config\PayPal\Config; | ||
use Magento\Braintree\Model\Ui\Adminhtml\PayPal\TokenUiComponentProvider; | ||
use Magento\Framework\UrlInterface; | ||
use Magento\Vault\Api\Data\PaymentTokenInterface; | ||
use Magento\Vault\Model\Ui\TokenUiComponentInterface; | ||
use Magento\Vault\Model\Ui\TokenUiComponentInterfaceFactory; | ||
use PHPUnit_Framework_MockObject_MockObject as MockObject; | ||
|
||
/** | ||
* Contains methods to test PayPal token Ui component provider | ||
*/ | ||
class TokenUiComponentProviderTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var TokenUiComponentInterfaceFactory|MockObject | ||
*/ | ||
private $componentFactory; | ||
|
||
/** | ||
* @var UrlInterface|MockObject | ||
*/ | ||
private $urlBuilder; | ||
|
||
/** | ||
* @var Config|MockObject | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* @var TokenUiComponentProvider | ||
*/ | ||
private $tokenUiComponentProvider; | ||
|
||
protected function setUp() | ||
{ | ||
$this->componentFactory = $this->getMockBuilder(TokenUiComponentInterfaceFactory::class) | ||
->disableOriginalConstructor() | ||
->setMethods(['create']) | ||
->getMock(); | ||
|
||
$this->urlBuilder = $this->getMock(UrlInterface::class); | ||
|
||
$this->config = $this->getMockBuilder(Config::class) | ||
->disableOriginalConstructor() | ||
->setMethods(['getPayPalIcon']) | ||
->getMock(); | ||
|
||
$this->tokenUiComponentProvider = new TokenUiComponentProvider( | ||
$this->componentFactory, | ||
$this->urlBuilder, | ||
$this->config | ||
); | ||
} | ||
|
||
/** | ||
* @covers \Magento\Braintree\Model\Ui\Adminhtml\PayPal\TokenUiComponentProvider::getComponentForToken | ||
*/ | ||
public function testGetComponentForToken() | ||
{ | ||
$nonceUrl = 'https://payment/adminhtml/nonce/url'; | ||
$payerEmail = 'john.doe@test.com'; | ||
$icon = [ | ||
'url' => 'https://payment/adminhtml/icon.png', | ||
'width' => 48, | ||
'height' => 32 | ||
]; | ||
|
||
$expected = [ | ||
'code' => 'vault', | ||
'nonceUrl' => $nonceUrl, | ||
'details' => [ | ||
'payerEmail' => $payerEmail, | ||
'icon' => $icon | ||
], | ||
'template' => 'vault.phtml' | ||
]; | ||
|
||
$this->config->expects(static::once()) | ||
->method('getPayPalIcon') | ||
->willReturn($icon); | ||
|
||
$paymentToken = $this->getMock(PaymentTokenInterface::class); | ||
$paymentToken->expects(static::once()) | ||
->method('getTokenDetails') | ||
->willReturn('{"payerEmail":" ' . $payerEmail . '"}'); | ||
$paymentToken->expects(static::once()) | ||
->method('getPublicHash') | ||
->willReturn('cmk32dl21l'); | ||
|
||
$this->urlBuilder->expects(static::once()) | ||
->method('getUrl') | ||
->willReturn($nonceUrl); | ||
|
||
$tokenComponent = $this->getMock(TokenUiComponentInterface::class); | ||
$tokenComponent->expects(static::once()) | ||
->method('getConfig') | ||
->willReturn($expected); | ||
|
||
$this->componentFactory->expects(static::once()) | ||
->method('create') | ||
->willReturn($tokenComponent); | ||
|
||
$component = $this->tokenUiComponentProvider->getComponentForToken($paymentToken); | ||
static::assertEquals($tokenComponent, $component); | ||
static::assertEquals($expected, $component->getConfig()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
app/code/Magento/Braintree/view/adminhtml/templates/form/paypal/vault.phtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
use Magento\Vault\Model\Ui\TokenUiComponentProviderInterface; | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
// @codingStandardsIgnoreFile | ||
|
||
/** @var \Magento\Framework\View\Element\Template $block */ | ||
$details = $block->getData(TokenUiComponentProviderInterface::COMPONENT_DETAILS); | ||
$icon = $details['icon']; | ||
$id = $block->escapeHtml($block->getData('id')); | ||
?> | ||
<div data-mage-init='{ | ||
"Magento_Braintree/js/vault": { | ||
"container": "payment_<?php /* @noEscape */ echo $id; ?>", | ||
"publicHash": "<?php echo $block->escapeHtml($block->getData(TokenUiComponentProviderInterface::COMPONENT_PUBLIC_HASH)); ?>", | ||
"code": "<?php echo $block->escapeHtml($block->getData('code')); ?>", | ||
"nonceUrl": "<?php echo $block->escapeUrl($block->getData('nonceUrl')); ?>" | ||
} | ||
}' id="payment_<?php /* @noEscape */ echo $id;?>" class="admin__field"> | ||
<div class="admin__field-control control"> | ||
<input type="radio" id="token_switcher_<?php /* @noEscape */ echo $id; ?>" name="payment[token_switcher]"/> | ||
<img src="<?php echo $block->escapeUrl($icon['url']); ?>" | ||
width="<?php echo $block->escapeHtml($icon['width']); ?>" | ||
height="<?php echo $block->escapeHtml($icon['height']); ?>" | ||
class="payment-icon" > | ||
<span><?php echo $block->escapeHtml($details['payerEmail']); ?></span> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.