*/ class Mage_Sales_Model_Quote_Payment extends Mage_Payment_Model_Info { protected $_eventPrefix = 'sales_quote_payment'; protected $_eventObject = 'payment'; protected $_quote; /** * Initialize resource model */ protected function _construct() { $this->_init('sales/quote_payment'); } /** * Declare quote model instance * * @param Mage_Sales_Model_Quote $quote * @return Mage_Sales_Model_Quote_Payment */ public function setQuote(Mage_Sales_Model_Quote $quote) { $this->_quote = $quote; $this->setQuoteId($quote->getId()); return $this; } /** * Retrieve quote model instance * * @return Mage_Sales_Model_Quote */ public function getQuote() { return $this->_quote; } /** * Import data array to payment method object, * Method calls quote totals collect because payment method availability * can be related to quote totals * * @param array $data * @throws Mage_Core_Exception * @return Mage_Sales_Model_Quote_Payment */ public function importData(array $data) { $data = new Varien_Object($data); Mage::dispatchEvent( $this->_eventPrefix . '_import_data_before', array( $this->_eventObject=>$this, 'input'=>$data, ) ); $this->setMethod($data->getMethod()); $method = $this->getMethodInstance(); /** * Payment availability related with quote totals. * We have recollect quote totals before checking */ $this->getQuote()->collectTotals(); if (!$method->isAvailable($this->getQuote())) { Mage::throwException(Mage::helper('sales')->__('The requested Payment Method is not available.')); } $method->assignData($data); /* * validating the payment data */ $method->validate(); return $this; } /** * Prepare object for save * * @return Mage_Sales_Model_Quote_Payment */ protected function _beforeSave() { if ($this->getQuote()) { $this->setQuoteId($this->getQuote()->getId()); } try { $method = $this->getMethodInstance(); } catch (Mage_Core_Exception $e) { return parent::_beforeSave(); } $method->prepareSave(); return parent::_beforeSave(); } /** * Checkout redirect URL getter * * @return string */ public function getCheckoutRedirectUrl() { $method = $this->getMethodInstance(); if ($method) { return $method->getCheckoutRedirectUrl(); } return ''; } /** * Checkout order place redirect URL getter * * @return string */ public function getOrderPlaceRedirectUrl() { $method = $this->getMethodInstance(); if ($method) { return $method->getOrderPlaceRedirectUrl(); } return ''; } /** * Retrieve payment method model object * * @return Mage_Payment_Model_Method_Abstract */ public function getMethodInstance() { $method = parent::getMethodInstance(); return $method->setStore($this->getQuote()->getStore()); } }