Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAGETWO-47615: Display Vault Tokens in Account on Storefront
- Displayed tokens for BraintreeTwo
- Loading branch information
1 parent
a7e1b50
commit e511f1b
Showing
21 changed files
with
732 additions
and
122 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
app/code/Magento/BraintreeTwo/Block/Customer/CardRenderer.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,96 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\BraintreeTwo\Block\Customer; | ||
|
||
use Magento\BraintreeTwo\Model\Ui\ConfigProvider; | ||
use Magento\Framework\View\Element\Template; | ||
use Magento\Payment\Model\CcConfigProvider; | ||
use Magento\Vault\Api\Data\PaymentTokenInterface; | ||
use Magento\Vault\Block\TokenRendererInterface; | ||
|
||
class CardRenderer extends Template implements TokenRendererInterface | ||
{ | ||
/** | ||
* @var PaymentTokenInterface|null | ||
*/ | ||
private $token; | ||
|
||
/** | ||
* @var CcConfigProvider | ||
*/ | ||
private $iconsProvider; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param Template\Context $context | ||
* @param CcConfigProvider $iconsProvider | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Template\Context $context, | ||
CcConfigProvider $iconsProvider, | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $data); | ||
$this->iconsProvider = $iconsProvider; | ||
} | ||
|
||
/** | ||
* Can render specified token | ||
* | ||
* @param PaymentTokenInterface $token | ||
* @return boolean | ||
*/ | ||
public function canRender(PaymentTokenInterface $token) | ||
{ | ||
return $token->getPaymentMethodCode() === ConfigProvider::CODE; | ||
} | ||
|
||
/** | ||
* Renders specified token | ||
* | ||
* @param PaymentTokenInterface $token | ||
* @return string | ||
*/ | ||
public function render(PaymentTokenInterface $token) | ||
{ | ||
$this->token = $token; | ||
$result = $this->toHtml(); | ||
$this->token = null; | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @return PaymentTokenInterface|null | ||
*/ | ||
public function getToken() | ||
{ | ||
return $this->token; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getTokenDetails() | ||
{ | ||
return json_decode($this->getToken()->getTokenDetails() ?: '{}', true); | ||
} | ||
|
||
/** | ||
* @param string $type | ||
* @return array|null | ||
*/ | ||
public function getIconForType($type) | ||
{ | ||
if (isset($this->iconsProvider->getIcons()[$type])) { | ||
return $this->iconsProvider->getIcons()[$type]; | ||
} | ||
|
||
return null; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
app/code/Magento/BraintreeTwo/view/frontend/layout/vault_cards_listaction.xml
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,16 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> | ||
<body> | ||
<referenceContainer name="content"> | ||
<referenceBlock name="vault.cards.list"> | ||
<block class="Magento\BraintreeTwo\Block\Customer\CardRenderer" name="braintree.card.renderer" template="customer_account/credit_card.phtml"/> | ||
</referenceBlock> | ||
</referenceContainer> | ||
</body> | ||
</page> |
44 changes: 44 additions & 0 deletions
44
app/code/Magento/BraintreeTwo/view/frontend/templates/customer_account/credit_card.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,44 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
use Magento\BraintreeTwo\Block\Customer\CardRenderer; | ||
use Magento\Vault\Api\Data\PaymentTokenInterface; | ||
|
||
/** @var CardRenderer $block */ | ||
$details = $block->getTokenDetails(); | ||
$icon = $block->getIconForType($details['type']); | ||
?> | ||
<div class="payment-method"> | ||
<form class="form" action="<?php /* @noEscape */ echo $block->getUrl('vault/cards/deleteaction') ?>" method="post"> | ||
<?php echo $block->getBlockHtml('formkey')?> | ||
<input | ||
name="<?php echo /* @noEscape */ PaymentTokenInterface::PUBLIC_HASH?>" | ||
value="<?php echo /* @noEscape */ $block->getToken()->getPublicHash()?>" | ||
type="hidden"/> | ||
<div class="payment-method-title field"> | ||
<label class="label"> | ||
<img src="<?php echo $block->escapeUrl($icon['url']); ?>" | ||
width="<?php echo $block->escapeHtml($icon['width']); ?>" | ||
height="<?php echo $block->escapeHtml($icon['height']); ?>" | ||
> | ||
<span><?php echo $block->escapeHtml(__('ending'));?></span> | ||
<span><?php echo $block->escapeHtml($details['maskedCC']); ?></span> | ||
<span><?php echo $block->escapeHtml(__('expires'));?></span>: | ||
<span><?php echo $block->escapeHtml($details['expirationDate']); ?></span> | ||
</label> | ||
</div> | ||
<div class="actions-toolbar"> | ||
<div class="primary"> | ||
<button | ||
type="submit" | ||
class="action delete primary" | ||
title="<?php /* @noEscape */ echo __('Delete') ?>"> | ||
<span><?php /* @noEscape */ echo __('Delete') ?></span> | ||
</button> | ||
</div> | ||
</div> | ||
</form> | ||
</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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Vault\Block; | ||
|
||
use Magento\Customer\Model\Session; | ||
use Magento\Framework\View\Element\Template; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
use Magento\Vault\Api\Data\PaymentTokenInterface; | ||
use Magento\Vault\Model\CustomerTokenManagement; | ||
|
||
class CreditCards extends Template | ||
{ | ||
/** | ||
* @var CustomerTokenManagement | ||
*/ | ||
private $customerTokenManagement; | ||
|
||
/** | ||
* CreditCards constructor. | ||
* @param Template\Context $context | ||
* @param CustomerTokenManagement $customerTokenManagement | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Template\Context $context, | ||
CustomerTokenManagement $customerTokenManagement, | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $data); | ||
$this->customerTokenManagement = $customerTokenManagement; | ||
} | ||
|
||
/** | ||
* @return PaymentTokenInterface[] | ||
*/ | ||
public function getPaymentTokens() | ||
{ | ||
return $this->customerTokenManagement->getCustomerSessionTokens(); | ||
} | ||
|
||
/** | ||
* @param PaymentTokenInterface $token | ||
* @return string | ||
*/ | ||
public function renderTokenHtml(PaymentTokenInterface $token) | ||
{ | ||
foreach ($this->getChildNames() as $childName) { | ||
$childBlock = $this->getChildBlock($childName); | ||
if ($childBlock instanceof TokenRendererInterface && $childBlock->canRender($token)) { | ||
return $childBlock->render($token); | ||
} | ||
} | ||
|
||
return ''; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Vault\Block; | ||
|
||
use Magento\Vault\Api\Data\PaymentTokenInterface; | ||
|
||
/** | ||
* Interface TokenRendererInterface | ||
* @api | ||
*/ | ||
interface TokenRendererInterface | ||
{ | ||
/** | ||
* Can render specified token | ||
* | ||
* @param PaymentTokenInterface $token | ||
* @return boolean | ||
*/ | ||
public function canRender(PaymentTokenInterface $token); | ||
|
||
/** | ||
* Renders specified token | ||
* | ||
* @param PaymentTokenInterface $token | ||
* @return string | ||
*/ | ||
public function render(PaymentTokenInterface $token); | ||
} |
Oops, something went wrong.