Skip to content

Commit 32baf19

Browse files
committed
MC-17337: Braintree Error Code Mapping Not Working for CVV 200
1 parent 6e534ad commit 32baf19

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
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/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>

0 commit comments

Comments
 (0)