00001 <?php 00002 /** 00003 * Magento 00004 * 00005 * NOTICE OF LICENSE 00006 * 00007 * This source file is subject to the Open Software License (OSL 3.0) 00008 * that is bundled with this package in the file LICENSE.txt. 00009 * It is also available through the world-wide-web at this URL: 00010 * http://opensource.org/licenses/osl-3.0.php 00011 * If you did not receive a copy of the license and are unable to 00012 * obtain it through the world-wide-web, please send an email 00013 * to license@magentocommerce.com so we can send you a copy immediately. 00014 * 00015 * DISCLAIMER 00016 * 00017 * Do not edit or add to this file if you wish to upgrade Magento to newer 00018 * versions in the future. If you wish to customize Magento for your 00019 * needs please refer to http://www.magentocommerce.com for more information. 00020 * 00021 * @category Mage 00022 * @package Mage_Sales 00023 * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) 00024 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 00025 */ 00026 00027 /** 00028 * Quote payment information 00029 */ 00030 class Mage_Sales_Model_Quote_Payment extends Mage_Payment_Model_Info 00031 { 00032 protected $_eventPrefix = 'sales_quote_payment'; 00033 protected $_eventObject = 'payment'; 00034 00035 protected $_quote; 00036 00037 /** 00038 * Initialize resource model 00039 */ 00040 protected function _construct() 00041 { 00042 $this->_init('sales/quote_payment'); 00043 } 00044 00045 /** 00046 * Declare quote model instance 00047 * 00048 * @param Mage_Sales_Model_Quote $quote 00049 * @return Mage_Sales_Model_Quote_Payment 00050 */ 00051 public function setQuote(Mage_Sales_Model_Quote $quote) 00052 { 00053 $this->_quote = $quote; 00054 $this->setQuoteId($quote->getId()); 00055 return $this; 00056 } 00057 00058 /** 00059 * Retrieve quote model instance 00060 * 00061 * @return Mage_Sales_Model_Quote 00062 */ 00063 public function getQuote() 00064 { 00065 return $this->_quote; 00066 } 00067 00068 /** 00069 * Import data 00070 * 00071 * @param array $data 00072 * @return Mage_Sales_Model_Quote_Payment 00073 */ 00074 public function importData(array $data) 00075 { 00076 $data = new Varien_Object($data); 00077 Mage::dispatchEvent( 00078 $this->_eventPrefix . '_import_data_before', 00079 array( 00080 $this->_eventObject=>$this, 00081 'input'=>$data, 00082 ) 00083 ); 00084 00085 $this->setMethod($data->getMethod()); 00086 $method = $this->getMethodInstance(); 00087 00088 $method->assignData($data); 00089 /* 00090 * validating the payment data 00091 */ 00092 $method->validate(); 00093 return $this; 00094 } 00095 00096 /** 00097 * Prepare object for save 00098 * 00099 * @return Mage_Sales_Model_Quote_Payment 00100 */ 00101 protected function _beforeSave() 00102 { 00103 try { 00104 $method = $this->getMethodInstance(); 00105 } catch (Mage_Core_Exception $e) { 00106 return parent::_beforeSave(); 00107 } 00108 $method->prepareSave(); 00109 if ($this->getQuote()) { 00110 $this->setParentId($this->getQuote()->getId()); 00111 } 00112 return parent::_beforeSave(); 00113 } 00114 00115 public function getCheckoutRedirectUrl() 00116 { 00117 $method = $this->getMethodInstance(); 00118 00119 return $method ? $method->getCheckoutRedirectUrl() : false; 00120 } 00121 00122 public function getOrderPlaceRedirectUrl() 00123 { 00124 $method = $this->getMethodInstance(); 00125 00126 return $method ? $method->getOrderPlaceRedirectUrl() : false; 00127 } 00128 }