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