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_Sales
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: * Quote payment information
29: *
30: * @method Mage_Sales_Model_Resource_Quote_Payment _getResource()
31: * @method Mage_Sales_Model_Resource_Quote_Payment getResource()
32: * @method int getQuoteId()
33: * @method Mage_Sales_Model_Quote_Payment setQuoteId(int $value)
34: * @method string getCreatedAt()
35: * @method Mage_Sales_Model_Quote_Payment setCreatedAt(string $value)
36: * @method string getUpdatedAt()
37: * @method Mage_Sales_Model_Quote_Payment setUpdatedAt(string $value)
38: * @method string getMethod()
39: * @method Mage_Sales_Model_Quote_Payment setMethod(string $value)
40: * @method string getCcType()
41: * @method Mage_Sales_Model_Quote_Payment setCcType(string $value)
42: * @method string getCcNumberEnc()
43: * @method Mage_Sales_Model_Quote_Payment setCcNumberEnc(string $value)
44: * @method string getCcLast4()
45: * @method Mage_Sales_Model_Quote_Payment setCcLast4(string $value)
46: * @method string getCcCidEnc()
47: * @method Mage_Sales_Model_Quote_Payment setCcCidEnc(string $value)
48: * @method string getCcOwner()
49: * @method Mage_Sales_Model_Quote_Payment setCcOwner(string $value)
50: * @method int getCcExpMonth()
51: * @method Mage_Sales_Model_Quote_Payment setCcExpMonth(int $value)
52: * @method int getCcExpYear()
53: * @method Mage_Sales_Model_Quote_Payment setCcExpYear(int $value)
54: * @method string getCcSsOwner()
55: * @method Mage_Sales_Model_Quote_Payment setCcSsOwner(string $value)
56: * @method int getCcSsStartMonth()
57: * @method Mage_Sales_Model_Quote_Payment setCcSsStartMonth(int $value)
58: * @method int getCcSsStartYear()
59: * @method Mage_Sales_Model_Quote_Payment setCcSsStartYear(int $value)
60: * @method string getCybersourceToken()
61: * @method Mage_Sales_Model_Quote_Payment setCybersourceToken(string $value)
62: * @method string getPaypalCorrelationId()
63: * @method Mage_Sales_Model_Quote_Payment setPaypalCorrelationId(string $value)
64: * @method string getPaypalPayerId()
65: * @method Mage_Sales_Model_Quote_Payment setPaypalPayerId(string $value)
66: * @method string getPaypalPayerStatus()
67: * @method Mage_Sales_Model_Quote_Payment setPaypalPayerStatus(string $value)
68: * @method string getPoNumber()
69: * @method Mage_Sales_Model_Quote_Payment setPoNumber(string $value)
70: * @method string getAdditionalData()
71: * @method Mage_Sales_Model_Quote_Payment setAdditionalData(string $value)
72: * @method string getCcSsIssue()
73: * @method Mage_Sales_Model_Quote_Payment setCcSsIssue(string $value)
74: * @method string getIdealIssuerId()
75: * @method Mage_Sales_Model_Quote_Payment setIdealIssuerId(string $value)
76: * @method string getIdealIssuerList()
77: * @method Mage_Sales_Model_Quote_Payment setIdealIssuerList(string $value)
78: *
79: * @category Mage
80: * @package Mage_Sales
81: * @author Magento Core Team <core@magentocommerce.com>
82: */
83: class Mage_Sales_Model_Quote_Payment extends Mage_Payment_Model_Info
84: {
85: protected $_eventPrefix = 'sales_quote_payment';
86: protected $_eventObject = 'payment';
87:
88: protected $_quote;
89:
90: /**
91: * Initialize resource model
92: */
93: protected function _construct()
94: {
95: $this->_init('sales/quote_payment');
96: }
97:
98: /**
99: * Declare quote model instance
100: *
101: * @param Mage_Sales_Model_Quote $quote
102: * @return Mage_Sales_Model_Quote_Payment
103: */
104: public function setQuote(Mage_Sales_Model_Quote $quote)
105: {
106: $this->_quote = $quote;
107: $this->setQuoteId($quote->getId());
108: return $this;
109: }
110:
111: /**
112: * Retrieve quote model instance
113: *
114: * @return Mage_Sales_Model_Quote
115: */
116: public function getQuote()
117: {
118: return $this->_quote;
119: }
120:
121: /**
122: * Import data array to payment method object,
123: * Method calls quote totals collect because payment method availability
124: * can be related to quote totals
125: *
126: * @param array $data
127: * @throws Mage_Core_Exception
128: * @return Mage_Sales_Model_Quote_Payment
129: */
130: public function importData(array $data)
131: {
132: $data = new Varien_Object($data);
133: Mage::dispatchEvent(
134: $this->_eventPrefix . '_import_data_before',
135: array(
136: $this->_eventObject=>$this,
137: 'input'=>$data,
138: )
139: );
140:
141: $this->setMethod($data->getMethod());
142: $method = $this->getMethodInstance();
143:
144: /**
145: * Payment availability related with quote totals.
146: * We have recollect quote totals before checking
147: */
148: $this->getQuote()->collectTotals();
149:
150: if (!$method->isAvailable($this->getQuote())) {
151: Mage::throwException(Mage::helper('sales')->__('The requested Payment Method is not available.'));
152: }
153:
154: $method->assignData($data);
155: /*
156: * validating the payment data
157: */
158: $method->validate();
159: return $this;
160: }
161:
162: /**
163: * Prepare object for save
164: *
165: * @return Mage_Sales_Model_Quote_Payment
166: */
167: protected function _beforeSave()
168: {
169: if ($this->getQuote()) {
170: $this->setQuoteId($this->getQuote()->getId());
171: }
172: try {
173: $method = $this->getMethodInstance();
174: } catch (Mage_Core_Exception $e) {
175: return parent::_beforeSave();
176: }
177: $method->prepareSave();
178: return parent::_beforeSave();
179: }
180:
181: /**
182: * Checkout redirect URL getter
183: *
184: * @return string
185: */
186: public function getCheckoutRedirectUrl()
187: {
188: $method = $this->getMethodInstance();
189: if ($method) {
190: return $method->getCheckoutRedirectUrl();
191: }
192: return '';
193: }
194:
195: /**
196: * Checkout order place redirect URL getter
197: *
198: * @return string
199: */
200: public function getOrderPlaceRedirectUrl()
201: {
202: $method = $this->getMethodInstance();
203: if ($method) {
204: return $method->getOrderPlaceRedirectUrl();
205: }
206: return '';
207: }
208:
209: /**
210: * Retrieve payment method model object
211: *
212: * @return Mage_Payment_Model_Method_Abstract
213: */
214: public function getMethodInstance()
215: {
216: $method = parent::getMethodInstance();
217: return $method->setStore($this->getQuote()->getStore());
218: }
219: }
220: