Skip to content

Commit e5cf9f4

Browse files
Merge pull request #356 from magento-mpi/MPI-PR-2.1.3
Fixed issues: - MAGETWO-56910: Braintree doesn't work when using table prefixing - MAGETWO-57426: [Github] Braintree Vault payments causing GET order API to throw error - MAGETWO-56932: Checkout page freezes when ordering Virtual Gift Card with Authorize.net set to Authorize and Capture - MAGETWO-57037: UPS not providing shipping rates for Puerto Rico - MAGETWO-57086: [Github] #5910 Braintree sandbox errors when using alternative Merchant Account ID
2 parents 68112cc + cbb2688 commit e5cf9f4

File tree

16 files changed

+187
-37
lines changed

16 files changed

+187
-37
lines changed

app/code/Magento/Braintree/Gateway/Config/Config.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,14 @@ public function isActive()
169169
{
170170
return (bool) $this->getValue(self::KEY_ACTIVE);
171171
}
172+
173+
/**
174+
* Get Merchant account ID
175+
*
176+
* @return string
177+
*/
178+
public function getMerchantAccountId()
179+
{
180+
return $this->getValue(self::KEY_MERCHANT_ACCOUNT_ID);
181+
}
172182
}

app/code/Magento/Braintree/Gateway/Request/PaymentDataBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function build(array $buildSubject)
8787
self::ORDER_ID => $order->getOrderIncrementId()
8888
];
8989

90-
$merchantAccountId = $this->config->getValue(Config::KEY_MERCHANT_ACCOUNT_ID);
90+
$merchantAccountId = $this->config->getMerchantAccountId();
9191
if (!empty($merchantAccountId)) {
9292
$result[self::MERCHANT_ACCOUNT_ID] = $merchantAccountId;
9393
}

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

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

8+
use Magento\Braintree\Gateway\Request\PaymentDataBuilder;
89
use Magento\Checkout\Model\ConfigProviderInterface;
910
use Magento\Braintree\Gateway\Config\Config;
1011
use Magento\Braintree\Gateway\Config\PayPal\Config as PayPalConfig;
@@ -116,7 +117,14 @@ public function getConfig()
116117
public function getClientToken()
117118
{
118119
if (empty($this->clientToken)) {
119-
$this->clientToken = $this->adapter->generate();
120+
$params = [];
121+
122+
$merchantAccountId = $this->config->getMerchantAccountId();
123+
if (!empty($merchantAccountId)) {
124+
$params[PaymentDataBuilder::MERCHANT_ACCOUNT_ID] = $merchantAccountId;
125+
}
126+
127+
$this->clientToken = $this->adapter->generate($params);
120128
}
121129

122130
return $this->clientToken;

app/code/Magento/Braintree/Test/Unit/Gateway/Request/PaymentDataBuilderTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ public function testBuild()
133133
->willReturnMap($additionalData);
134134

135135
$this->configMock->expects(static::once())
136-
->method('getValue')
137-
->with(Config::KEY_MERCHANT_ACCOUNT_ID)
136+
->method('getMerchantAccountId')
138137
->willReturn(self::MERCHANT_ACCOUNT_ID);
139138

140139
$this->paymentDO->expects(static::once())

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
class ConfigProviderTest extends \PHPUnit_Framework_TestCase
2020
{
2121
const SDK_URL = 'https://js.braintreegateway.com/v2/braintree.js';
22-
2322
const CLIENT_TOKEN = 'token';
23+
const MERCHANT_ACCOUNT_ID = '245345';
2424

2525
/**
2626
* @var Config|\PHPUnit_Framework_MockObject_MockObject
@@ -115,11 +115,17 @@ public function testGetConfig($config, $expected)
115115

116116
/**
117117
* @covers \Magento\Braintree\Model\Ui\ConfigProvider::getClientToken
118+
* @dataProvider getClientTokenDataProvider
118119
*/
119-
public function testGetClientToken()
120+
public function testGetClientToken($merchantAccountId, $params)
120121
{
122+
$this->config->expects(static::once())
123+
->method('getMerchantAccountId')
124+
->willReturn($merchantAccountId);
125+
121126
$this->braintreeAdapter->expects(static::once())
122127
->method('generate')
128+
->with($params)
123129
->willReturn(self::CLIENT_TOKEN);
124130

125131
static::assertEquals(self::CLIENT_TOKEN, $this->configProvider->getClientToken());
@@ -188,4 +194,21 @@ public function getConfigDataProvider()
188194
]
189195
];
190196
}
197+
198+
/**
199+
* @return array
200+
*/
201+
public function getClientTokenDataProvider()
202+
{
203+
return [
204+
[
205+
'merchantAccountId' => '',
206+
'params' => []
207+
],
208+
[
209+
'merchantAccountId' => self::MERCHANT_ACCOUNT_ID,
210+
'params' => ['merchantAccountId' => self::MERCHANT_ACCOUNT_ID]
211+
]
212+
];
213+
}
191214
}

app/code/Magento/Payment/view/frontend/web/js/view/payment/iframe.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ define(
154154
*/
155155
clearTimeout: function () {
156156
clearTimeout(this.timeoutId);
157+
this.fail();
157158

158159
return this;
159160
},

app/code/Magento/Sales/Model/ResourceModel/Order/Payment/Collection.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Sales\Model\ResourceModel\Order\Payment;
77

8+
use Magento\Sales\Api\Data\OrderPaymentInterface;
89
use Magento\Sales\Api\Data\OrderPaymentSearchResultInterface;
910
use Magento\Sales\Model\ResourceModel\Order\Collection\AbstractCollection;
1011

@@ -75,7 +76,34 @@ protected function _afterLoad()
7576
{
7677
foreach ($this->_items as $item) {
7778
$this->getResource()->unserializeFields($item);
79+
if (!empty($item->getData(OrderPaymentInterface::ADDITIONAL_INFORMATION))) {
80+
$additionalInfo = $this->convertAdditionalInfo(
81+
$item->getData(OrderPaymentInterface::ADDITIONAL_INFORMATION)
82+
);
83+
$item->setData(OrderPaymentInterface::ADDITIONAL_INFORMATION, $additionalInfo);
84+
}
7885
}
7986
return parent::_afterLoad();
8087
}
88+
89+
/**
90+
* Convert multidimensional additional information array to single
91+
*
92+
* @param array $info
93+
* @return array
94+
*/
95+
private function convertAdditionalInfo($info)
96+
{
97+
$result = [];
98+
foreach ($info as $key => $item) {
99+
if (is_array($item)) {
100+
$result += $this->convertAdditionalInfo($item);
101+
unset($info[$key]);
102+
} else {
103+
$result[$key] = $item;
104+
}
105+
}
106+
107+
return $result;
108+
}
81109
}

app/code/Magento/Ups/Model/Carrier.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,13 @@ public function setRequest(RateRequest $request)
325325
$destCountry = self::GUAM_COUNTRY_ID;
326326
}
327327

328-
$rowRequest->setDestCountry($this->_countryFactory->create()->load($destCountry)->getData('iso2_code'));
328+
$country = $this->_countryFactory->create()->load($destCountry);
329+
$rowRequest->setDestCountry($country->getData('iso2_code') ?: $destCountry);
329330

330331
$rowRequest->setDestRegionCode($request->getDestRegionCode());
331332

332333
if ($request->getDestPostcode()) {
333334
$rowRequest->setDestPostal($request->getDestPostcode());
334-
} else {
335335
}
336336

337337
$weight = $this->getTotalNumOfBoxes($request->getPackageWeight());

app/code/Magento/Ups/Test/Unit/Model/CarrierTest.php

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
use Magento\Quote\Model\Quote\Address\RateRequest;
99
use Magento\Ups\Model\Carrier;
10+
use Magento\Directory\Model\Country;
11+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
1012

1113
class CarrierTest extends \PHPUnit_Framework_TestCase
1214
{
@@ -54,7 +56,7 @@ class CarrierTest extends \PHPUnit_Framework_TestCase
5456
protected $countryFactory;
5557

5658
/**
57-
* @var \Magento\Directory\Model\Country
59+
* @var Country|MockObject
5860
*/
5961
protected $country;
6062

@@ -306,4 +308,47 @@ public function logDataProvider()
306308
]
307309
];
308310
}
311+
312+
/**
313+
* @covers \Magento\Ups\Model\Carrier::setRequest
314+
* @param string $countryCode
315+
* @param string $foundCountryCode
316+
* @dataProvider countryDataProvider
317+
*/
318+
public function testSetRequest($countryCode, $foundCountryCode)
319+
{
320+
/** @var RateRequest $request */
321+
$request = $this->helper->getObject(RateRequest::class);
322+
$request->setData([
323+
'orig_country' => 'USA',
324+
'orig_region_code' => 'CA',
325+
'orig_post_code' => 90230,
326+
'orig_city' => 'Culver City',
327+
'dest_country_id' => $countryCode,
328+
]);
329+
330+
$this->country->expects(static::at(1))
331+
->method('load')
332+
->with($countryCode)
333+
->willReturnSelf();
334+
335+
$this->country->expects(static::any())
336+
->method('getData')
337+
->with('iso2_code')
338+
->willReturn($foundCountryCode);
339+
340+
$this->model->setRequest($request);
341+
}
342+
343+
/**
344+
* Get list of country variations
345+
* @return array
346+
*/
347+
public function countryDataProvider()
348+
{
349+
return [
350+
['countryCode' => 'PR', 'foundCountryCode' => null],
351+
['countryCode' => 'US', 'foundCountryCode' => 'US'],
352+
];
353+
}
309354
}

app/code/Magento/Vault/Model/Method/Vault.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
*/
3232
final class Vault implements VaultPaymentInterface
3333
{
34+
/**
35+
* @deprecated
36+
*/
3437
const TOKEN_METADATA_KEY = 'token_metadata';
3538

3639
/**
@@ -111,6 +114,7 @@ final class Vault implements VaultPaymentInterface
111114
* @param PaymentTokenManagementInterface $tokenManagement
112115
* @param OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory
113116
* @param string $code
117+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
114118
*/
115119
public function __construct(
116120
ConfigInterface $config,
@@ -448,21 +452,20 @@ public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount)
448452
/**
449453
* @param OrderPaymentInterface $orderPayment
450454
* @return void
455+
* @throws \LogicException
451456
*/
452457
private function attachTokenExtensionAttribute(OrderPaymentInterface $orderPayment)
453458
{
454459
$additionalInformation = $orderPayment->getAdditionalInformation();
455460

456-
$tokenData = isset($additionalInformation[self::TOKEN_METADATA_KEY])
457-
? $additionalInformation[self::TOKEN_METADATA_KEY]
458-
: null;
459-
460-
if ($tokenData === null) {
461-
throw new \LogicException("Token metadata should be defined");
461+
if (empty($additionalInformation[PaymentTokenInterface::CUSTOMER_ID]) ||
462+
empty($additionalInformation[PaymentTokenInterface::PUBLIC_HASH])
463+
) {
464+
throw new \LogicException('Customer and public hash should be defined');
462465
}
463466

464-
$customerId = $tokenData[PaymentTokenInterface::CUSTOMER_ID];
465-
$publicHash = $tokenData[PaymentTokenInterface::PUBLIC_HASH];
467+
$customerId = $additionalInformation[PaymentTokenInterface::CUSTOMER_ID];
468+
$publicHash = $additionalInformation[PaymentTokenInterface::PUBLIC_HASH];
466469

467470
$paymentToken = $this->tokenManagement->getByPublicHash($publicHash, $customerId);
468471

app/code/Magento/Vault/Model/ResourceModel/PaymentToken.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function addLinkToOrderPayment($paymentTokenId, $orderPaymentId)
104104
$connection = $this->getConnection();
105105

106106
$select = $connection->select()
107-
->from(InstallSchema::ORDER_PAYMENT_TO_PAYMENT_TOKEN_TABLE)
107+
->from($this->getTable(InstallSchema::ORDER_PAYMENT_TO_PAYMENT_TOKEN_TABLE))
108108
->where('order_payment_id = ?', (int) $orderPaymentId)
109109
->where('payment_token_id =?', (int) $paymentTokenId);
110110

app/code/Magento/Vault/Observer/PaymentTokenAssigner.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public function execute(Observer $observer)
6868
}
6969

7070
$paymentModel->setAdditionalInformation(
71-
Vault::TOKEN_METADATA_KEY,
7271
[
7372
PaymentTokenInterface::CUSTOMER_ID => $customerId,
7473
PaymentTokenInterface::PUBLIC_HASH => $tokenPublicHash

app/code/Magento/Vault/Test/Unit/Model/Method/VaultTest.php

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
use Magento\Vault\Model\Method\Vault;
1919
use Magento\Vault\Model\VaultPaymentInterface;
2020

21+
/**
22+
* Class VaultTest
23+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
24+
*/
2125
class VaultTest extends \PHPUnit_Framework_TestCase
2226
{
2327
/**
@@ -45,23 +49,39 @@ public function testAuthorizeNotOrderPayment()
4549

4650
/**
4751
* @expectedException \LogicException
48-
* @expectedExceptionMessage Token metadata should be defined
52+
* @expectedExceptionMessage Customer and public hash should be defined
53+
* @dataProvider tokenMetadataProvider
4954
*/
50-
public function testAuthorizeNoTokenMetadata()
55+
public function testAuthorizeNoTokenMetadata($additionalInfo)
5156
{
5257
$paymentModel = $this->getMockBuilder(Payment::class)
5358
->disableOriginalConstructor()
5459
->getMock();
5560

5661
$paymentModel->expects(static::once())
5762
->method('getAdditionalInformation')
58-
->willReturn([]);
63+
->willReturn($additionalInfo);
5964

6065
/** @var Vault $model */
6166
$model = $this->objectManager->getObject(Vault::class);
6267
$model->authorize($paymentModel, 0);
6368
}
6469

70+
/**
71+
* Get list of variations
72+
* @return array
73+
*/
74+
public function tokenMetadataProvider()
75+
{
76+
return [
77+
['additionalInfo' => []],
78+
['additionalInfo' => ['public_hash' => null]],
79+
['additionalInfo' => ['customer_id' => null]],
80+
['additionalInfo' => ['public_hash' => '1ds23', 'customer_id' => null]],
81+
['additionalInfo' => ['public_hash' => null, 'customer_id' => 1]],
82+
];
83+
}
84+
6585
/**
6686
* @expectedException \LogicException
6787
* @expectedExceptionMessage No token found
@@ -80,10 +100,8 @@ public function testAuthorizeNoToken()
80100
->method('getAdditionalInformation')
81101
->willReturn(
82102
[
83-
Vault::TOKEN_METADATA_KEY => [
84-
PaymentTokenInterface::CUSTOMER_ID => $customerId,
85-
PaymentTokenInterface::PUBLIC_HASH => $publicHash
86-
]
103+
PaymentTokenInterface::CUSTOMER_ID => $customerId,
104+
PaymentTokenInterface::PUBLIC_HASH => $publicHash
87105
]
88106
);
89107
$tokenManagement->expects(static::once())
@@ -127,10 +145,8 @@ public function testAuthorize()
127145
->method('getAdditionalInformation')
128146
->willReturn(
129147
[
130-
Vault::TOKEN_METADATA_KEY => [
131-
PaymentTokenInterface::CUSTOMER_ID => $customerId,
132-
PaymentTokenInterface::PUBLIC_HASH => $publicHash
133-
]
148+
PaymentTokenInterface::CUSTOMER_ID => $customerId,
149+
PaymentTokenInterface::PUBLIC_HASH => $publicHash
134150
]
135151
);
136152
$tokenManagement->expects(static::once())

app/code/Magento/Vault/Test/Unit/Observer/PaymentTokenAssignerTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ public function testExecuteSaveMetadata()
199199
$paymentModel->expects(static::once())
200200
->method('setAdditionalInformation')
201201
->with(
202-
Vault::TOKEN_METADATA_KEY,
203202
[
204203
PaymentTokenInterface::CUSTOMER_ID => $customerId,
205204
PaymentTokenInterface::PUBLIC_HASH => $publicHash

0 commit comments

Comments
 (0)