Skip to content

Commit 1e1eb19

Browse files
committed
MAGETWO-53281: Update BN Codes for Braintree/PayPal
1 parent 04795a6 commit 1e1eb19

File tree

6 files changed

+138
-2
lines changed

6 files changed

+138
-2
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Braintree\Gateway\Request;
7+
8+
use Magento\Payment\Gateway\Request\BuilderInterface;
9+
use Magento\Framework\App\ProductMetadataInterface;
10+
11+
/**
12+
* Class BnCodeDataBuilder
13+
*/
14+
class ChannelDataBuilder implements BuilderInterface
15+
{
16+
/**
17+
* @var ProductMetadataInterface
18+
*/
19+
private $productMetadata;
20+
21+
/**
22+
* @var string
23+
*/
24+
private static $channel = 'channel';
25+
26+
/**
27+
* @var string
28+
*/
29+
private static $channelValue = 'Magento2_Cart_%s_BT';
30+
31+
/**
32+
* Constructor
33+
*
34+
* @param ProductMetadataInterface $productMetadata
35+
*/
36+
public function __construct(ProductMetadataInterface $productMetadata)
37+
{
38+
$this->productMetadata = $productMetadata;
39+
}
40+
41+
/**
42+
* @inheritdoc
43+
*/
44+
public function build(array $buildSubject)
45+
{
46+
return [
47+
self::$channel => sprintf(self::$channelValue, $this->productMetadata->getEdition())
48+
];
49+
}
50+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Braintree\Test\Unit\Gateway\Request;
7+
use Magento\Braintree\Gateway\Request\ChannelDataBuilder;
8+
use Magento\Framework\App\ProductMetadataInterface;
9+
10+
/**
11+
* Class PaymentDataBuilderTest
12+
*
13+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
14+
*/
15+
class ChannelDataBuilderTest extends \PHPUnit_Framework_TestCase
16+
{
17+
/**
18+
* @var ProductMetadataInterface|\PHPUnit_Framework_MockObject_MockObject
19+
*/
20+
private $productMetadataMock;
21+
22+
/**
23+
* @var ChannelDataBuilder
24+
*/
25+
private $builder;
26+
27+
protected function setUp()
28+
{
29+
$this->productMetadataMock = $this->getMock(ProductMetadataInterface::class);
30+
$this->builder = new ChannelDataBuilder($this->productMetadataMock);
31+
}
32+
33+
/**
34+
* @param string $edition
35+
* @param array $expected
36+
* @covers ChannelDataBuilder::build
37+
* @dataProvider buildDataProvider
38+
*/
39+
public function testBuild($edition, array $expected)
40+
{
41+
$buildSubject = [];
42+
$this->productMetadataMock->expects(static::once())
43+
->method('getEdition')
44+
->willReturn($edition);
45+
46+
$this->assertEquals($expected, $this->builder->build($buildSubject));
47+
}
48+
49+
/**
50+
* Get list of variations for build test
51+
* @return array
52+
*/
53+
public function buildDataProvider()
54+
{
55+
return [
56+
['Community', ['channel' => 'Magento2_Cart_Community_BT']],
57+
['Enterprise', ['channel' => 'Magento2_Cart_Enterprise_BT']],
58+
];
59+
}
60+
}

app/code/Magento/Braintree/etc/adminhtml/di.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<argument name="builders" xsi:type="array">
3232
<item name="customer" xsi:type="string">Magento\Braintree\Gateway\Request\CustomerDataBuilder</item>
3333
<item name="payment" xsi:type="string">Magento\Braintree\Gateway\Request\PaymentDataBuilder</item>
34+
<item name="channel" xsi:type="string">Magento\Braintree\Gateway\Request\ChannelDataBuilder</item>
3435
<item name="address" xsi:type="string">Magento\Braintree\Gateway\Request\AddressDataBuilder</item>
3536
<item name="vault" xsi:type="string">Magento\Braintree\Gateway\Request\VaultDataBuilder</item>
3637
</argument>
@@ -41,6 +42,7 @@
4142
<argument name="builders" xsi:type="array">
4243
<item name="customer" xsi:type="string">Magento\Braintree\Gateway\Request\CustomerDataBuilder</item>
4344
<item name="payment" xsi:type="string">Magento\Braintree\Gateway\Request\PaymentDataBuilder</item>
45+
<item name="channel" xsi:type="string">Magento\Braintree\Gateway\Request\ChannelDataBuilder</item>
4446
<item name="address" xsi:type="string">Magento\Braintree\Gateway\Request\AddressDataBuilder</item>
4547
</argument>
4648
</arguments>

app/code/Magento/Braintree/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
<argument name="builders" xsi:type="array">
117117
<item name="customer" xsi:type="string">Magento\Braintree\Gateway\Request\CustomerDataBuilder</item>
118118
<item name="payment" xsi:type="string">Magento\Braintree\Gateway\Request\PaymentDataBuilder</item>
119+
<item name="channel" xsi:type="string">Magento\Braintree\Gateway\Request\ChannelDataBuilder</item>
119120
<item name="address" xsi:type="string">Magento\Braintree\Gateway\Request\AddressDataBuilder</item>
120121
<item name="vault" xsi:type="string">Magento\Braintree\Gateway\Request\VaultDataBuilder</item>
121122
<item name="3dsecure" xsi:type="string">Magento\Braintree\Gateway\Request\ThreeDSecureDataBuilder</item>
@@ -139,6 +140,7 @@
139140
<argument name="builders" xsi:type="array">
140141
<item name="customer" xsi:type="string">Magento\Braintree\Gateway\Request\CustomerDataBuilder</item>
141142
<item name="payment" xsi:type="string">Magento\Braintree\Gateway\Request\PaymentDataBuilder</item>
143+
<item name="channel" xsi:type="string">Magento\Braintree\Gateway\Request\ChannelDataBuilder</item>
142144
<item name="address" xsi:type="string">Magento\Braintree\Gateway\Request\AddressDataBuilder</item>
143145
<item name="3dsecure" xsi:type="string">Magento\Braintree\Gateway\Request\ThreeDSecureDataBuilder</item>
144146
<item name="kount" xsi:type="string">Magento\Braintree\Gateway\Request\KountPaymentDataBuilder</item>
@@ -158,6 +160,7 @@
158160
<argument name="builders" xsi:type="array">
159161
<item name="customer" xsi:type="string">Magento\Braintree\Gateway\Request\CustomerDataBuilder</item>
160162
<item name="payment" xsi:type="string">Magento\Braintree\Gateway\Request\PaymentDataBuilder</item>
163+
<item name="channel" xsi:type="string">Magento\Braintree\Gateway\Request\ChannelDataBuilder</item>
161164
</argument>
162165
</arguments>
163166
</virtualType>

app/code/Magento/Paypal/Model/AbstractConfig.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Paypal\Model;
77

8+
use Magento\Framework\App\ProductMetadataInterface;
89
use Magento\Payment\Model\Method\ConfigInterface;
910
use Magento\Payment\Model\MethodInterface;
1011
use Magento\Store\Model\ScopeInterface;
@@ -49,6 +50,11 @@ abstract class AbstractConfig implements ConfigInterface
4950
*/
5051
protected $pathPattern;
5152

53+
/**
54+
* @var ProductMetadataInterface
55+
*/
56+
private $productMetadata;
57+
5258
/**
5359
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
5460
*/
@@ -323,10 +329,25 @@ public function isMethodSupportedForCountry($method = null, $countryCode = null)
323329
*/
324330
public function getBuildNotationCode()
325331
{
326-
return $this->_scopeConfig->getValue(
332+
$bnCode = $this->_scopeConfig->getValue(
327333
'paypal/bncode',
328334
ScopeInterface::SCOPE_STORE,
329335
$this->_storeId
330336
);
337+
return sprintf($bnCode, $this->getProductMetadata()->getEdition());
338+
}
339+
340+
/**
341+
* The getter function to get the ProductMetadata
342+
*
343+
* @return ProductMetadataInterface
344+
* @deprecated
345+
*/
346+
protected function getProductMetadata()
347+
{
348+
if (!is_object($this->productMetadata)) {
349+
$this->productMetadata = ObjectManager::getInstance()->get(ProductMetadataInterface::class);
350+
}
351+
return $this->productMetadata;
331352
}
332353
}

app/code/Magento/Paypal/etc/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
99
<default>
1010
<paypal>
11-
<bncode>Magento_Cart_Community</bncode>
11+
<bncode>Magento_Cart_%s</bncode>
1212
<style>
1313
<logo></logo>
1414
</style>

0 commit comments

Comments
 (0)