Skip to content

Commit

Permalink
Merge pull request #94 from magento-mpi/MPI-BUGFIXES
Browse files Browse the repository at this point in the history
[MPI] Bugfixes
  • Loading branch information
Oleksii Korshenko committed Jun 9, 2016
2 parents a2a87c1 + d13608e commit b7da986
Show file tree
Hide file tree
Showing 16 changed files with 293 additions and 29 deletions.
50 changes: 50 additions & 0 deletions app/code/Magento/Braintree/Gateway/Request/ChannelDataBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Braintree\Gateway\Request;

use Magento\Payment\Gateway\Request\BuilderInterface;
use Magento\Framework\App\ProductMetadataInterface;

/**
* Class BnCodeDataBuilder
*/
class ChannelDataBuilder implements BuilderInterface
{
/**
* @var ProductMetadataInterface
*/
private $productMetadata;

/**
* @var string
*/
private static $channel = 'channel';

/**
* @var string
*/
private static $channelValue = 'Magento2_Cart_%s_BT';

/**
* Constructor
*
* @param ProductMetadataInterface $productMetadata
*/
public function __construct(ProductMetadataInterface $productMetadata)
{
$this->productMetadata = $productMetadata;
}

/**
* @inheritdoc
*/
public function build(array $buildSubject)
{
return [
self::$channel => sprintf(self::$channelValue, $this->productMetadata->getEdition())
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Braintree\Test\Unit\Gateway\Request;

use Magento\Braintree\Gateway\Request\ChannelDataBuilder;
use Magento\Framework\App\ProductMetadataInterface;

/**
* Class PaymentDataBuilderTest
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class ChannelDataBuilderTest extends \PHPUnit_Framework_TestCase
{
/**
* @var ProductMetadataInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $productMetadataMock;

/**
* @var ChannelDataBuilder
*/
private $builder;

protected function setUp()
{
$this->productMetadataMock = $this->getMock(ProductMetadataInterface::class);
$this->builder = new ChannelDataBuilder($this->productMetadataMock);
}

/**
* @param string $edition
* @param array $expected
* @covers \Magento\Braintree\Gateway\Request\ChannelDataBuilder::build
* @dataProvider buildDataProvider
*/
public function testBuild($edition, array $expected)
{
$buildSubject = [];
$this->productMetadataMock->expects(static::once())
->method('getEdition')
->willReturn($edition);

$this->assertEquals($expected, $this->builder->build($buildSubject));
}

/**
* Get list of variations for build test
* @return array
*/
public function buildDataProvider()
{
return [
['FirstEdition', ['channel' => 'Magento2_Cart_FirstEdition_BT']],
['SecondEdition', ['channel' => 'Magento2_Cart_SecondEdition_BT']],
];
}
}
2 changes: 2 additions & 0 deletions app/code/Magento/Braintree/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<argument name="builders" xsi:type="array">
<item name="customer" xsi:type="string">Magento\Braintree\Gateway\Request\CustomerDataBuilder</item>
<item name="payment" xsi:type="string">Magento\Braintree\Gateway\Request\PaymentDataBuilder</item>
<item name="channel" xsi:type="string">Magento\Braintree\Gateway\Request\ChannelDataBuilder</item>
<item name="address" xsi:type="string">Magento\Braintree\Gateway\Request\AddressDataBuilder</item>
<item name="vault" xsi:type="string">Magento\Braintree\Gateway\Request\VaultDataBuilder</item>
</argument>
Expand All @@ -41,6 +42,7 @@
<argument name="builders" xsi:type="array">
<item name="customer" xsi:type="string">Magento\Braintree\Gateway\Request\CustomerDataBuilder</item>
<item name="payment" xsi:type="string">Magento\Braintree\Gateway\Request\PaymentDataBuilder</item>
<item name="channel" xsi:type="string">Magento\Braintree\Gateway\Request\ChannelDataBuilder</item>
<item name="address" xsi:type="string">Magento\Braintree\Gateway\Request\AddressDataBuilder</item>
</argument>
</arguments>
Expand Down
3 changes: 3 additions & 0 deletions app/code/Magento/Braintree/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
<argument name="builders" xsi:type="array">
<item name="customer" xsi:type="string">Magento\Braintree\Gateway\Request\CustomerDataBuilder</item>
<item name="payment" xsi:type="string">Magento\Braintree\Gateway\Request\PaymentDataBuilder</item>
<item name="channel" xsi:type="string">Magento\Braintree\Gateway\Request\ChannelDataBuilder</item>
<item name="address" xsi:type="string">Magento\Braintree\Gateway\Request\AddressDataBuilder</item>
<item name="vault" xsi:type="string">Magento\Braintree\Gateway\Request\VaultDataBuilder</item>
<item name="3dsecure" xsi:type="string">Magento\Braintree\Gateway\Request\ThreeDSecureDataBuilder</item>
Expand All @@ -139,6 +140,7 @@
<argument name="builders" xsi:type="array">
<item name="customer" xsi:type="string">Magento\Braintree\Gateway\Request\CustomerDataBuilder</item>
<item name="payment" xsi:type="string">Magento\Braintree\Gateway\Request\PaymentDataBuilder</item>
<item name="channel" xsi:type="string">Magento\Braintree\Gateway\Request\ChannelDataBuilder</item>
<item name="address" xsi:type="string">Magento\Braintree\Gateway\Request\AddressDataBuilder</item>
<item name="3dsecure" xsi:type="string">Magento\Braintree\Gateway\Request\ThreeDSecureDataBuilder</item>
<item name="kount" xsi:type="string">Magento\Braintree\Gateway\Request\KountPaymentDataBuilder</item>
Expand All @@ -158,6 +160,7 @@
<argument name="builders" xsi:type="array">
<item name="customer" xsi:type="string">Magento\Braintree\Gateway\Request\CustomerDataBuilder</item>
<item name="payment" xsi:type="string">Magento\Braintree\Gateway\Request\PaymentDataBuilder</item>
<item name="channel" xsi:type="string">Magento\Braintree\Gateway\Request\ChannelDataBuilder</item>
</argument>
</arguments>
</virtualType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function prepareSelect(\Magento\Framework\DB\Select $select)
$select->where(
'website_id = :website_id'
)->order(
['dest_country_id DESC', 'dest_region_id DESC', 'dest_zip DESC']
['dest_country_id DESC', 'dest_region_id DESC', 'dest_zip DESC', 'condition_value DESC']
)->limit(
1
);
Expand Down
39 changes: 39 additions & 0 deletions app/code/Magento/Payment/Model/Method/Cc.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
*/
namespace Magento\Payment\Model\Method;

use Magento\Framework\DataObject;
use Magento\Quote\Api\Data\PaymentInterface;
use Magento\Quote\Model\Quote\Payment;

/**
* @method \Magento\Quote\Api\Data\PaymentMethodExtensionInterface getExtensionAttributes()
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @deprecated
*/
class Cc extends \Magento\Payment\Model\Method\AbstractMethod
{
Expand Down Expand Up @@ -237,6 +242,40 @@ protected function _validateExpDate($expYear, $expMonth)
return true;
}

/**
* Assign data to info model instance
*
* @param \Magento\Framework\DataObject|mixed $data
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function assignData(\Magento\Framework\DataObject $data)
{
$additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
if (!is_object($additionalData)) {
$additionalData = new DataObject($additionalData ?: []);
}

/** @var DataObject $info */
$info = $this->getInfoInstance();
$info->addData(
[
'cc_type' => $additionalData->getCcType(),
'cc_owner' => $additionalData->getCcOwner(),
'cc_last_4' => substr($additionalData->getCcNumber(), -4),
'cc_number' => $additionalData->getCcNumber(),
'cc_cid' => $additionalData->getCcCid(),
'cc_exp_month' => $additionalData->getCcExpMonth(),
'cc_exp_year' => $additionalData->getCcExpYear(),
'cc_ss_issue' => $additionalData->getCcSsIssue(),
'cc_ss_start_month' => $additionalData->getCcSsStartMonth(),
'cc_ss_start_year' => $additionalData->getCcSsStartYear()
]
);

return $this;
}

/**
* @param string $type
* @return bool
Expand Down
73 changes: 73 additions & 0 deletions app/code/Magento/Payment/Test/Unit/Model/Method/CcTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Payment\Test\Unit\Model\Method;

use Magento\Framework\DataObject;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Payment\Model\Method\Cc;
use Magento\Quote\Api\Data\PaymentInterface;
use Magento\Quote\Model\Quote\Payment;

class CcTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Cc
*/
private $ccModel;

public function setUp()
{
$objectManager = new ObjectManager($this);
$this->ccModel = $objectManager->getObject(Cc::class);
}

public function testAssignData()
{
$additionalData = [
'cc_type' => 'VI',
'cc_owner' => 'Bruce',
'cc_number' => '41111111111111',
'cc_cid' => '42',
'cc_exp_month' => '02',
'cc_exp_year' => '30',
'cc_ss_issue' => '9',
'cc_ss_start_month' => '01',
'cc_ss_start_year' => '30'
];

$inputData = new DataObject(
[
PaymentInterface::KEY_ADDITIONAL_DATA => $additionalData
]
);

$payment = $this->getMockBuilder(Payment::class)
->disableOriginalConstructor()
->getMock();

$expectedData = [
'cc_type' => 'VI',
'cc_owner' => 'Bruce',
'cc_last_4' => '1111',
'cc_number' => '41111111111111',
'cc_cid' => '42',
'cc_exp_month' => '02',
'cc_exp_year' => '30',
'cc_ss_issue' => '9',
'cc_ss_start_month' => '01',
'cc_ss_start_year' => '30'
];

$payment->expects(static::once())
->method('addData')
->with(
$expectedData
);

$this->ccModel->setInfoInstance($payment);
$this->ccModel->assignData($inputData);
}
}
32 changes: 27 additions & 5 deletions app/code/Magento/Paypal/Model/AbstractConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
*/
namespace Magento\Paypal\Model;

use Magento\Framework\App\ProductMetadataInterface;
use Magento\Payment\Model\Method\ConfigInterface;
use Magento\Payment\Model\MethodInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Paypal\Model\Config;
use Magento\Framework\App\ObjectManager;

/**
* Class AbstractConfig
Expand Down Expand Up @@ -49,6 +51,16 @@ abstract class AbstractConfig implements ConfigInterface
*/
protected $pathPattern;

/**
* @var ProductMetadataInterface
*/
protected $productMetadata;

/**
* @var string
*/
private static $bnCode = 'Magento_Cart_%s';

/**
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
*/
Expand Down Expand Up @@ -323,10 +335,20 @@ public function isMethodSupportedForCountry($method = null, $countryCode = null)
*/
public function getBuildNotationCode()
{
return $this->_scopeConfig->getValue(
'paypal/bncode',
ScopeInterface::SCOPE_STORE,
$this->_storeId
);
return sprintf(self::$bnCode, $this->getProductMetadata()->getEdition());
}

/**
* The getter function to get the ProductMetadata
*
* @return ProductMetadataInterface
* @deprecated
*/
protected function getProductMetadata()
{
if ($this->productMetadata === null) {
$this->productMetadata = ObjectManager::getInstance()->get(ProductMetadataInterface::class);
}
return $this->productMetadata;
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Paypal/Model/Payflowpro.php
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ public function buildBasicRequest()
$request->setPartner($this->getConfigData('partner'));
$request->setPwd($this->getConfigData('pwd'));
$request->setVerbosity($this->getConfigData('verbosity'));
$request->setData('BNCODE', $config->getBuildNotationCode());
$request->setData('BUTTONSOURCE', $config->getBuildNotationCode());
$request->setTender(self::TENDER_CC);

return $request;
Expand Down
18 changes: 14 additions & 4 deletions app/code/Magento/Paypal/Test/Unit/Model/AbstractConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface as ModelScopeInterface;
use Magento\Payment\Model\MethodInterface;
use Magento\Framework\App\ProductMetadataInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;

/**
* Class AbstractConfigTest
Expand Down Expand Up @@ -290,10 +292,18 @@ public function testIsMethodActive()

public function testGetBuildNotationCode()
{
$this->scopeConfigMock->expects($this->once())
->method('getValue')
->with('paypal/bncode');
$productMetadata = $this->getMock(ProductMetadataInterface::class, [], [], '', false);
$productMetadata->expects($this->once())
->method('getEdition')
->will($this->returnValue('SomeEdition'));

$objectManagerHelper = new ObjectManagerHelper($this);
$objectManagerHelper->setBackwardCompatibleProperty(
$this->config,
'productMetadata',
$productMetadata
);

$this->config->getBuildNotationCode();
$this->assertEquals('Magento_Cart_SomeEdition', $this->config->getBuildNotationCode());
}
}
Loading

0 comments on commit b7da986

Please sign in to comment.