ErrorMessageMapper.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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\Payment\Gateway\ErrorMapper;
  8. use Magento\Framework\Config\DataInterface;
  9. /**
  10. * This class can be used for payment integrations which can validate different type of
  11. * error messages per one request.
  12. * For example, during authorization payment operation the payment integration can validate error messages
  13. * related to credit card details and customer address data.
  14. * In that case, this implementation can be extended via di.xml and configured with appropriate mappers.
  15. *
  16. * @api
  17. * @since 100.2.2
  18. */
  19. class ErrorMessageMapper implements ErrorMessageMapperInterface
  20. {
  21. /**
  22. * @var DataInterface
  23. */
  24. private $messageMapping;
  25. /**
  26. * @param DataInterface $messageMapping
  27. */
  28. public function __construct(DataInterface $messageMapping)
  29. {
  30. $this->messageMapping = $messageMapping;
  31. }
  32. /**
  33. * @inheritdoc
  34. * @since 100.2.2
  35. */
  36. public function getMessage(string $code)
  37. {
  38. $message = $this->messageMapping->get($code);
  39. return $message ? __($message) : null;
  40. }
  41. }