-
Notifications
You must be signed in to change notification settings - Fork 550
/
Standard.php
217 lines (200 loc) · 6.21 KB
/
Standard.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category Mage
* @package Mage_Paypal
* @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
/**
*
* PayPal Standard Checkout Module
*
* @author Magento Core Team <core@magentocommerce.com>
*/
class Mage_Paypal_Model_Standard extends Mage_Payment_Model_Method_Abstract
{
protected $_code = Mage_Paypal_Model_Config::METHOD_WPS;
protected $_formBlockType = 'paypal/standard_form';
protected $_infoBlockType = 'paypal/payment_info';
protected $_isInitializeNeeded = true;
protected $_canUseInternal = false;
protected $_canUseForMultishipping = false;
/**
* Config instance
* @var Mage_Paypal_Model_Config
*/
protected $_config = null;
/**
* Whether method is available for specified currency
*
* @param string $currencyCode
* @return bool
*/
public function canUseForCurrency($currencyCode)
{
return $this->getConfig()->isCurrencyCodeSupported($currencyCode);
}
/**
* Get paypal session namespace
*
* @return Mage_Paypal_Model_Session
*/
public function getSession()
{
return Mage::getSingleton('paypal/session');
}
/**
* Get checkout session namespace
*
* @return Mage_Checkout_Model_Session
*/
public function getCheckout()
{
return Mage::getSingleton('checkout/session');
}
/**
* Get current quote
*
* @return Mage_Sales_Model_Quote
*/
public function getQuote()
{
return $this->getCheckout()->getQuote();
}
/**
* Create main block for standard form
*
*/
public function createFormBlock($name)
{
$block = $this->getLayout()->createBlock('paypal/standard_form', $name)
->setMethod('paypal_standard')
->setPayment($this->getPayment())
->setTemplate('paypal/standard/form.phtml');
return $block;
}
/**
* Return Order place redirect url
*
* @return string
*/
public function getOrderPlaceRedirectUrl()
{
return Mage::getUrl('paypal/standard/redirect', array('_secure' => true));
}
/**
* Return form field array
*
* @return array
*/
public function getStandardCheckoutFormFields()
{
$orderIncrementId = $this->getCheckout()->getLastRealOrderId();
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
/* @var $api Mage_Paypal_Model_Api_Standard */
$api = Mage::getModel('paypal/api_standard')->setConfigObject($this->getConfig());
$api->setOrderId($orderIncrementId)
->setCurrencyCode($order->getBaseCurrencyCode())
//->setPaymentAction()
->setOrder($order)
->setNotifyUrl(Mage::getUrl('paypal/ipn/'))
->setReturnUrl(Mage::getUrl('paypal/standard/success'))
->setCancelUrl(Mage::getUrl('paypal/standard/cancel'));
// export address
$isOrderVirtual = $order->getIsVirtual();
$address = $isOrderVirtual ? $order->getBillingAddress() : $order->getShippingAddress();
if ($isOrderVirtual) {
$api->setNoShipping(true);
} elseif ($address->validate()) {
$api->setAddress($address);
}
// add cart totals and line items
$api->setPaypalCart(Mage::getModel('paypal/cart', array($order)))
->setIsLineItemsEnabled($this->_config->lineItemsEnabled)
;
$api->setCartSummary($this->_getAggregatedCartSummary());
$api->setLocale($api->getLocaleCode());
$result = $api->getStandardCheckoutRequest();
return $result;
}
/**
* Instantiate state and set it to state object
* @param string $paymentAction
* @param Varien_Object
*/
public function initialize($paymentAction, $stateObject)
{
$state = Mage_Sales_Model_Order::STATE_PENDING_PAYMENT;
$stateObject->setState($state);
$stateObject->setStatus('pending_payment');
$stateObject->setIsNotified(false);
}
/**
* Config instance getter
* @return Mage_Paypal_Model_Config
*/
public function getConfig()
{
if (null === $this->_config) {
$params = array($this->_code);
if ($store = $this->getStore()) {
$params[] = is_object($store) ? $store->getId() : $store;
}
$this->_config = Mage::getModel('paypal/config', $params);
}
return $this->_config;
}
/**
* Check whether payment method can be used
* @param Mage_Sales_Model_Quote
* @return bool
*/
public function isAvailable($quote = null)
{
if (parent::isAvailable($quote) && $this->getConfig()->isMethodAvailable()) {
return true;
}
return false;
}
/**
* Custom getter for payment configuration
*
* @param string $field
* @param int $storeId
* @return mixed
*/
public function getConfigData($field, $storeId = null)
{
return $this->getConfig()->$field;
}
/**
* Aggregated cart summary label getter
*
* @return string
*/
private function _getAggregatedCartSummary()
{
if ($this->_config->lineItemsSummary) {
return $this->_config->lineItemsSummary;
}
return Mage::app()->getStore($this->getStore())->getFrontendName();
}
}