Skip to content

Commit f770e75

Browse files
committed
Merge branch 'MC-17337' of https://github.com/magento-mpi/magento2ce into MPI_PR_2019_06_21
2 parents c6d90a3 + ad6a8ed commit f770e75

File tree

5 files changed

+118
-8
lines changed

5 files changed

+118
-8
lines changed

app/code/Magento/Braintree/Gateway/Validator/ErrorCodeProvider.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ public function getErrorCodes($response): array
3838
$result[] = $error->code;
3939
}
4040

41+
if (isset($response->transaction) && $response->transaction->status === 'gateway_rejected') {
42+
$result[] = $response->transaction->gatewayRejectionReason;
43+
}
44+
45+
if (isset($response->transaction) && $response->transaction->status === 'processor_declined') {
46+
$result[] = $response->transaction->processorResponseCode;
47+
}
48+
4149
return $result;
4250
}
4351
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Braintree\Test\Unit\Gateway\Validator;
9+
10+
use Braintree\Result\Error;
11+
use Magento\Braintree\Gateway\Validator\ErrorCodeProvider;
12+
use PHPUnit\Framework\TestCase;
13+
14+
/**
15+
* Class ErrorCodeProviderTest
16+
*/
17+
class ErrorCodeProviderTest extends TestCase
18+
{
19+
/**
20+
* @var ErrorCodeProvider
21+
*/
22+
private $model;
23+
24+
/**
25+
* Checks a extracting error codes from response.
26+
*
27+
* @param array $errors
28+
* @param array $transaction
29+
* @param array $expectedResult
30+
* @return void
31+
* @dataProvider getErrorCodeDataProvider
32+
*/
33+
public function testGetErrorCodes(array $errors, array $transaction, array $expectedResult): void
34+
{
35+
$response = new Error(
36+
[
37+
'errors' => ['errors' => $errors],
38+
'transaction' => $transaction,
39+
]
40+
);
41+
$this->model = new ErrorCodeProvider();
42+
$actual = $this->model->getErrorCodes($response);
43+
44+
$this->assertSame($expectedResult, $actual);
45+
}
46+
47+
/**
48+
* Gets list of errors variations.
49+
*
50+
* @return array
51+
*/
52+
public function getErrorCodeDataProvider(): array
53+
{
54+
return [
55+
[
56+
'errors' => [
57+
['code' => 91734],
58+
['code' => 91504]
59+
],
60+
'transaction' => [
61+
'status' => 'success',
62+
],
63+
'expectedResult' => ['91734', '91504']
64+
],
65+
[
66+
'errors' => [],
67+
'transaction' => [
68+
'status' => 'processor_declined',
69+
'processorResponseCode' => '1000'
70+
],
71+
'expectedResult' => ['1000']
72+
],
73+
[
74+
'errors' => [],
75+
'transaction' => [
76+
'status' => 'processor_declined',
77+
'processorResponseCode' => '1000'
78+
],
79+
'expectedResult' => ['1000']
80+
],
81+
[
82+
'errors' => [
83+
['code' => 91734],
84+
['code' => 91504]
85+
],
86+
'transaction' => [
87+
'status' => 'processor_declined',
88+
'processorResponseCode' => '1000'
89+
],
90+
'expectedResult' => ['91734', '91504', '1000']
91+
],
92+
];
93+
}
94+
}

app/code/Magento/Braintree/Test/Unit/Gateway/Validator/GeneralResponseValidatorTest.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
use Magento\Payment\Gateway\Validator\ResultInterfaceFactory;
1515
use PHPUnit_Framework_MockObject_MockObject as MockObject;
1616

17+
/**
18+
* Class GeneralResponseValidatorTest
19+
*/
1720
class GeneralResponseValidatorTest extends \PHPUnit\Framework\TestCase
1821
{
1922
/**
@@ -61,11 +64,13 @@ public function testValidate(array $validationSubject, bool $isValid, $messages,
6164
$result = new Result($isValid, $messages);
6265

6366
$this->resultInterfaceFactory->method('create')
64-
->with([
65-
'isValid' => $isValid,
66-
'failsDescription' => $messages,
67-
'errorCodes' => $errorCodes
68-
])
67+
->with(
68+
[
69+
'isValid' => $isValid,
70+
'failsDescription' => $messages,
71+
'errorCodes' => $errorCodes
72+
]
73+
)
6974
->willReturn($result);
7075

7176
$actual = $this->responseValidator->validate($validationSubject);
@@ -82,9 +87,11 @@ public function dataProviderTestValidate()
8287
{
8388
$successTransaction = new \stdClass();
8489
$successTransaction->success = true;
90+
$successTransaction->status = 'authorized';
8591

8692
$failureTransaction = new \stdClass();
8793
$failureTransaction->success = false;
94+
$failureTransaction->status = 'declined';
8895
$failureTransaction->message = 'Transaction was failed.';
8996

9097
$errors = [
@@ -93,10 +100,10 @@ public function dataProviderTestValidate()
93100
'code' => 81804,
94101
'attribute' => 'base',
95102
'message' => 'Cannot process transaction.'
96-
]
103+
],
97104
]
98105
];
99-
$errorTransaction = new Error(['errors' => $errors]);
106+
$errorTransaction = new Error(['errors' => $errors, 'transaction' => ['status' => 'declined']]);
100107

101108
return [
102109
[

app/code/Magento/Braintree/etc/braintree_error_mapping.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<message code="81716" translate="true">Credit card number must be 12-19 digits.</message>
2121
<message code="81723" translate="true">Cardholder name is too long.</message>
2222
<message code="81736" translate="true">CVV verification failed.</message>
23+
<message code="cvv" translate="true">CVV verification failed.</message>
2324
<message code="81737" translate="true">Postal code verification failed.</message>
2425
<message code="81750" translate="true">Credit card number is prohibited.</message>
2526
<message code="81801" translate="true">Addresses must have at least one field filled in.</message>

dev/tests/integration/testsuite/Magento/Checkout/Api/PaymentInformationManagementTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function testSavePaymentInformationAndPlaceOrderWithErrors(
9696
array_push($errors['errors'], ['code' => $testErrorCode]);
9797
}
9898

99-
$response = new Error(['errors' => $errors]);
99+
$response = new Error(['errors' => $errors, 'transaction' => ['status' => 'declined']]);
100100

101101
$this->client->method('placeRequest')
102102
->willReturn(['object' => $response]);

0 commit comments

Comments
 (0)