1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Payment
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Base payment iformation block
29: *
30: */
31: class Mage_Payment_Block_Info extends Mage_Core_Block_Template
32: {
33: /**
34: * Payment rendered specific information
35: *
36: * @var Varien_Object
37: */
38: protected $_paymentSpecificInformation = null;
39:
40: protected function _construct()
41: {
42: parent::_construct();
43: $this->setTemplate('payment/info/default.phtml');
44: }
45:
46: /**
47: * Retrieve info model
48: *
49: * @return Mage_Payment_Model_Info
50: */
51: public function getInfo()
52: {
53: $info = $this->getData('info');
54: if (!($info instanceof Mage_Payment_Model_Info)) {
55: Mage::throwException($this->__('Cannot retrieve the payment info model object.'));
56: }
57: return $info;
58: }
59:
60: /**
61: * Retrieve payment method model
62: *
63: * @return Mage_Payment_Model_Method_Abstract
64: */
65: public function getMethod()
66: {
67: return $this->getInfo()->getMethodInstance();
68: }
69:
70: /**
71: * Render as PDF
72: * @return string
73: */
74: public function toPdf()
75: {
76: $this->setTemplate('payment/info/pdf/default.phtml');
77: return $this->toHtml();
78: }
79:
80: /**
81: * Getter for children PDF, as array. Analogue of $this->getChildHtml()
82: *
83: * Children must have toPdf() callable
84: * Known issue: not sorted
85: * @return array
86: */
87: public function getChildPdfAsArray()
88: {
89: $result = array();
90: foreach ($this->getChild() as $child) {
91: if (is_callable(array($child, 'toPdf'))) {
92: $result[] = $child->toPdf();
93: }
94: }
95: return $result;
96: }
97:
98: /**
99: * Get some specific information in format of array($label => $value)
100: *
101: * @return array
102: */
103: public function getSpecificInformation()
104: {
105: return $this->_prepareSpecificInformation()->getData();
106: }
107:
108: /**
109: * Render the value as an array
110: *
111: * @param mixed $value
112: * @param bool $escapeHtml
113: * @return $array
114: */
115: public function getValueAsArray($value, $escapeHtml = false)
116: {
117: if (empty($value)) {
118: return array();
119: }
120: if (!is_array($value)) {
121: $value = array($value);
122: }
123: if ($escapeHtml) {
124: foreach ($value as $_key => $_val) {
125: $value[$_key] = $this->escapeHtml($_val);
126: }
127: }
128: return $value;
129: }
130:
131: /**
132: * Check whether payment information should show up in secure mode
133: * true => only "public" payment information may be shown
134: * false => full information may be shown
135: *
136: * @return bool
137: */
138: public function getIsSecureMode()
139: {
140: if ($this->hasIsSecureMode()) {
141: return (bool)(int)$this->_getData('is_secure_mode');
142: }
143: if (!$payment = $this->getInfo()) {
144: return true;
145: }
146: if (!$method = $payment->getMethodInstance()) {
147: return true;
148: }
149: return !Mage::app()->getStore($method->getStore())->isAdmin();
150: }
151:
152: /**
153: * Prepare information specific to current payment method
154: *
155: * @param Varien_Object|array $transport
156: * @return Varien_Object
157: */
158: protected function _prepareSpecificInformation($transport = null)
159: {
160: if (null === $this->_paymentSpecificInformation) {
161: if (null === $transport) {
162: $transport = new Varien_Object;
163: } elseif (is_array($transport)) {
164: $transport = new Varien_Object($transport);
165: }
166: Mage::dispatchEvent('payment_info_block_prepare_specific_information', array(
167: 'transport' => $transport,
168: 'payment' => $this->getInfo(),
169: 'block' => $this,
170: ));
171: $this->_paymentSpecificInformation = $transport;
172: }
173: return $this->_paymentSpecificInformation;
174: }
175: }
176: