Skip to content

Commit

Permalink
[ECP-9506] Fix response handling of non-200 http status codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Can Demiralp committed Oct 3, 2024
1 parent c3be66f commit 371562b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Gateway/Http/Client/TransactionPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ public function placeRequest(TransferInterface $transferObject): array
$this->adyenHelper->logResponse($responseData);
} catch (AdyenException $e) {
$this->adyenHelper->logAdyenException($e);

$responseObj['error'] = $e->getMessage();
$responseObj['errorCode'] = $e->getAdyenErrorCode();

$responseCollection[] = $responseObj;
}

return $responseCollection;
Expand Down
9 changes: 6 additions & 3 deletions Gateway/Validator/CheckoutResponseValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,17 @@ public function validate(array $validationSubject): ResultInterface
// Extract all the payment responses
$responseCollection = $validationSubject['response'];
unset($validationSubject['response']);

// hasOnlyGiftCards is needed later but cannot be processed as a response
unset($responseCollection['hasOnlyGiftCards']);

// Assign the remaining items to $commandSubject
$commandSubject = $validationSubject;

if (empty($responseCollection)) {
throw new ValidatorException(__("No responses were provided"));
}

// hasOnlyGiftCards is needed later but cannot be processed as a response
unset($responseCollection['hasOnlyGiftCards']);
foreach ($responseCollection as $thisResponse) {
$responseSubject = array_merge($commandSubject, ['response' => $thisResponse]);
$this->validateResponse($responseSubject);
Expand All @@ -90,11 +92,12 @@ private function validateResponse($responseSubject): void

$payment->setAdditionalInformation('3dActive', false);

// validate result
// Handle empty result for unexpected cases
if (empty($response['resultCode'])) {
$this->handleEmptyResultCode($response);
}

// Handle the `/payments` response
$this->validateResult($response, $payment);
}

Expand Down

0 comments on commit 371562b

Please sign in to comment.