Skip to content

Commit 8568cc9

Browse files
ENGCOM-6153: Braintree - Don't request ClientToken if payment method is not active magento#25223
2 parents cbef977 + d3b97ab commit 8568cc9

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

app/code/Magento/Braintree/Model/Ui/ConfigProvider.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,12 @@ public function __construct(
6767
public function getConfig()
6868
{
6969
$storeId = $this->session->getStoreId();
70+
$isActive = $this->config->isActive($storeId);
7071
return [
7172
'payment' => [
7273
self::CODE => [
73-
'isActive' => $this->config->isActive($storeId),
74-
'clientToken' => $this->getClientToken(),
74+
'isActive' => $isActive,
75+
'clientToken' => $isActive ? $this->getClientToken() : null,
7576
'ccTypesMapper' => $this->config->getCcTypesMapper(),
7677
'sdkUrl' => $this->config->getSdkUrl(),
7778
'hostedFieldsSdkUrl' => $this->config->getHostedFieldsSdkUrl(),

app/code/Magento/Braintree/Test/Unit/Model/Ui/ConfigProviderTest.php

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,30 +76,45 @@ protected function setUp()
7676
}
7777

7878
/**
79-
* Run test getConfig method
79+
* Ensure that get config returns correct data if payment is active or not
8080
*
8181
* @param array $config
8282
* @param array $expected
8383
* @dataProvider getConfigDataProvider
8484
*/
8585
public function testGetConfig($config, $expected)
8686
{
87-
$this->braintreeAdapter->expects(static::once())
88-
->method('generate')
89-
->willReturn(self::CLIENT_TOKEN);
87+
if ($config['isActive']) {
88+
$this->braintreeAdapter->expects($this->once())
89+
->method('generate')
90+
->willReturn(self::CLIENT_TOKEN);
91+
} else {
92+
$config = array_replace_recursive(
93+
$this->getConfigDataProvider()[0]['config'],
94+
$config
95+
);
96+
$expected = array_replace_recursive(
97+
$this->getConfigDataProvider()[0]['expected'],
98+
$expected
99+
);
100+
$this->braintreeAdapter->expects($this->never())
101+
->method('generate');
102+
}
90103

91104
foreach ($config as $method => $value) {
92-
$this->config->expects(static::once())
105+
$this->config->expects($this->once())
93106
->method($method)
94107
->willReturn($value);
95108
}
96109

97-
static::assertEquals($expected, $this->configProvider->getConfig());
110+
$this->assertEquals($expected, $this->configProvider->getConfig());
98111
}
99112

100113
/**
101-
* @covers \Magento\Braintree\Model\Ui\ConfigProvider::getClientToken
114+
* @covers \Magento\Braintree\Model\Ui\ConfigProvider::getClientToken
102115
* @dataProvider getClientTokenDataProvider
116+
* @param $merchantAccountId
117+
* @param $params
103118
*/
104119
public function testGetClientToken($merchantAccountId, $params)
105120
{
@@ -124,7 +139,7 @@ public function getConfigDataProvider()
124139
[
125140
'config' => [
126141
'isActive' => true,
127-
'getCcTypesMapper' => ['visa' => 'VI', 'american-express'=> 'AE'],
142+
'getCcTypesMapper' => ['visa' => 'VI', 'american-express' => 'AE'],
128143
'getSdkUrl' => self::SDK_URL,
129144
'getHostedFieldsSdkUrl' => 'https://sdk.com/test.js',
130145
'getCountrySpecificCardTypeConfig' => [
@@ -148,7 +163,7 @@ public function getConfigDataProvider()
148163
'ccTypesMapper' => ['visa' => 'VI', 'american-express' => 'AE'],
149164
'sdkUrl' => self::SDK_URL,
150165
'hostedFieldsSdkUrl' => 'https://sdk.com/test.js',
151-
'countrySpecificCardTypes' =>[
166+
'countrySpecificCardTypes' => [
152167
'GB' => ['VI', 'AE'],
153168
'US' => ['DI', 'JCB']
154169
],
@@ -166,6 +181,19 @@ public function getConfigDataProvider()
166181
]
167182
]
168183
]
184+
],
185+
[
186+
'config' => [
187+
'isActive' => false,
188+
],
189+
'expected' => [
190+
'payment' => [
191+
ConfigProvider::CODE => [
192+
'isActive' => false,
193+
'clientToken' => null,
194+
]
195+
]
196+
]
169197
]
170198
];
171199
}

0 commit comments

Comments
 (0)