Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Payment_Block_Catalog_Product_View_Profile
  • Mage_Payment_Block_Form
  • Mage_Payment_Block_Form_Banktransfer
  • Mage_Payment_Block_Form_Cashondelivery
  • Mage_Payment_Block_Form_Cc
  • Mage_Payment_Block_Form_Ccsave
  • Mage_Payment_Block_Form_Checkmo
  • Mage_Payment_Block_Form_Container
  • Mage_Payment_Block_Form_Purchaseorder
  • Mage_Payment_Block_Info
  • Mage_Payment_Block_Info_Banktransfer
  • Mage_Payment_Block_Info_Cc
  • Mage_Payment_Block_Info_Ccsave
  • Mage_Payment_Block_Info_Checkmo
  • Mage_Payment_Block_Info_Container
  • Mage_Payment_Block_Info_Purchaseorder
  • Mage_Payment_Helper_Data
  • Mage_Payment_Model_Billing_AgreementAbstract
  • Mage_Payment_Model_Config
  • Mage_Payment_Model_Info
  • Mage_Payment_Model_Method_Abstract
  • Mage_Payment_Model_Method_Banktransfer
  • Mage_Payment_Model_Method_Cashondelivery
  • Mage_Payment_Model_Method_Cc
  • Mage_Payment_Model_Method_Ccsave
  • Mage_Payment_Model_Method_Checkmo
  • Mage_Payment_Model_Method_Free
  • Mage_Payment_Model_Method_Purchaseorder
  • Mage_Payment_Model_Observer
  • Mage_Payment_Model_Paygate_Result
  • Mage_Payment_Model_Recurring_Profile
  • Mage_Payment_Model_Source_Cctype
  • Mage_Payment_Model_Source_Invoice

Interfaces

  • Mage_Payment_Model_Billing_Agreement_MethodInterface
  • Mage_Payment_Model_Recurring_Profile_MethodInterface

Exceptions

  • Mage_Payment_Exception
  • Mage_Payment_Model_Info_Exception
  • Overview
  • Package
  • Class
  • Tree
  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:  * Payment module base helper
 29:  *
 30:  * @author      Magento Core Team <core@magentocommerce.com>
 31:  */
 32: class Mage_Payment_Helper_Data extends Mage_Core_Helper_Abstract
 33: {
 34:     const XML_PATH_PAYMENT_METHODS = 'payment';
 35:     const XML_PATH_PAYMENT_GROUPS = 'global/payment/groups';
 36: 
 37:     /**
 38:      * Retrieve method model object
 39:      *
 40:      * @param   string $code
 41:      * @return  Mage_Payment_Model_Method_Abstract|false
 42:      */
 43:     public function getMethodInstance($code)
 44:     {
 45:         $key = self::XML_PATH_PAYMENT_METHODS.'/'.$code.'/model';
 46:         $class = Mage::getStoreConfig($key);
 47:         return Mage::getModel($class);
 48:     }
 49: 
 50:     /**
 51:      * Get and sort available payment methods for specified or current store
 52:      *
 53:      * array structure:
 54:      *  $index => Varien_Simplexml_Element
 55:      *
 56:      * @param mixed $store
 57:      * @param Mage_Sales_Model_Quote $quote
 58:      * @return array
 59:      */
 60:     public function getStoreMethods($store = null, $quote = null)
 61:     {
 62:         $res = array();
 63:         foreach ($this->getPaymentMethods($store) as $code => $methodConfig) {
 64:             $prefix = self::XML_PATH_PAYMENT_METHODS . '/' . $code . '/';
 65:             if (!$model = Mage::getStoreConfig($prefix . 'model', $store)) {
 66:                 continue;
 67:             }
 68:             $methodInstance = Mage::getModel($model);
 69:             if (!$methodInstance) {
 70:                 continue;
 71:             }
 72:             $methodInstance->setStore($store);
 73:             if (!$methodInstance->isAvailable($quote)) {
 74:                 /* if the payment method cannot be used at this time */
 75:                 continue;
 76:             }
 77:             $sortOrder = (int)$methodInstance->getConfigData('sort_order', $store);
 78:             $methodInstance->setSortOrder($sortOrder);
 79:             $res[] = $methodInstance;
 80:         }
 81: 
 82:         usort($res, array($this, '_sortMethods'));
 83:         return $res;
 84:     }
 85: 
 86:     protected function _sortMethods($a, $b)
 87:     {
 88:         if (is_object($a)) {
 89:             return (int)$a->sort_order < (int)$b->sort_order ? -1 : ((int)$a->sort_order > (int)$b->sort_order ? 1 : 0);
 90:         }
 91:         return 0;
 92:     }
 93: 
 94:     /**
 95:      * Retreive payment method form html
 96:      *
 97:      * @param   Mage_Payment_Model_Abstract $method
 98:      * @return  Mage_Payment_Block_Form
 99:      */
100:     public function getMethodFormBlock(Mage_Payment_Model_Method_Abstract $method)
101:     {
102:         $block = false;
103:         $blockType = $method->getFormBlockType();
104:         if ($this->getLayout()) {
105:             $block = $this->getLayout()->createBlock($blockType);
106:             $block->setMethod($method);
107:         }
108:         return $block;
109:     }
110: 
111:     /**
112:      * Retrieve payment information block
113:      *
114:      * @param   Mage_Payment_Model_Info $info
115:      * @return  Mage_Core_Block_Template
116:      */
117:     public function getInfoBlock(Mage_Payment_Model_Info $info)
118:     {
119:         $blockType = $info->getMethodInstance()->getInfoBlockType();
120:         if ($this->getLayout()) {
121:             $block = $this->getLayout()->createBlock($blockType);
122:         }
123:         else {
124:             $className = Mage::getConfig()->getBlockClassName($blockType);
125:             $block = new $className;
126:         }
127:         $block->setInfo($info);
128:         return $block;
129:     }
130: 
131:     /**
132:      * Retrieve available billing agreement methods
133:      *
134:      * @param mixed $store
135:      * @param Mage_Sales_Model_Quote $quote
136:      * @return array
137:      */
138:     public function getBillingAgreementMethods($store = null, $quote = null)
139:     {
140:         $result = array();
141:         foreach ($this->getStoreMethods($store, $quote) as $method) {
142:             if ($method->canManageBillingAgreements()) {
143:                 $result[] = $method;
144:             }
145:         }
146:         return $result;
147:     }
148: 
149:     /**
150:      * Get payment methods that implement recurring profilez management
151:      *
152:      * @param mixed $store
153:      * @return array
154:      */
155:     public function getRecurringProfileMethods($store = null)
156:     {
157:         $result = array();
158:         foreach ($this->getPaymentMethods($store) as $code => $data) {
159:             $method = $this->getMethodInstance($code);
160:             if ($method && $method->canManageRecurringProfiles()) {
161:                 $result[] = $method;
162:             }
163:         }
164:         return $result;
165:     }
166: 
167:     /**
168:      * Retrieve all payment methods
169:      *
170:      * @param mixed $store
171:      * @return array
172:      */
173:     public function getPaymentMethods($store = null)
174:     {
175:         return Mage::getStoreConfig(self::XML_PATH_PAYMENT_METHODS, $store);
176:     }
177: 
178:     /**
179:      * Retrieve all payment methods list as an array
180:      *
181:      * Possible output:
182:      * 1) assoc array as <code> => <title>
183:      * 2) array of array('label' => <title>, 'value' => <code>)
184:      * 3) array of array(
185:      *                 array('value' => <code>, 'label' => <title>),
186:      *                 array('value' => array(
187:      *                     'value' => array(array(<code1> => <title1>, <code2> =>...),
188:      *                     'label' => <group name>
189:      *                 )),
190:      *                 array('value' => <code>, 'label' => <title>),
191:      *                 ...
192:      *             )
193:      *
194:      * @param bool $sorted
195:      * @param bool $asLabelValue
196:      * @param bool $withGroups
197:      * @return array
198:      */
199:     public function getPaymentMethodList($sorted = true, $asLabelValue = false, $withGroups = false, $store = null)
200:     {
201:         $methods = array();
202:         $groups = array();
203:         $groupRelations = array();
204: 
205:         foreach ($this->getPaymentMethods($store) as $code => $data) {
206:             if ((isset($data['title']))) {
207:                 $methods[$code] = $data['title'];
208:             } else {
209:                 if ($this->getMethodInstance($code)) {
210:                     $methods[$code] = $this->getMethodInstance($code)->getConfigData('title', $store);
211:                 }
212:             }
213:             if ($asLabelValue && $withGroups && isset($data['group'])) {
214:                 $groupRelations[$code] = $data['group'];
215:             }
216:         }
217:         if ($asLabelValue && $withGroups) {
218:             $groups = Mage::app()->getConfig()->getNode(self::XML_PATH_PAYMENT_GROUPS)->asCanonicalArray();
219:             foreach ($groups as $code => $title) {
220:                 $methods[$code] = $title; // for sorting, see below
221:             }
222:         }
223:         if ($sorted) {
224:             asort($methods);
225:         }
226:         if ($asLabelValue) {
227:             $labelValues = array();
228:             foreach ($methods as $code => $title) {
229:                 $labelValues[$code] = array();
230:             }
231:             foreach ($methods as $code => $title) {
232:                 if (isset($groups[$code])) {
233:                     $labelValues[$code]['label'] = $title;
234:                 } elseif (isset($groupRelations[$code])) {
235:                     unset($labelValues[$code]);
236:                     $labelValues[$groupRelations[$code]]['value'][$code] = array('value' => $code, 'label' => $title);
237:                 } else {
238:                     $labelValues[$code] = array('value' => $code, 'label' => $title);
239:                 }
240:             }
241:             return $labelValues;
242:         }
243: 
244:         return $methods;
245:     }
246: 
247:     /**
248:      * Retrieve all billing agreement methods (code and label)
249:      *
250:      * @return array
251:      */
252:     public function getAllBillingAgreementMethods()
253:     {
254:         $result = array();
255:         $interface = 'Mage_Payment_Model_Billing_Agreement_MethodInterface';
256:         foreach ($this->getPaymentMethods() as $code => $data) {
257:             if (!isset($data['model'])) {
258:                 continue;
259:             }
260:             $method = Mage::app()->getConfig()->getModelClassName($data['model']);
261:             if (in_array($interface, class_implements($method))) {
262:                 $result[$code] = $data['title'];
263:             }
264:         }
265:         return $result;
266:     }
267: 
268:     /**
269:      * Returns value of Zero Subtotal Checkout / Enabled
270:      *
271:      * @param mixed $store
272:      * @return boolean
273:      */
274:     public function isZeroSubTotal($store = null)
275:     {
276:         return Mage::getStoreConfig(Mage_Payment_Model_Method_Free::XML_PATH_PAYMENT_FREE_ACTIVE, $store);
277:     }
278: 
279:     /**
280:      * Returns value of Zero Subtotal Checkout / New Order Status
281:      *
282:      * @param mixed $store
283:      * @return string
284:      */
285:     public function getZeroSubTotalOrderStatus($store = null)
286:     {
287:         return Mage::getStoreConfig(Mage_Payment_Model_Method_Free::XML_PATH_PAYMENT_FREE_ORDER_STATUS, $store);
288:     }
289: 
290:     /**
291:      * Returns value of Zero Subtotal Checkout / Automatically Invoice All Items
292:      *
293:      * @param mixed $store
294:      * @return string
295:      */
296:     public function getZeroSubTotalPaymentAutomaticInvoice($store = null)
297:     {
298:         return Mage::getStoreConfig(Mage_Payment_Model_Method_Free::XML_PATH_PAYMENT_FREE_PAYMENT_ACTION, $store);
299:     }
300: }
301: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0