ErrorCodeProvider.php 966 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Braintree\Gateway\Validator;
  8. use Braintree\Error\ErrorCollection;
  9. use Braintree\Error\Validation;
  10. use Braintree\Result\Error;
  11. use Braintree\Result\Successful;
  12. /**
  13. * Processes errors codes from Braintree response.
  14. */
  15. class ErrorCodeProvider
  16. {
  17. /**
  18. * Retrieves list of error codes from Braintree response.
  19. *
  20. * @param Successful|Error $response
  21. * @return array
  22. */
  23. public function getErrorCodes($response): array
  24. {
  25. $result = [];
  26. if (!$response instanceof Error) {
  27. return $result;
  28. }
  29. /** @var ErrorCollection $collection */
  30. $collection = $response->errors;
  31. /** @var Validation $error */
  32. foreach ($collection->deepAll() as $error) {
  33. $result[] = $error->code;
  34. }
  35. return $result;
  36. }
  37. }