Skip to content

Commit

Permalink
Merge pull request #95 from magento-mpi/MAGETWO-53238
Browse files Browse the repository at this point in the history
[MPI] Bug Fixes
  • Loading branch information
dvoskoboinikov authored Jun 10, 2016
2 parents b7da986 + 1d409db commit a27a846
Show file tree
Hide file tree
Showing 77 changed files with 1,159 additions and 1,340 deletions.
35 changes: 29 additions & 6 deletions app/code/Magento/Braintree/Block/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
use Magento\Braintree\Gateway\Config\Config as GatewayConfig;
use Magento\Braintree\Model\Adminhtml\Source\CcType;
use Magento\Braintree\Model\Ui\ConfigProvider;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\View\Element\Template\Context;
use Magento\Payment\Block\Form\Cc;
use Magento\Payment\Helper\Data;
use Magento\Payment\Model\Config;
use Magento\Vault\Model\VaultPaymentInterface;

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

/**
* @var VaultPaymentInterface
* @var Data
*/
protected $vaultService;
private $paymentDataHelper;

/**
* @param Context $context
* @param Config $paymentConfig
* @param Quote $sessionQuote
* @param GatewayConfig $gatewayConfig
* @param CcType $ccType
* @param VaultPaymentInterface $vaultService
* @param array $data
*/
public function __construct(
Expand All @@ -55,14 +56,12 @@ public function __construct(
Quote $sessionQuote,
GatewayConfig $gatewayConfig,
CcType $ccType,
VaultPaymentInterface $vaultService,
array $data = []
) {
parent::__construct($context, $paymentConfig, $data);
$this->sessionQuote = $sessionQuote;
$this->gatewayConfig = $gatewayConfig;
$this->ccType = $ccType;
$this->vaultService = $vaultService;
}

/**
Expand Down Expand Up @@ -91,7 +90,9 @@ public function useCvv()
*/
public function isVaultEnabled()
{
return $this->vaultService->isActiveForPayment(ConfigProvider::CODE);
$storeId = $this->_storeManager->getStore()->getId();
$vaultPayment = $this->getVaultPayment();
return $vaultPayment->isActive($storeId);
}

/**
Expand Down Expand Up @@ -123,4 +124,26 @@ private function filterCardTypesForCountry(array $configCardTypes, $countryId)
}
return $filtered;
}

/**
* Get configured vault payment for Braintree
* @return VaultPaymentInterface
*/
private function getVaultPayment()
{
return $this->getPaymentDataHelper()->getMethodInstance(ConfigProvider::CC_VAULT_CODE);
}

/**
* Get payment data helper instance
* @return Data
* @deprecated
*/
private function getPaymentDataHelper()
{
if ($this->paymentDataHelper === null) {
$this->paymentDataHelper = ObjectManager::getInstance()->get(Data::class);
}
return $this->paymentDataHelper;
}
}
3 changes: 3 additions & 0 deletions app/code/Magento/Braintree/Model/Ui/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ final class ConfigProvider implements ConfigProviderInterface

const PAYPAL_CODE = 'braintree_paypal';

const CC_VAULT_CODE = 'braintree_cc_vault';

/**
* @var ResolverInterface
*/
Expand Down Expand Up @@ -88,6 +90,7 @@ public function getConfig()
'kountMerchantId' => $this->config->getKountMerchantId(),
'hasFraudProtection' => $this->config->hasFraudProtection(),
'merchantId' => $this->config->getMerchantId(),
'ccVaultCode' => static::CC_VAULT_CODE
],
Config::CODE_3DSECURE => [
'enabled' => $this->config->isVerify3DSecure(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function getComponentForToken(PaymentTokenInterface $paymentToken)
$component = $this->componentFactory->create(
[
'config' => [
'code' => ConfigProvider::CC_VAULT_CODE,
'nonceUrl' => $this->getNonceRetrieveUrl(),
TokenUiComponentProviderInterface::COMPONENT_DETAILS => $jsonDetails,
TokenUiComponentProviderInterface::COMPONENT_PUBLIC_HASH => $paymentToken->getPublicHash()
Expand Down
58 changes: 46 additions & 12 deletions app/code/Magento/Braintree/Test/Unit/Block/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
use Magento\Braintree\Model\Adminhtml\Source\CcType;
use Magento\Braintree\Model\Ui\ConfigProvider;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Payment\Helper\Data;
use Magento\Payment\Model\Config;
use Magento\Vault\Model\Ui\VaultConfigProvider;
use Magento\Store\Api\Data\StoreInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Vault\Model\VaultPaymentInterface;
use OAuthTest\Mocks\Common\Service\Mock;
use PHPUnit_Framework_MockObject_MockObject as MockObject;

/**
* Class FormTest
Expand All @@ -40,41 +44,52 @@ class FormTest extends \PHPUnit_Framework_TestCase
private $block;

/**
* @var Quote|\PHPUnit_Framework_MockObject_MockObject
* @var Quote|MockObject
*/
private $sessionQuote;

/**
* @var Config|\PHPUnit_Framework_MockObject_MockObject
* @var Config|MockObject
*/
private $gatewayConfig;

/**
* @var CcType|\PHPUnit_Framework_MockObject_MockObject
* @var CcType|MockObject
*/
private $ccType;

/**
* @var VaultPaymentInterface|\PHPUnit_Framework_MockObject_MockObject
* @var StoreManagerInterface|MockObject
*/
private $vaultService;
private $storeManager;

/**
* @var Data|MockObject
*/
private $paymentDataHelper;

protected function setUp()
{
$this->initCcTypeMock();
$this->initSessionQuoteMock();
$this->initGatewayConfigMock();

$this->vaultService = $this->getMock(VaultPaymentInterface::class);

$this->storeManager = $this->getMockForAbstractClass(StoreManagerInterface::class);
$this->paymentDataHelper = $this->getMockBuilder(Data::class)
->disableOriginalConstructor()
->setMethods(['getMethodInstance'])
->getMock();

$managerHelper = new ObjectManager($this);
$this->block = $managerHelper->getObject(Form::class, [
'paymentConfig' => $managerHelper->getObject(Config::class),
'sessionQuote' => $this->sessionQuote,
'gatewayConfig' => $this->gatewayConfig,
'ccType' => $this->ccType,
'vaultService' => $this->vaultService
'storeManager' => $this->storeManager
]);

$managerHelper->setBackwardCompatibleProperty($this->block, 'paymentDataHelper', $this->paymentDataHelper);
}

/**
Expand Down Expand Up @@ -117,11 +132,30 @@ public function countryCardTypesDataProvider()
];
}

/**
* @covers \Magento\Braintree\Block\Form::isVaultEnabled
*/
public function testIsVaultEnabled()
{
$this->vaultService->expects(static::once())
->method('isActiveForPayment')
->with(ConfigProvider::CODE)
$storeId = 1;
$store = $this->getMockForAbstractClass(StoreInterface::class);
$this->storeManager->expects(static::once())
->method('getStore')
->willReturn($store);

$store->expects(static::once())
->method('getId')
->willReturn($storeId);

$vaultPayment = $this->getMockForAbstractClass(VaultPaymentInterface::class);
$this->paymentDataHelper->expects(static::once())
->method('getMethodInstance')
->with(ConfigProvider::CC_VAULT_CODE)
->willReturn($vaultPayment);

$vaultPayment->expects(static::once())
->method('isActive')
->with($storeId)
->willReturn(true);

static::assertTrue($this->block->isVaultEnabled());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function getConfigDataProvider()
'getEnvironment' => 'test-environment',
'getKountMerchantId' => 'test-kount-merchant-id',
'getMerchantId' => 'test-merchant-id',
'hasFraudProtection' => true
'hasFraudProtection' => true,
],
'expected' => [
'payment' => [
Expand All @@ -167,7 +167,8 @@ public function getConfigDataProvider()
'environment' => 'test-environment',
'kountMerchantId' => 'test-kount-merchant-id',
'merchantId' => 'test-merchant-id',
'hasFraudProtection' => true
'hasFraudProtection' => true,
'ccVaultCode' => ConfigProvider::CC_VAULT_CODE
],
Config::CODE_3DSECURE => [
'enabled' => true,
Expand Down
7 changes: 0 additions & 7 deletions app/code/Magento/Braintree/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@
</arguments>
</type>

<type name="Magento\Vault\Model\Adminhtml\Source\VaultProvidersMap">
<arguments>
<argument name="options" xsi:type="array">
<item xsi:type="object" name="braintree">BraintreeFacade</item>
</argument>
</arguments>
</type>
<virtualType name="BraintreeAuthorizeDataBuilder" type="Magento\Payment\Gateway\Request\BuilderComposite">
<arguments>
<argument name="builders" xsi:type="array">
Expand Down
12 changes: 12 additions & 0 deletions app/code/Magento/Braintree/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
<group id="braintree_required"/>
</requires>
</field>
<field id="braintree_cc_vault_active" translate="label" type="select" sortOrder="12" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Vault enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/braintree_cc_vault/active</config_path>
<requires>
<group id="braintree_required"/>
</requires>
</field>
<group id="braintree_required" translate="label" showInDefault="1" showInWebsite="1" sortOrder="5">
<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>
<label>Basic Braintree Settings</label>
Expand Down Expand Up @@ -71,6 +79,10 @@
<group id="braintree_advanced" translate="label" showInDefault="1" showInWebsite="1" sortOrder="20">
<label>Advanced Braintree Settings</label>
<frontend_model>Magento\Config\Block\System\Config\Form\Fieldset</frontend_model>
<field id="braintree_cc_vault_title" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Vault Title</label>
<config_path>payment/braintree_cc_vault/title</config_path>
</field>
<field id="merchant_account_id" translate="label" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Merchant Account ID</label>
<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>
Expand Down
4 changes: 4 additions & 0 deletions app/code/Magento/Braintree/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
<privateInfoKeys>processorResponseCode,processorResponseText,paymentId</privateInfoKeys>
<paymentInfoKeys>processorResponseCode,processorResponseText,paymentId,payerEmail</paymentInfoKeys>
</braintree_paypal>
<braintree_cc_vault>
<model>BraintreeCreditCardVaultFacade</model>
<title>Stored Cards (Braintree)</title>
</braintree_cc_vault>
</payment>
</default>
</config>
26 changes: 26 additions & 0 deletions app/code/Magento/Braintree/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,32 @@
<argument name="commandPool" xsi:type="object">BraintreePayPalCommandPool</argument>
</arguments>
</virtualType>
<!-- Configuration for Braintree Vault payment -->
<virtualType name="BraintreeVaultPaymentConfig" type="Magento\Payment\Gateway\Config\Config">
<arguments>
<argument name="methodCode" xsi:type="const">Magento\Braintree\Model\Ui\ConfigProvider::CC_VAULT_CODE</argument>
</arguments>
</virtualType>
<virtualType name="BraintreeVaultPaymentValueHandler" type="VaultPaymentDefaultValueHandler">
<arguments>
<argument name="configInterface" xsi:type="object">BraintreeVaultPaymentConfig</argument>
</arguments>
</virtualType>
<virtualType name="BraintreeVaultPaymentValueHandlerPool" type="VaultPaymentValueHandlerPool">
<arguments>
<argument name="handlers" xsi:type="array">
<item name="default" xsi:type="string">BraintreeVaultPaymentValueHandler</item>
</argument>
</arguments>
</virtualType>
<virtualType name="BraintreeCreditCardVaultFacade" type="Magento\Vault\Model\Method\Vault">
<arguments>
<argument name="config" xsi:type="object">BraintreeVaultPaymentConfig</argument>
<argument name="valueHandlerPool" xsi:type="object">BraintreeVaultPaymentValueHandlerPool</argument>
<argument name="vaultProvider" xsi:type="object">BraintreeFacade</argument>
<argument name="code" xsi:type="const">Magento\Braintree\Model\Ui\ConfigProvider::CC_VAULT_CODE</argument>
</arguments>
</virtualType>

<!-- Configuration reader -->
<type name="Magento\Braintree\Gateway\Config\Config">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
<argument name="template" xsi:type="string">Magento_Braintree::form/cc.phtml</argument>
</action>
</referenceBlock>
<referenceBlock name="order_create_billing_form">
<action method="setMethodFormTemplate">
<argument name="method" xsi:type="string">braintree_cc_vault</argument>
<argument name="template" xsi:type="string">Magento_Vault::form/vault.phtml</argument>
</action>
</referenceBlock>
<referenceBlock name="content">
<block name="braintree_payment_script"
as="braintree_payment_script"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@
<argument name="template" xsi:type="string">Magento_Braintree::form/cc.phtml</argument>
</action>
</referenceBlock>
<referenceBlock name="order.create.billing.method.form">
<action method="setMethodFormTemplate">
<argument name="method" xsi:type="string">braintree_cc_vault</argument>
<argument name="template" xsi:type="string">Magento_Vault::form/vault.phtml</argument>
</action>
</referenceBlock>
</body>
</page>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ define([
'Magento_Braintree/js/validator',
'Magento_Vault/js/view/payment/vault-enabler',
'mage/translate'
], function ($, Component, validator, vaultEnabler, $t) {
], function ($, Component, validator, VaultEnabler, $t) {
'use strict';

return Component.extend({
Expand All @@ -33,8 +33,8 @@ define([
*/
initialize: function () {
this._super();
this.vaultEnabler = vaultEnabler();
this.vaultEnabler.setPaymentCode(this.getCode());
this.vaultEnabler = new VaultEnabler();
this.vaultEnabler.setPaymentCode(this.getVaultCode());

return this;
},
Expand Down Expand Up @@ -150,6 +150,13 @@ define([
if (this.validateCardType()) {
$(this.getSelector('submit')).trigger('click');
}
},

/**
* @returns {String}
*/
getVaultCode: function () {
return window.checkoutConfig.payment[this.getCode()].ccVaultCode;
}
});
});
Loading

0 comments on commit a27a846

Please sign in to comment.