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_Checkout_Block_Agreements
  • Mage_Checkout_Block_Cart
  • Mage_Checkout_Block_Cart_Abstract
  • Mage_Checkout_Block_Cart_Coupon
  • Mage_Checkout_Block_Cart_Crosssell
  • Mage_Checkout_Block_Cart_Item_Configure
  • Mage_Checkout_Block_Cart_Item_Renderer
  • Mage_Checkout_Block_Cart_Item_Renderer_Configurable
  • Mage_Checkout_Block_Cart_Item_Renderer_Grouped
  • Mage_Checkout_Block_Cart_Shipping
  • Mage_Checkout_Block_Cart_Sidebar
  • Mage_Checkout_Block_Cart_Totals
  • Mage_Checkout_Block_Links
  • Mage_Checkout_Block_Multishipping_Abstract
  • Mage_Checkout_Block_Multishipping_Address_Select
  • Mage_Checkout_Block_Multishipping_Addresses
  • Mage_Checkout_Block_Multishipping_Billing
  • Mage_Checkout_Block_Multishipping_Billing_Items
  • Mage_Checkout_Block_Multishipping_Link
  • Mage_Checkout_Block_Multishipping_Overview
  • Mage_Checkout_Block_Multishipping_Payment_Info
  • Mage_Checkout_Block_Multishipping_Shipping
  • Mage_Checkout_Block_Multishipping_State
  • Mage_Checkout_Block_Multishipping_Success
  • Mage_Checkout_Block_Onepage
  • Mage_Checkout_Block_Onepage_Abstract
  • Mage_Checkout_Block_Onepage_Billing
  • Mage_Checkout_Block_Onepage_Failure
  • Mage_Checkout_Block_Onepage_Link
  • Mage_Checkout_Block_Onepage_Login
  • Mage_Checkout_Block_Onepage_Payment
  • Mage_Checkout_Block_Onepage_Payment_Info
  • Mage_Checkout_Block_Onepage_Payment_Methods
  • Mage_Checkout_Block_Onepage_Progress
  • Mage_Checkout_Block_Onepage_Review
  • Mage_Checkout_Block_Onepage_Review_Info
  • Mage_Checkout_Block_Onepage_Shipping
  • Mage_Checkout_Block_Onepage_Shipping_Method
  • Mage_Checkout_Block_Onepage_Shipping_Method_Additional
  • Mage_Checkout_Block_Onepage_Shipping_Method_Available
  • Mage_Checkout_Block_Onepage_Success
  • Mage_Checkout_Block_Success
  • Mage_Checkout_Block_Total_Default
  • Mage_Checkout_Block_Total_Nominal
  • Mage_Checkout_Block_Total_Tax
  • Mage_Checkout_CartController
  • Mage_Checkout_Controller_Action
  • Mage_Checkout_Exception
  • Mage_Checkout_Helper_Cart
  • Mage_Checkout_Helper_Data
  • Mage_Checkout_Helper_Url
  • Mage_Checkout_IndexController
  • Mage_Checkout_Model_Agreement
  • Mage_Checkout_Model_Api_Resource
  • Mage_Checkout_Model_Api_Resource_Customer
  • Mage_Checkout_Model_Api_Resource_Product
  • Mage_Checkout_Model_Cart
  • Mage_Checkout_Model_Cart_Api
  • Mage_Checkout_Model_Cart_Api_V2
  • Mage_Checkout_Model_Cart_Coupon_Api
  • Mage_Checkout_Model_Cart_Coupon_Api_V2
  • Mage_Checkout_Model_Cart_Customer_Api
  • Mage_Checkout_Model_Cart_Customer_Api_V2
  • Mage_Checkout_Model_Cart_Payment_Api
  • Mage_Checkout_Model_Cart_Payment_Api_V2
  • Mage_Checkout_Model_Cart_Product_Api
  • Mage_Checkout_Model_Cart_Product_Api_V2
  • Mage_Checkout_Model_Cart_Shipping_Api
  • Mage_Checkout_Model_Cart_Shipping_Api_V2
  • Mage_Checkout_Model_Config_Source_Cart_Summary
  • Mage_Checkout_Model_Mysql4_Agreement
  • Mage_Checkout_Model_Mysql4_Agreement_Collection
  • Mage_Checkout_Model_Mysql4_Cart
  • Mage_Checkout_Model_Mysql4_Setup
  • Mage_Checkout_Model_Observer
  • Mage_Checkout_Model_Resource_Agreement
  • Mage_Checkout_Model_Resource_Agreement_Collection
  • Mage_Checkout_Model_Resource_Cart
  • Mage_Checkout_Model_Resource_Setup
  • Mage_Checkout_Model_Session
  • Mage_Checkout_Model_Type_Abstract
  • Mage_Checkout_Model_Type_Multishipping
  • Mage_Checkout_Model_Type_Multishipping_State
  • Mage_Checkout_Model_Type_Onepage
  • Mage_Checkout_Multishipping_AddressController
  • Mage_Checkout_MultishippingController
  • Mage_Checkout_OnepageController

Interfaces

  • Mage_Checkout_Model_Cart_Interface
  • 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_Checkout
 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:  * Shopping cart api
 29:  *
 30:  * @category    Mage
 31:  * @package     Mage_Checkout
 32:  * @author      Magento Core Team <core@magentocommerce.com>
 33:  */
 34: 
 35: class Mage_Checkout_Model_Cart_Payment_Api extends Mage_Checkout_Model_Api_Resource
 36: {
 37: 
 38:     protected function _preparePaymentData($data)
 39:     {
 40:         if (!(is_array($data) && is_null($data[0]))) {
 41:             return array();
 42:         }
 43: 
 44:         return $data;
 45:     }
 46: 
 47:     /**
 48:      * @param  $method
 49:      * @param  $quote
 50:      * @return bool
 51:      */
 52:     protected function _canUsePaymentMethod($method, $quote)
 53:     {
 54:         if ( !($method->isGateway() || $method->canUseInternal()) ) {
 55:             return false;
 56:         }
 57: 
 58:         if (!$method->canUseForCountry($quote->getBillingAddress()->getCountry())) {
 59:             return false;
 60:         }
 61: 
 62:         if (!$method->canUseForCurrency(Mage::app()->getStore($quote->getStoreId())->getBaseCurrencyCode())) {
 63:             return false;
 64:         }
 65: 
 66:         /**
 67:          * Checking for min/max order total for assigned payment method
 68:          */
 69:         $total = $quote->getBaseGrandTotal();
 70:         $minTotal = $method->getConfigData('min_order_total');
 71:         $maxTotal = $method->getConfigData('max_order_total');
 72: 
 73:         if ((!empty($minTotal) && ($total < $minTotal)) || (!empty($maxTotal) && ($total > $maxTotal))) {
 74:             return false;
 75:         }
 76: 
 77:         return true;
 78:     }
 79: 
 80:     protected function _getPaymentMethodAvailableCcTypes($method)
 81:     {
 82:         $ccTypes = Mage::getSingleton('payment/config')->getCcTypes();
 83:         $methodCcTypes = explode(',',$method->getConfigData('cctypes'));
 84:         foreach ($ccTypes as $code=>$title) {
 85:             if (!in_array($code, $methodCcTypes)) {
 86:                 unset($ccTypes[$code]);
 87:             }
 88:         }
 89:         if (empty($ccTypes)) {
 90:             return null;
 91:         }
 92: 
 93:         return $ccTypes;
 94:     }
 95: 
 96:     /**
 97:      * @param  $quoteId
 98:      * @param  $store
 99:      * @return array
100:      */
101:     public function getPaymentMethodsList($quoteId, $store=null)
102:     {
103:         $quote = $this->_getQuote($quoteId, $store);
104:         $store = $quote->getStoreId();
105: 
106:         $total = $quote->getBaseSubtotal();
107: 
108:         $methodsResult = array();
109:         $methods = Mage::helper('payment')->getStoreMethods($store, $quote);
110:         foreach ($methods as $key=>$method) {
111:             /** @var $method Mage_Payment_Model_Method_Abstract */
112:             if ($this->_canUsePaymentMethod($method, $quote)
113:                     && ($total != 0
114:                         || $method->getCode() == 'free'
115:                         || ($quote->hasRecurringItems() && $method->canManageRecurringProfiles()))) {
116:                 $methodsResult[] =
117:                         array(
118:                             "code" => $method->getCode(),
119:                             "title" => $method->getTitle(),
120:                             "ccTypes" => $this->_getPaymentMethodAvailableCcTypes($method)
121:                         );
122:             }
123:         }
124: 
125:         return $methodsResult;
126:     }
127: 
128:     /**
129:      * @param  $quoteId
130:      * @param  $paymentData
131:      * @param  $store
132:      * @return bool
133:      */
134:     public function setPaymentMethod($quoteId, $paymentData, $store=null)
135:     {
136:         $quote = $this->_getQuote($quoteId, $store);
137:         $store = $quote->getStoreId();
138: 
139:         $paymentData = $this->_preparePaymentData($paymentData);
140: 
141:         if (empty($paymentData)) {
142:             $this->_fault("payment_method_empty");
143:         }
144: 
145:         if ($quote->isVirtual()) {
146:             // check if billing address is set
147:             if (is_null($quote->getBillingAddress()->getId()) ) {
148:                 $this->_fault('billing_address_is_not_set');
149:             }
150:             $quote->getBillingAddress()->setPaymentMethod(isset($paymentData['method']) ? $paymentData['method'] : null);
151:         } else {
152:             // check if shipping address is set
153:             if (is_null($quote->getShippingAddress()->getId()) ) {
154:                 $this->_fault('shipping_address_is_not_set');
155:             }
156:             $quote->getShippingAddress()->setPaymentMethod(isset($paymentData['method']) ? $paymentData['method'] : null);
157:         }
158: 
159:         if (!$quote->isVirtual() && $quote->getShippingAddress()) {
160:             $quote->getShippingAddress()->setCollectShippingRates(true);
161:         }
162: 
163:         $total = $quote->getBaseSubtotal();
164:         $methods = Mage::helper('payment')->getStoreMethods($store, $quote);
165:         foreach ($methods as $key=>$method) {
166:             if ($method->getCode() == $paymentData['method']) {
167:                 /** @var $method Mage_Payment_Model_Method_Abstract */
168:                 if (!($this->_canUsePaymentMethod($method, $quote)
169:                         && ($total != 0
170:                             || $method->getCode() == 'free'
171:                             || ($quote->hasRecurringItems() && $method->canManageRecurringProfiles())))) {
172:                     $this->_fault("method_not_allowed");
173:                 }
174:             }
175:         }
176: 
177:         try {
178:             $payment = $quote->getPayment();
179:             $payment->importData($paymentData);
180: 
181: 
182:             $quote->setTotalsCollectedFlag(false)
183:                     ->collectTotals()
184:                     ->save();
185:         } catch (Mage_Core_Exception $e) {
186:             $this->_fault('payment_method_is_not_set', $e->getMessage());
187:         }
188:         return true;
189:     }
190: 
191: }
192: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0