Skip to content

Commit b7da986

Browse files
author
Oleksii Korshenko
committed
Merge pull request #94 from magento-mpi/MPI-BUGFIXES
[MPI] Bugfixes
2 parents a2a87c1 + d13608e commit b7da986

File tree

16 files changed

+293
-29
lines changed

16 files changed

+293
-29
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: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
8+
use Magento\Braintree\Gateway\Request\ChannelDataBuilder;
9+
use Magento\Framework\App\ProductMetadataInterface;
10+
11+
/**
12+
* Class PaymentDataBuilderTest
13+
*
14+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
15+
*/
16+
class ChannelDataBuilderTest extends \PHPUnit_Framework_TestCase
17+
{
18+
/**
19+
* @var ProductMetadataInterface|\PHPUnit_Framework_MockObject_MockObject
20+
*/
21+
private $productMetadataMock;
22+
23+
/**
24+
* @var ChannelDataBuilder
25+
*/
26+
private $builder;
27+
28+
protected function setUp()
29+
{
30+
$this->productMetadataMock = $this->getMock(ProductMetadataInterface::class);
31+
$this->builder = new ChannelDataBuilder($this->productMetadataMock);
32+
}
33+
34+
/**
35+
* @param string $edition
36+
* @param array $expected
37+
* @covers \Magento\Braintree\Gateway\Request\ChannelDataBuilder::build
38+
* @dataProvider buildDataProvider
39+
*/
40+
public function testBuild($edition, array $expected)
41+
{
42+
$buildSubject = [];
43+
$this->productMetadataMock->expects(static::once())
44+
->method('getEdition')
45+
->willReturn($edition);
46+
47+
$this->assertEquals($expected, $this->builder->build($buildSubject));
48+
}
49+
50+
/**
51+
* Get list of variations for build test
52+
* @return array
53+
*/
54+
public function buildDataProvider()
55+
{
56+
return [
57+
['FirstEdition', ['channel' => 'Magento2_Cart_FirstEdition_BT']],
58+
['SecondEdition', ['channel' => 'Magento2_Cart_SecondEdition_BT']],
59+
];
60+
}
61+
}

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/OfflineShipping/Model/ResourceModel/Carrier/Tablerate/RateQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function prepareSelect(\Magento\Framework\DB\Select $select)
3232
$select->where(
3333
'website_id = :website_id'
3434
)->order(
35-
['dest_country_id DESC', 'dest_region_id DESC', 'dest_zip DESC']
35+
['dest_country_id DESC', 'dest_region_id DESC', 'dest_zip DESC', 'condition_value DESC']
3636
)->limit(
3737
1
3838
);

app/code/Magento/Payment/Model/Method/Cc.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55
*/
66
namespace Magento\Payment\Model\Method;
77

8+
use Magento\Framework\DataObject;
9+
use Magento\Quote\Api\Data\PaymentInterface;
10+
use Magento\Quote\Model\Quote\Payment;
11+
812
/**
913
* @method \Magento\Quote\Api\Data\PaymentMethodExtensionInterface getExtensionAttributes()
1014
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
15+
* @deprecated
1116
*/
1217
class Cc extends \Magento\Payment\Model\Method\AbstractMethod
1318
{
@@ -237,6 +242,40 @@ protected function _validateExpDate($expYear, $expMonth)
237242
return true;
238243
}
239244

245+
/**
246+
* Assign data to info model instance
247+
*
248+
* @param \Magento\Framework\DataObject|mixed $data
249+
* @return $this
250+
* @throws \Magento\Framework\Exception\LocalizedException
251+
*/
252+
public function assignData(\Magento\Framework\DataObject $data)
253+
{
254+
$additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
255+
if (!is_object($additionalData)) {
256+
$additionalData = new DataObject($additionalData ?: []);
257+
}
258+
259+
/** @var DataObject $info */
260+
$info = $this->getInfoInstance();
261+
$info->addData(
262+
[
263+
'cc_type' => $additionalData->getCcType(),
264+
'cc_owner' => $additionalData->getCcOwner(),
265+
'cc_last_4' => substr($additionalData->getCcNumber(), -4),
266+
'cc_number' => $additionalData->getCcNumber(),
267+
'cc_cid' => $additionalData->getCcCid(),
268+
'cc_exp_month' => $additionalData->getCcExpMonth(),
269+
'cc_exp_year' => $additionalData->getCcExpYear(),
270+
'cc_ss_issue' => $additionalData->getCcSsIssue(),
271+
'cc_ss_start_month' => $additionalData->getCcSsStartMonth(),
272+
'cc_ss_start_year' => $additionalData->getCcSsStartYear()
273+
]
274+
);
275+
276+
return $this;
277+
}
278+
240279
/**
241280
* @param string $type
242281
* @return bool
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Payment\Test\Unit\Model\Method;
7+
8+
use Magento\Framework\DataObject;
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10+
use Magento\Payment\Model\Method\Cc;
11+
use Magento\Quote\Api\Data\PaymentInterface;
12+
use Magento\Quote\Model\Quote\Payment;
13+
14+
class CcTest extends \PHPUnit_Framework_TestCase
15+
{
16+
/**
17+
* @var Cc
18+
*/
19+
private $ccModel;
20+
21+
public function setUp()
22+
{
23+
$objectManager = new ObjectManager($this);
24+
$this->ccModel = $objectManager->getObject(Cc::class);
25+
}
26+
27+
public function testAssignData()
28+
{
29+
$additionalData = [
30+
'cc_type' => 'VI',
31+
'cc_owner' => 'Bruce',
32+
'cc_number' => '41111111111111',
33+
'cc_cid' => '42',
34+
'cc_exp_month' => '02',
35+
'cc_exp_year' => '30',
36+
'cc_ss_issue' => '9',
37+
'cc_ss_start_month' => '01',
38+
'cc_ss_start_year' => '30'
39+
];
40+
41+
$inputData = new DataObject(
42+
[
43+
PaymentInterface::KEY_ADDITIONAL_DATA => $additionalData
44+
]
45+
);
46+
47+
$payment = $this->getMockBuilder(Payment::class)
48+
->disableOriginalConstructor()
49+
->getMock();
50+
51+
$expectedData = [
52+
'cc_type' => 'VI',
53+
'cc_owner' => 'Bruce',
54+
'cc_last_4' => '1111',
55+
'cc_number' => '41111111111111',
56+
'cc_cid' => '42',
57+
'cc_exp_month' => '02',
58+
'cc_exp_year' => '30',
59+
'cc_ss_issue' => '9',
60+
'cc_ss_start_month' => '01',
61+
'cc_ss_start_year' => '30'
62+
];
63+
64+
$payment->expects(static::once())
65+
->method('addData')
66+
->with(
67+
$expectedData
68+
);
69+
70+
$this->ccModel->setInfoInstance($payment);
71+
$this->ccModel->assignData($inputData);
72+
}
73+
}

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

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
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;
1112
use Magento\Paypal\Model\Config;
13+
use Magento\Framework\App\ObjectManager;
1214

1315
/**
1416
* Class AbstractConfig
@@ -49,6 +51,16 @@ abstract class AbstractConfig implements ConfigInterface
4951
*/
5052
protected $pathPattern;
5153

54+
/**
55+
* @var ProductMetadataInterface
56+
*/
57+
protected $productMetadata;
58+
59+
/**
60+
* @var string
61+
*/
62+
private static $bnCode = 'Magento_Cart_%s';
63+
5264
/**
5365
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
5466
*/
@@ -323,10 +335,20 @@ public function isMethodSupportedForCountry($method = null, $countryCode = null)
323335
*/
324336
public function getBuildNotationCode()
325337
{
326-
return $this->_scopeConfig->getValue(
327-
'paypal/bncode',
328-
ScopeInterface::SCOPE_STORE,
329-
$this->_storeId
330-
);
338+
return sprintf(self::$bnCode, $this->getProductMetadata()->getEdition());
339+
}
340+
341+
/**
342+
* The getter function to get the ProductMetadata
343+
*
344+
* @return ProductMetadataInterface
345+
* @deprecated
346+
*/
347+
protected function getProductMetadata()
348+
{
349+
if ($this->productMetadata === null) {
350+
$this->productMetadata = ObjectManager::getInstance()->get(ProductMetadataInterface::class);
351+
}
352+
return $this->productMetadata;
331353
}
332354
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ public function buildBasicRequest()
623623
$request->setPartner($this->getConfigData('partner'));
624624
$request->setPwd($this->getConfigData('pwd'));
625625
$request->setVerbosity($this->getConfigData('verbosity'));
626-
$request->setData('BNCODE', $config->getBuildNotationCode());
626+
$request->setData('BUTTONSOURCE', $config->getBuildNotationCode());
627627
$request->setTender(self::TENDER_CC);
628628

629629
return $request;

app/code/Magento/Paypal/Test/Unit/Model/AbstractConfigTest.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Magento\Framework\App\Config\ScopeConfigInterface;
99
use Magento\Store\Model\ScopeInterface as ModelScopeInterface;
1010
use Magento\Payment\Model\MethodInterface;
11+
use Magento\Framework\App\ProductMetadataInterface;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1113

1214
/**
1315
* Class AbstractConfigTest
@@ -290,10 +292,18 @@ public function testIsMethodActive()
290292

291293
public function testGetBuildNotationCode()
292294
{
293-
$this->scopeConfigMock->expects($this->once())
294-
->method('getValue')
295-
->with('paypal/bncode');
295+
$productMetadata = $this->getMock(ProductMetadataInterface::class, [], [], '', false);
296+
$productMetadata->expects($this->once())
297+
->method('getEdition')
298+
->will($this->returnValue('SomeEdition'));
299+
300+
$objectManagerHelper = new ObjectManagerHelper($this);
301+
$objectManagerHelper->setBackwardCompatibleProperty(
302+
$this->config,
303+
'productMetadata',
304+
$productMetadata
305+
);
296306

297-
$this->config->getBuildNotationCode();
307+
$this->assertEquals('Magento_Cart_SomeEdition', $this->config->getBuildNotationCode());
298308
}
299309
}

0 commit comments

Comments
 (0)