Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Info.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Payment\Model;
7 
9 
16 class Info extends AbstractExtensibleModel implements InfoInterface
17 {
23  protected $_additionalInformation = [];
24 
30  protected $_paymentData;
31 
35  protected $_encryptor;
36 
48  public function __construct(
49  \Magento\Framework\Model\Context $context,
50  \Magento\Framework\Registry $registry,
51  \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
52  \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory,
53  \Magento\Payment\Helper\Data $paymentData,
54  \Magento\Framework\Encryption\EncryptorInterface $encryptor,
55  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
56  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
57  array $data = []
58  ) {
59  $this->_paymentData = $paymentData;
60  $this->_encryptor = $encryptor;
61  parent::__construct(
62  $context,
63  $registry,
64  $extensionFactory,
66  $resource,
67  $resourceCollection,
68  $data
69  );
70  }
71 
79  public function getData($key = '', $index = null)
80  {
81  if ('cc_number' === $key) {
82  if (empty($this->_data['cc_number']) && !empty($this->_data['cc_number_enc'])) {
83  $this->_data['cc_number'] = $this->decrypt($this->getCcNumberEnc());
84  }
85  }
86  if ('cc_cid' === $key) {
87  if (empty($this->_data['cc_cid']) && !empty($this->_data['cc_cid_enc'])) {
88  $this->_data['cc_cid'] = $this->decrypt($this->getCcCidEnc());
89  }
90  }
91  return parent::getData($key, $index);
92  }
93 
100  public function getMethodInstance()
101  {
102  if (!$this->hasMethodInstance()) {
103  if (!$this->getMethod()) {
104  throw new \Magento\Framework\Exception\LocalizedException(
105  __('The payment method you requested is not available.')
106  );
107  }
108 
109  try {
110  $instance = $this->_paymentData->getMethodInstance($this->getMethod());
111  } catch (\UnexpectedValueException $e) {
112  $instance = $this->_paymentData->getMethodInstance(Method\Substitution::CODE);
113  }
114 
115  $instance->setInfoInstance($this);
116  $this->setMethodInstance($instance);
117  }
118 
119  return $this->_getData('method_instance');
120  }
121 
128  public function encrypt($data)
129  {
130  return $this->_encryptor->encrypt($data);
131  }
132 
139  public function decrypt($data)
140  {
141  return $this->_encryptor->decrypt($data);
142  }
143 
154  public function setAdditionalInformation($key, $value = null)
155  {
156  if (is_object($value)) {
157  throw new \Magento\Framework\Exception\LocalizedException(__('The payment disallows storing objects.'));
158  }
160  if (is_array($key) && $value === null) {
161  $this->_additionalInformation = $key;
162  } else {
163  $this->_additionalInformation[$key] = $value;
164  }
165  return $this->setData('additional_information', $this->_additionalInformation);
166  }
167 
174  public function getAdditionalInformation($key = null)
175  {
177  if (null === $key) {
179  }
180  return isset($this->_additionalInformation[$key]) ? $this->_additionalInformation[$key] : null;
181  }
182 
189  public function unsAdditionalInformation($key = null)
190  {
191  if ($key && isset($this->_additionalInformation[$key])) {
192  unset($this->_additionalInformation[$key]);
193  return $this->setData('additional_information', $this->_additionalInformation);
194  } elseif (null === $key) {
195  $this->_additionalInformation = [];
196  return $this->unsetData('additional_information');
197  }
198 
199  return $this;
200  }
201 
208  public function hasAdditionalInformation($key = null)
209  {
211  return null === $key ? !empty($this->_additionalInformation) : array_key_exists(
212  $key,
213  $this->_additionalInformation
214  );
215  }
216 
222  protected function _initAdditionalInformation()
223  {
224  $additionalInfo = $this->_getData('additional_information');
225  if (empty($this->_additionalInformation) && $additionalInfo) {
226  $this->_additionalInformation = $additionalInfo;
227  }
228  }
229 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13
getData($key='', $index=null)
Definition: Info.php:79
$resource
Definition: bulk.php:12
unsAdditionalInformation($key=null)
Definition: Info.php:189
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory, \Magento\Payment\Helper\Data $paymentData, \Magento\Framework\Encryption\EncryptorInterface $encryptor, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
Definition: Info.php:48
$value
Definition: gender.phtml:16
setAdditionalInformation($key, $value=null)
Definition: Info.php:154
hasAdditionalInformation($key=null)
Definition: Info.php:208
getAdditionalInformation($key=null)
Definition: Info.php:174
$index
Definition: list.phtml:44