Skip to content

Commit

Permalink
MAGETWO-56342: [Github] #5910 Braintree sandbox errors when using alt…
Browse files Browse the repository at this point in the history
…ernative Merchant Account ID
  • Loading branch information
Dmytro Yushkin committed Aug 15, 2016
2 parents 3f4746c + 90bcc85 commit 64536b2
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
10 changes: 10 additions & 0 deletions app/code/Magento/Braintree/Gateway/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,14 @@ public function getDynamicDescriptors()
}
return $values;
}

/**
* Get Merchant account ID
*
* @return string
*/
public function getMerchantAccountId()
{
return $this->getValue(self::KEY_MERCHANT_ACCOUNT_ID);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function build(array $buildSubject)
self::ORDER_ID => $order->getOrderIncrementId()
];

$merchantAccountId = $this->config->getValue(Config::KEY_MERCHANT_ACCOUNT_ID);
$merchantAccountId = $this->config->getMerchantAccountId();
if (!empty($merchantAccountId)) {
$result[self::MERCHANT_ACCOUNT_ID] = $merchantAccountId;
}
Expand Down
10 changes: 9 additions & 1 deletion app/code/Magento/Braintree/Model/Ui/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\Braintree\Model\Ui;

use Magento\Braintree\Gateway\Request\PaymentDataBuilder;
use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Braintree\Gateway\Config\Config;
use Magento\Braintree\Model\Adapter\BraintreeAdapter;
Expand Down Expand Up @@ -86,7 +87,14 @@ public function getConfig()
public function getClientToken()
{
if (empty($this->clientToken)) {
$this->clientToken = $this->adapter->generate();
$params = [];

$merchantAccountId = $this->config->getMerchantAccountId();
if (!empty($merchantAccountId)) {
$params[PaymentDataBuilder::MERCHANT_ACCOUNT_ID] = $merchantAccountId;
}

$this->clientToken = $this->adapter->generate($params);
}

return $this->clientToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ public function testBuild()
->willReturnMap($additionalData);

$this->configMock->expects(static::once())
->method('getValue')
->with(Config::KEY_MERCHANT_ACCOUNT_ID)
->method('getMerchantAccountId')
->willReturn(self::MERCHANT_ACCOUNT_ID);

$this->paymentDO->expects(static::once())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
class ConfigProviderTest extends \PHPUnit_Framework_TestCase
{
const SDK_URL = 'https://js.braintreegateway.com/v2/braintree.js';

const CLIENT_TOKEN = 'token';
const MERCHANT_ACCOUNT_ID = '245345';

/**
* @var Config|MockObject
Expand Down Expand Up @@ -76,11 +76,17 @@ public function testGetConfig($config, $expected)

/**
* @covers \Magento\Braintree\Model\Ui\ConfigProvider::getClientToken
* @dataProvider getClientTokenDataProvider
*/
public function testGetClientToken()
public function testGetClientToken($merchantAccountId, $params)
{
$this->config->expects(static::once())
->method('getMerchantAccountId')
->willReturn($merchantAccountId);

$this->braintreeAdapter->expects(static::once())
->method('generate')
->with($params)
->willReturn(self::CLIENT_TOKEN);

static::assertEquals(self::CLIENT_TOKEN, $this->configProvider->getClientToken());
Expand Down Expand Up @@ -140,4 +146,21 @@ public function getConfigDataProvider()
]
];
}

/**
* @return array
*/
public function getClientTokenDataProvider()
{
return [
[
'merchantAccountId' => '',
'params' => []
],
[
'merchantAccountId' => self::MERCHANT_ACCOUNT_ID,
'params' => ['merchantAccountId' => self::MERCHANT_ACCOUNT_ID]
]
];
}
}

0 comments on commit 64536b2

Please sign in to comment.