Skip to content

Commit bf7ae24

Browse files
committed
Merge branch 'MAGETWO-68793' into MPI-Bugfixes
2 parents cb5a52f + a302838 commit bf7ae24

File tree

9 files changed

+141
-65
lines changed

9 files changed

+141
-65
lines changed

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

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -677,31 +677,24 @@ protected function _getAvsLabel($value)
677677
{
678678
if (!isset($this->_labelCodesCache[self::PAYPAL_AVS_CODE])) {
679679
$this->_labelCodesCache[self::PAYPAL_AVS_CODE] = [
680-
// Visa, MasterCard, Discover and American Express
681-
'A' => __('Matched Address only (no ZIP)'),
682-
// international "A"
683-
'B' => __('Matched Address only (no ZIP) International'),
680+
'A' => __('Matched Address only (no ZIP)'), // Visa, MasterCard, Discover and American Express
681+
'B' => __('Matched Address only (no ZIP) International'), // international "A"
684682
'N' => __('No Details matched'),
685-
// international "N"
686-
'C' => __('No Details matched. International'),
683+
'C' => __('No Details matched. International'), // international "N"
687684
'X' => __('Exact Match.'),
688-
// international "X"
689-
'D' => __('Exact Match. Address and Postal Code. International'),
690-
// UK-specific "X"
691-
'F' => __('Exact Match. Address and Postal Code. UK-specific'),
685+
'D' => __('Exact Match. Address and Postal Code. International'), // international "X"
686+
'F' => __('Exact Match. Address and Postal Code. UK-specific'), // UK-specific "X"
692687
'E' => __('N/A. Not allowed for MOTO (Internet/Phone) transactions'),
693688
'G' => __('N/A. Global Unavailable'),
694689
'I' => __('N/A. International Unavailable'),
695690
'Z' => __('Matched five-digit ZIP only (no Address)'),
696-
// international "Z"
697-
'P' => __('Matched Postal Code only (no Address)'),
691+
'P' => __('Matched Postal Code only (no Address)'), // international "Z"
698692
'R' => __('N/A. Retry'),
699693
'S' => __('N/A. Service not Supported'),
700694
'U' => __('N/A. Unavailable'),
701695
'W' => __('Matched whole nine-digit ZIP (no Address)'),
702696
'Y' => __('Yes. Matched Address and five-digit ZIP'),
703-
// Maestro and Solo
704-
'0' => __('All the address information matched'),
697+
'0' => __('All the address information matched'), // Maestro and Solo
705698
'1' => __('None of the address information matched'),
706699
'2' => __('Part of the address information matched'),
707700
'3' => __('N/A. The merchant did not provide AVS information'),

app/code/Magento/Paypal/Model/Payflow/Service/Response/Validator/AVSResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class AVSResponse implements ValidatorInterface
3535
* Indicates whether AVS response is international (Y),
3636
* US (N), or cannot be determined (X). Client version
3737
* 3.06 or later is required.
38+
* @deprecated
39+
* @see \Magento\Paypal\Model\Payflow\Service\Response\Validator\IAVSResponse
3840
*/
3941
const IAVS = 'iavs';
4042

@@ -58,7 +60,6 @@ class AVSResponse implements ValidatorInterface
5860
protected $avsCheck = [
5961
'avsaddr' => 'avs_street',
6062
'avszip' => 'avs_zip',
61-
'iavs' => 'avs_international',
6263
];
6364

6465
/**
@@ -67,7 +68,6 @@ class AVSResponse implements ValidatorInterface
6768
protected $errorsMessages = [
6869
'avs_street' => 'AVS address does not match.',
6970
'avs_zip' => 'AVS zip does not match.',
70-
'avs_international' => 'International AVS indicator does not match.',
7171
];
7272

7373
/**
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Paypal\Model\Payflow\Service\Response\Validator;
7+
8+
use Magento\Framework\DataObject;
9+
use Magento\Paypal\Model\Payflow\Service\Response\ValidatorInterface;
10+
use Magento\Paypal\Model\Payflow\Transparent;
11+
12+
/**
13+
* International AVS response validator checks configuration option
14+
* and fails validation if PayPal returns IAVS's check marked as international issuing bank.
15+
*/
16+
class IAVSResponse implements ValidatorInterface
17+
{
18+
/**
19+
* Indicates whether AVS response is international (Y),
20+
* US (N), or cannot be determined (X).
21+
* @var string
22+
*/
23+
private static $iavs = 'iavs';
24+
25+
/**
26+
* @var string
27+
*/
28+
private static $negativeResponseCode = 'y';
29+
30+
/**
31+
* @inheritdoc
32+
*/
33+
public function validate(DataObject $response, Transparent $transparentModel)
34+
{
35+
$config = $transparentModel->getConfig();
36+
// the IAVS configuration setting is not enabled
37+
if (!$config->getValue('avs_international')) {
38+
return true;
39+
}
40+
41+
if (strtolower((string) $response->getData(self::$iavs)) === self::$negativeResponseCode) {
42+
$response->setRespmsg('International AVS indicator does not match.');
43+
return false;
44+
}
45+
46+
return true;
47+
}
48+
}

app/code/Magento/Paypal/Test/Unit/Model/Payflow/Service/Response/Validator/AVSResponseTest.php

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,35 @@
88
use Magento\Payment\Model\Method\ConfigInterface;
99
use Magento\Paypal\Model\Payflow\Service\Response\Validator\AVSResponse;
1010
use Magento\Paypal\Model\Payflow\Transparent;
11+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
1112

12-
/**
13-
* Class AVSResponseTest
14-
*
15-
* Test class for \Magento\Paypal\Model\Payflow\Service\Response\Validator\AVSResponse
16-
*/
1713
class AVSResponseTest extends \PHPUnit_Framework_TestCase
1814
{
1915
/**
20-
* @var \Magento\Paypal\Model\Payflow\Service\Response\Validator\AVSResponse
16+
* @var AVSResponse
2117
*/
22-
protected $validator;
18+
private $validator;
2319

2420
/**
25-
* @var ConfigInterface|\PHPUnit_Framework_MockObject_MockObject
21+
* @var ConfigInterface|MockObject
2622
*/
27-
protected $configMock;
23+
private $config;
2824

2925
/**
30-
* @var Transparent|\PHPUnit_Framework_MockObject_MockObject
26+
* @var Transparent|MockObject
3127
*/
32-
protected $payflowproFacade;
28+
private $payflowproFacade;
3329

3430
/**
35-
* Set up
36-
*
37-
* @return void
31+
* @inheritdoc
3832
*/
3933
protected function setUp()
4034
{
41-
$this->configMock = $this->getMockBuilder(ConfigInterface::class)
35+
$this->config = $this->getMockBuilder(ConfigInterface::class)
4236
->getMockForAbstractClass();
4337

4438
$this->payflowproFacade = $this->getMockBuilder(Transparent::class)
4539
->disableOriginalConstructor()
46-
->setMethods([])
4740
->getMock();
4841

4942
$this->validator = new AVSResponse();
@@ -53,22 +46,18 @@ protected function setUp()
5346
* @param bool $expectedResult
5447
* @param \Magento\Framework\DataObject $response
5548
* @param array $configMap
56-
* @param int $exactlyCount
5749
*
5850
* @dataProvider validationDataProvider
5951
*/
6052
public function testValidation(
6153
$expectedResult,
6254
\Magento\Framework\DataObject $response,
63-
array $configMap,
64-
$exactlyCount
55+
array $configMap
6556
) {
66-
$this->payflowproFacade->expects(static::once())
67-
->method('getConfig')
68-
->willReturn($this->configMock);
57+
$this->payflowproFacade->method('getConfig')
58+
->willReturn($this->config);
6959

70-
$this->configMock->expects(static::exactly($exactlyCount))
71-
->method('getValue')
60+
$this->config->method('getValue')
7261
->willReturnMap($configMap);
7362

7463
static::assertEquals($expectedResult, $this->validator->validate($response, $this->payflowproFacade));
@@ -92,111 +81,90 @@ public function validationDataProvider()
9281
[
9382
'avsaddr' => 'Y',
9483
'avszip' => 'Y',
95-
'iavs' => 'Y',
9684
]
9785
),
9886
'configMap' => [
9987
['avs_street', null, '0'],
10088
['avs_zip', null, '0'],
101-
['avs_international', null, '0'],
10289
],
103-
'exactlyCount' => 3,
10490
],
10591
[
10692
'expectedResult' => true,
10793
'response' => new \Magento\Framework\DataObject(
10894
[
10995
'avsaddr' => 'Y',
11096
'avszip' => 'Y',
111-
'iavs' => 'Y',
11297
]
11398
),
11499
'configMap' => [
115100
['avs_street', null, '1'],
116101
['avs_zip', null, '1'],
117-
['avs_international', null, '1'],
118102
],
119-
'exactlyCount' => 3,
120103
],
121104
[
122105
'expectedResult' => false,
123106
'response' => new \Magento\Framework\DataObject(
124107
[
125108
'avsaddr' => 'Y',
126109
'avszip' => 'N',
127-
'iavs' => 'Y',
128110
]
129111
),
130112
'configMap' => [
131113
['avs_street', null, '1'],
132114
['avs_zip', null, '1'],
133-
['avs_international', null, '1'],
134115
],
135-
'exactlyCount' => 2,
136116
],
137117
[
138118
'expectedResult' => true,
139119
'response' => new \Magento\Framework\DataObject(
140120
[
141121
'avsaddr' => 'Y',
142122
'avszip' => 'N',
143-
'iavs' => 'N',
144123
]
145124
),
146125
'configMap' => [
147126
['avs_street', null, '1'],
148127
['avs_zip', null, '0'],
149-
['avs_international', null, '0'],
150128
],
151-
'exactlyCount' => 3,
152129
],
153130
[
154131
'expectedResult' => true,
155132
'response' => new \Magento\Framework\DataObject(
156133
[
157134
'avsaddr' => 'Y',
158135
'avszip' => 'N',
159-
'iavs' => 'N',
160136
]
161137
),
162138
'configMap' => [
163139
['avs_street', null, '0'],
164140
['avs_zip', null, '0'],
165-
['avs_international', null, '0'],
166141
],
167-
'exactlyCount' => 3,
168142
],
169143
[
170144
'expectedResult' => true,
171145
'response' => new \Magento\Framework\DataObject(
172146
[
173147
'avsaddr' => 'X',
174148
'avszip' => 'Y',
175-
'iavs' => 'X',
176149
]
177150
),
178151
'configMap' => [
179152
['avs_street', null, '1'],
180153
['avs_zip', null, '1'],
181-
['avs_international', null, '1'],
182154
],
183-
'exactlyCount' => 3,
184155
],
185156
[
186157
'expectedResult' => true,
187158
'response' => new \Magento\Framework\DataObject(
188159
[
189160
'avsaddr' => 'X',
190161
'avszip' => 'Y',
191-
'iavs' => 'X',
192162
]
193163
),
194164
'configMap' => [
195165
['avs_street', null, '1'],
196166
['avs_zip', null, '0'],
197-
['avs_international', null, '1'],
198167
],
199-
'exactlyCount' => 3,
200168
],
201169
];
202170
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Paypal\Test\Unit\Model\Payflow\Service\Response\Validator;
7+
8+
use Magento\Framework\DataObject;
9+
use Magento\Paypal\Model\Payflow\Service\Response\Validator\IAVSResponse;
10+
use Magento\Paypal\Model\Payflow\Transparent;
11+
use Magento\Paypal\Model\PayflowConfig;
12+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
13+
14+
class IAVSResponseTest extends \PHPUnit_Framework_TestCase
15+
{
16+
/**
17+
* Checks a case when IAVS validator retrieves different response from PayPal.
18+
*
19+
* @param int $configValue
20+
* @param string $iavs
21+
* @param bool $expected
22+
* @dataProvider variationsDataProvider
23+
*/
24+
public function testValidate($configValue, $iavs, $expected)
25+
{
26+
$response = new DataObject([
27+
'iavs' => $iavs
28+
]);
29+
30+
/** @var PayflowConfig|MockObject $config */
31+
$config = $this->getMockBuilder(PayflowConfig::class)
32+
->disableOriginalConstructor()
33+
->getMock();
34+
35+
/** @var Transparent|MockObject $model */
36+
$model = $this->getMockBuilder(Transparent::class)
37+
->disableOriginalConstructor()
38+
->getMock();
39+
40+
$model->method('getConfig')
41+
->willReturn($config);
42+
43+
$config->method('getValue')
44+
->willReturn($configValue);
45+
46+
$validator = new IAVSResponse();
47+
self::assertEquals($expected, $validator->validate($response, $model));
48+
}
49+
50+
/**
51+
* Gets list of different variations like configuration, IAVS value.
52+
*
53+
* @return array
54+
*/
55+
public function variationsDataProvider()
56+
{
57+
return [
58+
['configValue' => 1, 'iavs' => 'Y', 'expected' => false],
59+
['configValue' => 0, 'iavs' => 'Y', 'expected' => true],
60+
['configValue' => 1, 'iavs' => 'N', 'expected' => true],
61+
['configValue' => 1, 'iavs' => 'X', 'expected' => true],
62+
['configValue' => 0, 'iavs' => 'X', 'expected' => true],
63+
];
64+
}
65+
}

app/code/Magento/Paypal/etc/adminhtml/system/paypal_payflowpro.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@
188188
<attribute type="shared">1</attribute>
189189
</field>
190190
<field id="avs_international" translate="label" type="select" sortOrder="3" showInDefault="1" showInWebsite="1">
191-
<label>International AVS Indicator Does Not Match</label>
191+
<label>Card Issuer Is Outside The United States</label>
192192
<config_path>payment/payflowpro/avs_international</config_path>
193193
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
194194
<attribute type="shared">1</attribute>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
<argument name="validators" xsi:type="array">
127127
<item name="cvv2_code" xsi:type="object">Magento\Paypal\Model\Payflow\Service\Response\Validator\CVV2Match</item>
128128
<item name="avs_response" xsi:type="object">Magento\Paypal\Model\Payflow\Service\Response\Validator\AVSResponse</item>
129+
<item name="iavs_response" xsi:type="object">Magento\Paypal\Model\Payflow\Service\Response\Validator\IAVSResponse</item>
129130
</argument>
130131
</arguments>
131132
</type>
@@ -135,6 +136,7 @@
135136
<item name="secure_token" xsi:type="object">Magento\Paypal\Model\Payflow\Service\Response\Validator\SecureToken</item>
136137
<item name="cvv2_code" xsi:type="object">Magento\Paypal\Model\Payflow\Service\Response\Validator\CVV2Match</item>
137138
<item name="avs_response" xsi:type="object">Magento\Paypal\Model\Payflow\Service\Response\Validator\AVSResponse</item>
139+
<item name="iavs_response" xsi:type="object">Magento\Paypal\Model\Payflow\Service\Response\Validator\IAVSResponse</item>
138140
</argument>
139141
</arguments>
140142
</virtualType>

0 commit comments

Comments
 (0)