123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Payment\Block;
- /**
- * Base payment information block
- *
- * @api
- * @since 100.0.2
- */
- class Info extends \Magento\Framework\View\Element\Template
- {
- /**
- * Payment rendered specific information
- *
- * @var \Magento\Framework\DataObject
- */
- protected $_paymentSpecificInformation;
- /**
- * @var string
- */
- protected $_template = 'Magento_Payment::info/default.phtml';
- /**
- * Retrieve info model
- *
- * @return \Magento\Payment\Model\InfoInterface
- * @throws \Magento\Framework\Exception\LocalizedException
- */
- public function getInfo()
- {
- $info = $this->getData('info');
- if (!$info instanceof \Magento\Payment\Model\InfoInterface) {
- throw new \Magento\Framework\Exception\LocalizedException(
- __('We cannot retrieve the payment info model object.')
- );
- }
- return $info;
- }
- /**
- * Retrieve payment method model
- *
- * @return \Magento\Payment\Model\MethodInterface
- */
- public function getMethod()
- {
- return $this->getInfo()->getMethodInstance();
- }
- /**
- * Render as PDF
- * @return string
- */
- public function toPdf()
- {
- $this->setTemplate('Magento_Payment::info/pdf/default.phtml');
- return $this->toHtml();
- }
- /**
- * Getter for children PDF, as array. Analogue of $this->getChildHtml()
- *
- * Children must have toPdf() callable
- * Known issue: not sorted
- * @return array
- */
- public function getChildPdfAsArray()
- {
- $result = [];
- foreach ($this->getLayout()->getChildBlocks($this->getNameInLayout()) as $child) {
- if (method_exists($child, 'toPdf') && is_callable([$child, 'toPdf'])) {
- $result[] = $child->toPdf();
- }
- }
- return $result;
- }
- /**
- * Get some specific information in format of array($label => $value)
- *
- * @return array
- */
- public function getSpecificInformation()
- {
- return $this->_prepareSpecificInformation()->getData();
- }
- /**
- * Render the value as an array
- *
- * @param mixed $value
- * @param bool $escapeHtml
- * @return array
- */
- public function getValueAsArray($value, $escapeHtml = false)
- {
- if (empty($value)) {
- return [];
- }
- if (!is_array($value)) {
- $value = [$value];
- }
- if ($escapeHtml) {
- foreach ($value as $_key => $_val) {
- $value[$_key] = $this->escapeHtml($_val);
- }
- }
- return $value;
- }
- /**
- * Check whether payment information should show up in secure mode
- * true => only "public" payment information may be shown
- * false => full information may be shown
- *
- * @return bool
- * @SuppressWarnings(PHPMD.BooleanGetMethodName)
- */
- public function getIsSecureMode()
- {
- if ($this->hasIsSecureMode()) {
- return (bool)(int)$this->_getData('is_secure_mode');
- }
- $method = $this->getMethod();
- if (!$method) {
- return true;
- }
- $store = $method->getStore();
- if (!$store) {
- return false;
- }
- $methodStore = $this->_storeManager->getStore($store);
- return $methodStore->getCode() != \Magento\Store\Model\Store::ADMIN_CODE;
- }
- /**
- * Prepare information specific to current payment method
- *
- * @param null|\Magento\Framework\DataObject|array $transport
- * @return \Magento\Framework\DataObject
- */
- protected function _prepareSpecificInformation($transport = null)
- {
- if (null === $this->_paymentSpecificInformation) {
- if (null === $transport) {
- $transport = new \Magento\Framework\DataObject();
- } elseif (is_array($transport)) {
- $transport = new \Magento\Framework\DataObject($transport);
- }
- $this->_paymentSpecificInformation = $transport;
- }
- return $this->_paymentSpecificInformation;
- }
- }
|