forked from azdcgo/axiscommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Abstract.php
278 lines (249 loc) · 7.12 KB
/
Abstract.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<?php
/**
* Axis
*
* This file is part of Axis.
*
* Axis is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Axis is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Axis. If not, see <http://www.gnu.org/licenses/>.
*
* @category Axis
* @package Axis_Checkout
* @subpackage Axis_Checkout_Method
* @copyright Copyright 2008-2012 Axis
* @license GNU Public License V3.0
*/
/**
*
* @category Axis
* @package Axis_Checkout
* @subpackage Axis_Checkout_Method
* @author Axis Core Team <core@axiscommerce.com>
* @abstract
*/
abstract class Axis_Method_Payment_Model_Abstract extends Axis_Method_Abstract
{
/**
* Payment Method unique code
*/
protected $_section = 'payment';
protected $_file = __FILE__;
/**
* Checkout data storage
*
* @var Zend_Session_Namespace
*/
private $_storage;
public function __construct()
{
parent::__construct();
try {
$writer = new Zend_Log_Writer_Stream(
Axis::config()->system->path .
Axis::config()->log->main->payment
);
$this->_logger = new Zend_Log($writer);
} catch (Exception $e) {}
}
/**
* Validation of order data by payment service
* should be called from this method
*
* If invalid data received methods should throw an Exception
*
* Method can return a redirect url:
* array(
* 'redirect' => payment aggregator url
* )
*/
public function preProcess() {}
/**
*
* @param Axis_Sales_Model_Order_Row $order
* @return bool
*/
public function pending(Axis_Sales_Model_Order_Row $order) { return true;}
/**
*
* @param Axis_Sales_Model_Order_Row $order
* @return bool
*/
public function processing(Axis_Sales_Model_Order_Row $order) {return true;}
/**
*
* @param Axis_Sales_Model_Order_Row $order
* @return bool
*/
public function cancel(Axis_Sales_Model_Order_Row $order) {return true;}
/**
*
* @param Axis_Sales_Model_Order_Row $order
* @return bool
*/
public function refund(Axis_Sales_Model_Order_Row $order) {return true;}
/**
*
* @param Axis_Sales_Model_Order_Row $order
* @return bool
*/
public function failed(Axis_Sales_Model_Order_Row $order) {return true;}
/**
* @param Axis_Sales_Model_Order_Row $order
*
* Method can return a redirect url:
* array(
* 'redirect' => payment aggregator url
* )
*/
public function postProcess(Axis_Sales_Model_Order_Row $order) { }
/**
* Return checkout data storage
*
* @return Zend_Session_Namespace
*/
public function getStorage()
{
if (null === $this->_storage) {
$this->_storage = new Zend_Session_Namespace(
$this->_code . '-Checkout'
);
$this->_storage->setExpirationSeconds(600);
$this->_storage->setExpirationHops(5);
}
return $this->_storage;
}
/**
* Saved custom attributes
* @see (form.phtml, setPaymentAction)
* @return bool
* @param array $data
*/
public function saveData($data)
{
return $this->getStorage()->data = $data;
}
/**
* Clear payment storage
*/
public function clear()
{
$this->getStorage()->unsetAll();
}
/**
*
* @param string $message
*/
public function log($message)
{
//Axis::message()->addError($message);
$this->_logger->info($message);
}
/**
*
* @param array $request
* @return bool
*/
public function isAllowed($request)
{
// Zend_Debug::dump($request);die;
if (isset($this->_config->minOrderTotal) &&
!empty($this->_config->minOrderTotal) &&
$request['price'] < $this->_config->minOrderTotal)
{
return false;
}
if (isset($this->_config->maxOrderTotal) &&
!empty($this->_config->maxOrderTotal) &&
$request['price'] > $this->_config->maxOrderTotal)
{
return false;
}
if (null !== $request['shipping_method_code']) {
$shipping = Axis_Shipping::getMethod($request['shipping_method_code']);
// get list of disallowed payment methods, and compare with requested payment method
$disallowedPaymentMethods = $shipping->config()->payments->toArray();
if (in_array($this->getCode(), $disallowedPaymentMethods)) {
return false;
}
// get list of disallowed shippings and compare with selected shipping method
$disallowedShippingMethods = $this->_config->shippings->toArray();
if (in_array($shipping->getCode(false), $disallowedShippingMethods)) {
return false;
}
}
if (!isset($this->_config->geozone)
|| !intval($this->_config->geozone)) {
return true;
}
if (empty($request['country']['id'])) {
return true;
}
$zoneId = null;
if (isset($request['zone']['id'])) {
$zoneId = $request['zone']['id'];
}
return Axis::single('location/geozone_zone')->inGeozone(
$this->_config->geozone,
$request['country']['id'],
$zoneId
);
}
/**
* @return string
*/
public function getTitle()
{
$title = isset($this->_config->title) ?
$this->_config->title : $this->_title;
return $this->getTranslator()->__($title);
}
/**
* Convert abstract total of order
* to payment baseCurrency
*
* @param float $amount
* @return float
*/
public function getAmountInBaseCurrency($amount)
{
return Axis::single('locale/currency')
->to($amount, $this->getBaseCurrencyCode());
}
/**
* Retrieve baseCurrency code
* Used for online transactions
*
* @return string
*/
public function getBaseCurrencyCode()
{
$baseCurrency = $this->_config->currency;
if (null === $baseCurrency) {
$baseCurrency = Axis::config('locale/main/baseCurrency');
}
return (null === $baseCurrency || strlen($baseCurrency) != 3) ?
'USD' : $baseCurrency;
}
/**
* Only Axis payments are supported
* @todo return module with category name
* example: Axis_PaymentPaypal
*
* @return Axis_Translator
*/
public function getTranslator()
{
$codeArray = explode('_', $this->_code);
return Axis::translate('Payment' . current($codeArray));
}
}