Skip to content

Commit ad779f2

Browse files
authored
Merge pull request #4112 from magento-borg/MAGETWO-99307
[borg] MAGETWO-99307: Authorize.net Transaction Fails but Order goes through
2 parents c7ac6df + e01d589 commit ad779f2

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

app/code/Magento/AuthorizenetAcceptjs/Gateway/Validator/TransactionResponseValidator.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ public function validate(array $validationSubject): ResultInterface
5454
if (isset($transactionResponse['messages']['message']['code'])) {
5555
$errorCodes[] = $transactionResponse['messages']['message']['code'];
5656
$errorMessages[] = $transactionResponse['messages']['message']['text'];
57-
} elseif ($transactionResponse['messages']['message']) {
57+
} elseif (isset($transactionResponse['messages']['message'])) {
5858
foreach ($transactionResponse['messages']['message'] as $message) {
5959
$errorCodes[] = $message['code'];
6060
$errorMessages[] = $message['description'];
6161
}
6262
} elseif (isset($transactionResponse['errors'])) {
6363
foreach ($transactionResponse['errors'] as $message) {
6464
$errorCodes[] = $message['errorCode'];
65-
$errorMessages[] = $message['errorCode'];
65+
$errorMessages[] = $message['errorText'];
6666
}
6767
}
6868

@@ -85,8 +85,10 @@ private function isResponseCodeAnError(array $transactionResponse): bool
8585
?? $transactionResponse['errors'][0]['errorCode']
8686
?? null;
8787

88-
return in_array($transactionResponse['responseCode'], [self::RESPONSE_CODE_APPROVED, self::RESPONSE_CODE_HELD])
89-
&& $code
88+
return !in_array($transactionResponse['responseCode'], [
89+
self::RESPONSE_CODE_APPROVED, self::RESPONSE_CODE_HELD
90+
])
91+
|| $code
9092
&& !in_array(
9193
$code,
9294
[

app/code/Magento/AuthorizenetAcceptjs/Test/Unit/Gateway/Validator/TransactionResponseValidatorTest.php

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@
1515
use PHPUnit\Framework\MockObject\MockObject;
1616
use PHPUnit\Framework\TestCase;
1717

18+
/**
19+
* Tests for the transaction response validator
20+
*/
1821
class TransactionResponseValidatorTest extends TestCase
1922
{
2023
private const RESPONSE_CODE_APPROVED = 1;
2124
private const RESPONSE_CODE_HELD = 4;
25+
private const RESPONSE_CODE_DENIED = 2;
2226
private const RESPONSE_REASON_CODE_APPROVED = 1;
2327
private const RESPONSE_REASON_CODE_PENDING_REVIEW_AUTHORIZED = 252;
2428
private const RESPONSE_REASON_CODE_PENDING_REVIEW = 253;
29+
private const ERROR_CODE_AVS_MISMATCH = 27;
2530

2631
/**
2732
* @var ResultInterfaceFactory|MockObject
@@ -86,16 +91,6 @@ public function testValidateScenarios($transactionResponse, $isValid, $errorCode
8691
public function scenarioProvider()
8792
{
8893
return [
89-
// This validator only cares about successful edge cases so test for default behavior
90-
[
91-
[
92-
'responseCode' => 'foo',
93-
],
94-
true,
95-
[],
96-
[]
97-
],
98-
9994
// Test for acceptable reason codes
10095
[
10196
[
@@ -208,6 +203,29 @@ public function scenarioProvider()
208203
['foo'],
209204
['bar']
210205
],
206+
[
207+
[
208+
'responseCode' => self::RESPONSE_CODE_DENIED,
209+
'errors' => [
210+
[
211+
'errorCode' => self::ERROR_CODE_AVS_MISMATCH,
212+
'errorText' => 'bar'
213+
]
214+
]
215+
],
216+
false,
217+
[self::ERROR_CODE_AVS_MISMATCH],
218+
['bar']
219+
],
220+
// This validator only cares about successful edge cases so test for default behavior
221+
[
222+
[
223+
'responseCode' => 'foo',
224+
],
225+
false,
226+
[],
227+
[]
228+
],
211229
];
212230
}
213231
}

0 commit comments

Comments
 (0)