ConfigurableInfo.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Block;
  7. use Magento\Framework\Phrase;
  8. use Magento\Framework\View\Element\Template\Context;
  9. use Magento\Payment\Gateway\ConfigInterface;
  10. /**
  11. * Class ConfigurableInfo
  12. * @api
  13. * @since 100.0.2
  14. */
  15. class ConfigurableInfo extends \Magento\Payment\Block\Info
  16. {
  17. /**
  18. * @var ConfigInterface
  19. */
  20. private $config;
  21. /**
  22. * @param Context $context
  23. * @param ConfigInterface $config
  24. * @param array $data
  25. */
  26. public function __construct(
  27. Context $context,
  28. ConfigInterface $config,
  29. array $data = []
  30. ) {
  31. parent::__construct($context, $data);
  32. $this->config = $config;
  33. if (isset($data['pathPattern'])) {
  34. $this->config->setPathPattern($data['pathPattern']);
  35. }
  36. if (isset($data['methodCode'])) {
  37. $this->config->setMethodCode($data['methodCode']);
  38. }
  39. }
  40. /**
  41. * Prepare payment information
  42. *
  43. * @param \Magento\Framework\DataObject|array|null $transport
  44. * @return \Magento\Framework\DataObject
  45. */
  46. protected function _prepareSpecificInformation($transport = null)
  47. {
  48. $transport = parent::_prepareSpecificInformation($transport);
  49. $payment = $this->getInfo();
  50. $storedFields = explode(',', (string)$this->config->getValue('paymentInfoKeys'));
  51. if ($this->getIsSecureMode()) {
  52. $storedFields = array_diff(
  53. $storedFields,
  54. explode(',', (string)$this->config->getValue('privateInfoKeys'))
  55. );
  56. }
  57. foreach ($storedFields as $field) {
  58. if ($payment->getAdditionalInformation($field) !== null) {
  59. $this->setDataToTransfer(
  60. $transport,
  61. $field,
  62. $payment->getAdditionalInformation($field)
  63. );
  64. }
  65. }
  66. return $transport;
  67. }
  68. /**
  69. * Sets data to transport
  70. *
  71. * @param \Magento\Framework\DataObject $transport
  72. * @param string $field
  73. * @param string $value
  74. * @return void
  75. */
  76. protected function setDataToTransfer(
  77. \Magento\Framework\DataObject $transport,
  78. $field,
  79. $value
  80. ) {
  81. $transport->setData(
  82. (string)$this->getLabel($field),
  83. (string)$this->getValueView(
  84. $field,
  85. $value
  86. )
  87. );
  88. }
  89. /**
  90. * Returns label
  91. *
  92. * @param string $field
  93. * @return string | Phrase
  94. */
  95. protected function getLabel($field)
  96. {
  97. return $field;
  98. }
  99. /**
  100. * Returns value view
  101. *
  102. * @param string $field
  103. * @param string $value
  104. * @return string | Phrase
  105. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  106. */
  107. protected function getValueView($field, $value)
  108. {
  109. return $value;
  110. }
  111. }