Skip to content

Commit d51ad91

Browse files
Merge pull request #283 from magento-mpi/MPI-PR-2.0
Fixed issues: - MAGETWO-57069: Maestro credit cards doesn't pass validation on server side patch for 2.0.11 - MAGETWO-57072: Maestro credit card doesn't pass validation patch for 2.0.x - MAGETWO-56908: UPS not providing shipping rates for Puerto Rico for 2.0.x - MAGETWO-56911: [Github] #5910 Braintree sandbox errors when using alternative Merchant Account ID for 2.0.x
2 parents a8abd0a + 4db2f5e commit d51ad91

File tree

6 files changed

+89
-16
lines changed

6 files changed

+89
-16
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,13 @@ public function isActive()
169169
public function getClientToken()
170170
{
171171
if ($this->clientToken == null) {
172-
$this->clientToken = $this->braintreeClientToken->generate();
172+
$params = [];
173+
174+
if (!empty($this->getMerchantAccountId())) {
175+
$params['merchantAccountId'] = $this->getMerchantAccountId();
176+
}
177+
178+
$this->clientToken = $this->braintreeClientToken->generate($params);
173179
}
174180
return $this->clientToken;
175181
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ public function validate()
181181
'|8[6-9][0-9]{10}|9[0-9]{11})|62(2(12[6-9][0-9]{10}|1[3-9][0-9]{11}|[2-8][0-9]{12}' .
182182
'|9[0-1][0-9]{11}|92[0-5][0-9]{10})|[4-6][0-9]{13}|8[2-8][0-9]{12})|6(4[4-9][0-9]{13}' .
183183
'|5[0-9]{14}))$/',
184+
'MI' => '/^(5(0|[6-9])|63|67(?!59|6770|6774))[0-9]{10,17}/',
185+
'MD' => '/^(6759(?!24|38|40|6[3-9]|70|76)[0-9]{8,15}|(676770|676774)[0-9]{6,13})/',
184186
];
185187

186188
$ccNumAndTypeMatches = isset(
@@ -250,6 +252,8 @@ public function getVerificationRegEx()
250252
'SO' => '/^[0-9]{3,4}$/',
251253
'OT' => '/^[0-9]{3,4}$/',
252254
'JCB' => '/^[0-9]{3,4}$/',
255+
'MI' => '/^[0-9]{3}$/',
256+
'MD' => '/^[0-9]{3}$/',
253257
];
254258
return $verificationExpList;
255259
}

app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/credit-card-number-validator/credit-card-type.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,20 @@ define(
9191
}
9292
},
9393
{
94-
title: 'Maestro',
94+
title: 'Maestro International',
9595
type: 'MI',
96-
pattern: '^((5((0|[6-9])\\d*)?)|(6|6[37]\\d*))$',
96+
pattern: '^(5(0|[6-9])|63|67(?!59|6770|6774))\\d*$',
97+
gaps: [4, 8, 12],
98+
lengths: [12, 13, 14, 15, 16, 17, 18, 19],
99+
code: {
100+
name: 'CVC',
101+
size: 3
102+
}
103+
},
104+
{
105+
title: 'Maestro Domestic',
106+
type: 'MD',
107+
pattern: '^6759(?!24|38|40|6[3-9]|70|76)|676770|676774\\d*$',
97108
gaps: [4, 8, 12],
98109
lengths: [12, 13, 14, 15, 16, 17, 18, 19],
99110
code: {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,13 @@ public function setRequest(RateRequest $request)
318318
$destCountry = self::GUAM_COUNTRY_ID;
319319
}
320320

321-
$rowRequest->setDestCountry($this->_countryFactory->create()->load($destCountry)->getData('iso2_code'));
321+
$country = $this->_countryFactory->create()->load($destCountry);
322+
$rowRequest->setDestCountry($country->getData('iso2_code') ?: $destCountry);
322323

323324
$rowRequest->setDestRegionCode($request->getDestRegionCode());
324325

325326
if ($request->getDestPostcode()) {
326327
$rowRequest->setDestPostal($request->getDestPostcode());
327-
} else {
328328
}
329329

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

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

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
namespace Magento\Ups\Test\Unit\Model;
77

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

13+
/**
14+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
15+
*/
1016
class CarrierTest extends \PHPUnit_Framework_TestCase
1117
{
1218
const FREE_METHOD_NAME = 'free_method';
@@ -19,10 +25,12 @@ class CarrierTest extends \PHPUnit_Framework_TestCase
1925
* @var \Magento\Quote\Model\Quote\Address\RateResult\Error|\PHPUnit_Framework_MockObject_MockObject
2026
*/
2127
protected $error;
28+
2229
/**
2330
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
2431
*/
2532
protected $helper;
33+
2634
/**
2735
* Model under test
2836
*
@@ -51,7 +59,7 @@ class CarrierTest extends \PHPUnit_Framework_TestCase
5159
protected $countryFactory;
5260

5361
/**
54-
* @var \Magento\Directory\Model\Country
62+
* @var Country|MockObject
5563
*/
5664
protected $country;
5765

@@ -70,7 +78,7 @@ protected function setUp()
7078
$this->helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
7179

7280
$this->scope = $this->getMockBuilder(
73-
'\Magento\Framework\App\Config\ScopeConfigInterface'
81+
\Magento\Framework\App\Config\ScopeConfigInterface::class
7482
)->disableOriginalConstructor()->getMock();
7583

7684
$this->scope->expects(
@@ -81,43 +89,43 @@ protected function setUp()
8189
$this->returnCallback([$this, 'scopeConfiggetValue'])
8290
);
8391

84-
$this->error = $this->getMockBuilder('\Magento\Quote\Model\Quote\Address\RateResult\Error')
92+
$this->error = $this->getMockBuilder(\Magento\Quote\Model\Quote\Address\RateResult\Error::class)
8593
->setMethods(['setCarrier', 'setCarrierTitle', 'setErrorMessage'])
8694
->getMock();
8795

88-
$this->errorFactory = $this->getMockBuilder('Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory')
96+
$this->errorFactory = $this->getMockBuilder(\Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory::class)
8997
->disableOriginalConstructor()
9098
->setMethods(['create'])
9199
->getMock();
92100

93101
$this->errorFactory->expects($this->any())->method('create')->willReturn($this->error);
94102

95-
$this->rate = $this->getMock('Magento\Shipping\Model\Rate\Result', ['getError'], [], '', false);
96-
$rateFactory = $this->getMock('Magento\Shipping\Model\Rate\ResultFactory', ['create'], [], '', false);
103+
$this->rate = $this->getMock(\Magento\Shipping\Model\Rate\Result::class, ['getError'], [], '', false);
104+
$rateFactory = $this->getMock(\Magento\Shipping\Model\Rate\ResultFactory::class, ['create'], [], '', false);
97105

98106
$rateFactory->expects($this->any())->method('create')->willReturn($this->rate);
99107

100-
$this->country = $this->getMockBuilder('\Magento\Directory\Model\Country')
108+
$this->country = $this->getMockBuilder(\Magento\Directory\Model\Country::class)
101109
->disableOriginalConstructor()
102110
->setMethods(['load'])
103111
->getMock();
104112

105-
$this->abstractModel = $this->getMockBuilder('Magento\Framework\Model\AbstractModel')
113+
$this->abstractModel = $this->getMockBuilder(\Magento\Framework\Model\AbstractModel::class)
106114
->disableOriginalConstructor()
107115
->setMethods(['getData'])
108116
->getMock();
109117

110118
$this->country->expects($this->any())->method('load')->willReturn($this->abstractModel);
111119

112-
$this->countryFactory = $this->getMockBuilder('\Magento\Directory\Model\CountryFactory')
120+
$this->countryFactory = $this->getMockBuilder(\Magento\Directory\Model\CountryFactory::class)
113121
->disableOriginalConstructor()
114122
->setMethods(['create'])
115123
->getMock();
116124

117125
$this->countryFactory->expects($this->any())->method('create')->willReturn($this->country);
118126

119127
$this->model = $this->helper->getObject(
120-
'Magento\Ups\Model\Carrier',
128+
\Magento\Ups\Model\Carrier::class,
121129
[
122130
'scopeConfig' => $this->scope,
123131
'rateErrorFactory' => $this->errorFactory,
@@ -233,4 +241,47 @@ public function testCollectRatesFail()
233241

234242
$this->assertSame($this->rate, $this->model->collectRates($request));
235243
}
244+
245+
/**
246+
* @covers \Magento\Ups\Model\Carrier::setRequest
247+
* @param string $countryCode
248+
* @param string $foundCountryCode
249+
* @dataProvider countryDataProvider
250+
*/
251+
public function testSetRequest($countryCode, $foundCountryCode)
252+
{
253+
/** @var RateRequest $request */
254+
$request = $this->helper->getObject(RateRequest::class);
255+
$request->setData([
256+
'orig_country' => 'USA',
257+
'orig_region_code' => 'CA',
258+
'orig_post_code' => 90230,
259+
'orig_city' => 'Culver City',
260+
'dest_country_id' => $countryCode,
261+
]);
262+
263+
$this->country->expects(static::at(1))
264+
->method('load')
265+
->with($countryCode)
266+
->willReturnSelf();
267+
268+
$this->country->expects(static::any())
269+
->method('getData')
270+
->with('iso2_code')
271+
->willReturn($foundCountryCode);
272+
273+
$this->model->setRequest($request);
274+
}
275+
276+
/**
277+
* Get list of country variations
278+
* @return array
279+
*/
280+
public function countryDataProvider()
281+
{
282+
return [
283+
['countryCode' => 'PR', 'foundCountryCode' => null],
284+
['countryCode' => 'US', 'foundCountryCode' => 'US'],
285+
];
286+
}
236287
}

lib/web/mage/validation.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@
108108
'OT': [new RegExp('^([0-9]+)$'), new RegExp('^([0-9]{3}|[0-9]{4})?$'), false],
109109
'DN': [new RegExp('^3((0([0-5]\\d*)?)|[689]\\d*)?$'), new RegExp('^[0-9]{3}$'), true],
110110
'UN': [new RegExp('^6(2\\d*)?$'), new RegExp('^[0-9]{3}$'), true],
111-
'MI': [new RegExp('^((5((0|[6-9])\\d*)?)|(6|6[37]\\d*))$'), new RegExp('^[0-9]{3}$'), true]
111+
'MI': [new RegExp('^(5(0|[6-9])|63|67(?!59|6770|6774))\\d*$'), new RegExp('^[0-9]{3}$'), true],
112+
'MD': [new RegExp('^6759(?!24|38|40|6[3-9]|70|76)|676770|676774\\d*$'), new RegExp('^[0-9]{3}$'), true]
112113
};
113114

114115
/**

0 commit comments

Comments
 (0)