Skip to content

Commit

Permalink
Improved Exception details from ErrorCode check
Browse files Browse the repository at this point in the history
  • Loading branch information
eusonlito committed Jun 20, 2018
1 parent 13fbc9f commit 2823775
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions src/Redsys/Tpv/Tpv.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,16 +340,8 @@ public function checkTransaction(array $post)

private function checkTransactionError(array $data, $prefix)
{
$error = isset($data[$prefix.'ErrorCode']) ? $data[$prefix.'ErrorCode'] : null;

if (empty($error)) {
return null;
}

if ($message = Messages::getByCode($error)) {
throw new Exception(sprintf('TPV returned error code %s: %s', $error, $message['message']));
} else {
throw new Exception(sprintf('TPV returned unknown error code %s', $error));
if ($error = (isset($data[$prefix.'ErrorCode']) ? $data[$prefix.'ErrorCode'] : false)) {
throw new Exception(Messages::getByCode($error) ?: '', (int)$error);
}
}

Expand All @@ -364,11 +356,7 @@ private function checkTransactionResponse(array $data, $prefix)
$value = (int)$response;

if (($value < 0) || (($value > 99) && ($value !== 900))) {
if ($message = Messages::getByCode($response)) {
throw new Exception(sprintf('Response code is Transaction Denied %s: %s', $response, $message['message']));
} else {
throw new Exception(sprintf('Response code is unknown %s', $response));
}
throw new Exception(Messages::getByCode($response) ?: '', $value);
}
}

Expand Down

0 comments on commit 2823775

Please sign in to comment.