Version Notes
* When order is cancelled product is credited to inventory
* Cart is now restored when returning from Payson and payment failed
Download this release
Release Info
Developer | Oscar Villegas |
Extension | Payson |
Version | 1.0.0 |
Comparing to | |
See all releases |
Code changes from version 0.1.3 to 1.0.0
- app/code/community/Payson/Payson/Block/Form.php +8 -7
- app/code/community/Payson/Payson/Block/Invoice/Form.php +8 -7
- app/code/community/Payson/Payson/Block/Order/Totals/Fee.php +17 -17
- app/code/community/Payson/Payson/Block/Standard/Form.php +8 -7
- app/code/community/Payson/Payson/Helper/Api.php +1031 -1180
- app/code/community/Payson/Payson/Helper/Api/Response/Interface.php +16 -15
- app/code/community/Payson/Payson/Helper/Api/Response/Standard.php +128 -150
- app/code/community/Payson/Payson/Helper/Api/Response/Standard/Parameters.php +55 -67
- app/code/community/Payson/Payson/Helper/Api/Response/Validate.php +43 -46
- app/code/community/Payson/Payson/Helper/Data.php +2 -2
- app/code/community/Payson/Payson/Model/Config.php +217 -232
- app/code/community/Payson/Payson/Model/Method/Abstract.php +159 -174
- app/code/community/Payson/Payson/Model/Method/Invoice.php +109 -129
- app/code/community/Payson/Payson/Model/Method/Standard.php +36 -37
- app/code/community/Payson/Payson/Model/Mysql4/Setup.php +3 -2
- app/code/community/Payson/Payson/Model/Order/Creditmemo/Total/Invoice.php +31 -32
- app/code/community/Payson/Payson/Model/Order/Invoice/Total/Invoice.php +30 -32
- app/code/community/Payson/Payson/Model/Quote/Address/Total/Invoice.php +45 -49
- app/code/community/Payson/Payson/Model/Standard.php +115 -128
- app/code/community/Payson/Payson/controllers/CheckoutController.php +135 -133
- app/code/community/Payson/Payson/controllers/IpnController.php +22 -26
- app/code/community/Payson/Payson/etc/config.xml +18 -16
- app/code/community/Payson/Payson/etc/system.xml +159 -139
- app/code/community/Payson/Payson/sql/payson_setup/mysql4-install-0.1.0.php +3 -14
- app/code/community/Payson/Payson/sql/payson_setup/mysql4-upgrade-0.1.0-0.1.2.php +1 -0
- app/design/adminhtml/default/default/Payson/Payson/total.phtml +2 -2
- app/design/adminhtml/default/default/layout/Payson.xml +20 -30
- app/design/frontend/base/default/layout/Payson.xml +41 -41
- app/design/frontend/base/default/template/Payson/Payson/invoice_form.phtml +9 -9
- app/design/frontend/base/default/template/Payson/Payson/standard_form.phtml +4 -4
- app/etc/modules/Payson_Payson.xml +10 -10
- package.xml +8 -12
app/code/community/Payson/Payson/Block/Form.php
CHANGED
@@ -1,10 +1,11 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
{
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
9 |
}
|
10 |
|
1 |
<?php
|
2 |
+
|
3 |
+
class Payson_Payson_Block_Form extends Mage_Payment_Block_Form {
|
4 |
+
|
5 |
+
protected function _construct() {
|
6 |
+
$this->setTemplate('Payson/Payson/form.phtml');
|
7 |
+
parent::_construct();
|
8 |
+
}
|
9 |
+
|
10 |
}
|
11 |
|
app/code/community/Payson/Payson/Block/Invoice/Form.php
CHANGED
@@ -1,10 +1,11 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
{
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
9 |
}
|
10 |
|
1 |
<?php
|
2 |
+
|
3 |
+
class Payson_Payson_Block_Invoice_Form extends Mage_Payment_Block_Form {
|
4 |
+
|
5 |
+
protected function _construct() {
|
6 |
+
$this->setTemplate('Payson/Payson/invoice_form.phtml');
|
7 |
+
parent::_construct();
|
8 |
+
}
|
9 |
+
|
10 |
}
|
11 |
|
app/code/community/Payson/Payson/Block/Order/Totals/Fee.php
CHANGED
@@ -1,22 +1,22 @@
|
|
1 |
<?php
|
2 |
-
class Payson_Payson_Block_Order_Totals_Fee extends Mage_Core_Block_Abstract
|
3 |
-
{
|
4 |
-
public function initTotals()
|
5 |
-
{
|
6 |
-
$parent = $this->getParentBlock();
|
7 |
-
$this->_order = $parent->getOrder();
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
return $this;
|
20 |
-
}
|
21 |
}
|
22 |
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
class Payson_Payson_Block_Order_Totals_Fee extends Mage_Core_Block_Abstract {
|
4 |
+
|
5 |
+
public function initTotals() {
|
6 |
+
$parent = $this->getParentBlock();
|
7 |
+
$this->_order = $parent->getOrder();
|
8 |
+
|
9 |
+
if ($this->_order->getPayment()->getMethod() === 'payson_invoice') {
|
10 |
+
$parent->addTotalBefore(new Varien_Object(array
|
11 |
+
(
|
12 |
+
'code' => 'payson_invoice',
|
13 |
+
'label' => Mage::helper('payson')->__('Invoice fee'),
|
14 |
+
'value' => $this->_order->getPaysonInvoiceFee()
|
15 |
+
)), 'tax');
|
16 |
+
}
|
17 |
+
|
18 |
+
return $this;
|
19 |
+
}
|
20 |
|
|
|
|
|
21 |
}
|
22 |
|
app/code/community/Payson/Payson/Block/Standard/Form.php
CHANGED
@@ -1,10 +1,11 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
{
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
9 |
}
|
10 |
|
1 |
<?php
|
2 |
+
|
3 |
+
class Payson_Payson_Block_Standard_Form extends Mage_Payment_Block_Form {
|
4 |
+
|
5 |
+
protected function _construct() {
|
6 |
+
$this->setTemplate('Payson/Payson/standard_form.phtml');
|
7 |
+
parent::_construct();
|
8 |
+
}
|
9 |
+
|
10 |
}
|
11 |
|
app/code/community/Payson/Payson/Helper/Api.php
CHANGED
@@ -1,510 +1,458 @@
|
|
1 |
<?php
|
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 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
'Failed to initialize payment. Payson replied: %s'),
|
449 |
-
$response->GetError()), $response->GetErrorId());
|
450 |
-
}
|
451 |
-
|
452 |
-
return $this;
|
453 |
-
}
|
454 |
-
|
455 |
-
/**
|
456 |
-
* Implements the IPN procedure
|
457 |
-
*
|
458 |
-
* http://api.payson.se/#title11
|
459 |
-
*
|
460 |
-
* @param string $http_body
|
461 |
-
* @param string $content_type
|
462 |
-
* @return object $this
|
463 |
-
*/
|
464 |
-
public function Validate($http_body, $content_type)
|
465 |
-
{
|
466 |
-
$helper = Mage::helper('payson');
|
467 |
-
$config = Mage::getModel('payson/config');
|
468 |
-
// Parse request done by Payson to our IPN controller
|
469 |
-
$ipn_response = Payson_Payson_Helper_Api_Response_Standard
|
470 |
-
::FromHttpBody($http_body);
|
471 |
-
|
472 |
-
// Get the database connection
|
473 |
-
$resource = Mage::getSingleton('core/resource');
|
474 |
-
$db = $resource->getConnection('core_write');
|
475 |
-
|
476 |
-
$order_table = $resource->getTableName('payson_order');
|
477 |
-
$order_log_table = $resource->getTableName('payson_order_log');
|
478 |
-
|
479 |
-
/* Save data sent by Payson, log entry as invalid by default, this
|
480 |
-
value will be changed later in this method if successful. No payson
|
481 |
-
order id is set, because we dont have one yet */
|
482 |
-
$db->insert($order_log_table,
|
483 |
-
array
|
484 |
-
(
|
485 |
-
'added' => new Zend_Db_Expr('NOW()'),
|
486 |
-
'api_call' => 'validate',
|
487 |
-
'valid' => 0,
|
488 |
-
'response' => serialize($ipn_response->ToArray())
|
489 |
-
));
|
490 |
-
|
491 |
-
$order_log_id = $db->lastInsertId();
|
492 |
-
|
493 |
-
/* $ipn_response will never contain responseEnvelope.ack, as I first
|
494 |
-
thought it would */
|
495 |
-
/*if(!$ipn_response->IsValid())
|
496 |
-
{
|
497 |
-
Mage::throwException('Invalid request');
|
498 |
-
}*/
|
499 |
-
|
500 |
-
/* Save fetch mode so that we can reset it and not mess up Magento
|
501 |
-
functionality */
|
502 |
-
$old_fetch_mode = $db->getFetchMode();
|
503 |
-
$db->setFetchMode(Zend_Db::FETCH_OBJ);
|
504 |
-
|
505 |
-
// Get payson order information and validate token
|
506 |
-
$payson_order = $db->fetchRow(
|
507 |
-
'SELECT
|
508 |
id,
|
509 |
order_id,
|
510 |
store_id
|
@@ -517,534 +465,448 @@ AND
|
|
517 |
LIMIT
|
518 |
0,1', $ipn_response->token);
|
519 |
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
-
|
920 |
-
|
921 |
-
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
case self::STATUS_ERROR:
|
966 |
-
// throw new Mage_Core_Exception(sprintf($helper->__('Denaid.')));
|
967 |
-
|
968 |
-
//Mage::throwException('Invalid order id (' . $order->getId() . ')');
|
969 |
-
|
970 |
-
$order->setState(
|
971 |
-
Mage_Sales_Model_Order::STATE_CANCELED,
|
972 |
-
Mage_Sales_Model_Order::STATE_CANCELED,
|
973 |
-
sprintf($helper->__(
|
974 |
-
'Ther order was denied by Payson.')))
|
975 |
-
->cancel();
|
976 |
-
//throw new Mage_Core_Exception(sprintf($helper->__('Denaid.')));
|
977 |
-
break;
|
978 |
-
|
979 |
-
|
980 |
-
|
981 |
-
case self::STATUS_INCOMPLETE:
|
982 |
-
case self::STATUS_EXPIRED:
|
983 |
-
case self::STATUS_REVERSALERROR:
|
984 |
-
default:
|
985 |
-
{
|
986 |
-
/*$order->setState(
|
987 |
-
Mage_Sales_Model_Order::STATE_CANCELED,
|
988 |
-
Mage_Sales_Model_Order::STATE_CANCELED,
|
989 |
-
sprintf($helper->__(
|
990 |
-
'Payson cancelled the order with status %s'),
|
991 |
-
$ipn_response->status))
|
992 |
-
->cancel();*/
|
993 |
-
$order->cancel();
|
994 |
-
}
|
995 |
-
}
|
996 |
-
|
997 |
-
$order->save();
|
998 |
-
|
999 |
-
// Update the database tables
|
1000 |
-
$db->update($order_log_table,
|
1001 |
-
array
|
1002 |
-
(
|
1003 |
-
'valid' => 1
|
1004 |
-
),
|
1005 |
-
array
|
1006 |
-
(
|
1007 |
-
'id = ?' => $order_log_id
|
1008 |
-
));
|
1009 |
-
|
1010 |
-
$db->update($order_table,
|
1011 |
-
array
|
1012 |
-
(
|
1013 |
-
'ipn_status' => $ipn_response->status
|
1014 |
-
),
|
1015 |
-
array
|
1016 |
-
(
|
1017 |
-
'id = ?' => $payson_order->id
|
1018 |
-
));
|
1019 |
-
|
1020 |
-
return $this;
|
1021 |
-
}
|
1022 |
-
|
1023 |
-
/**
|
1024 |
-
* http://api.payson.se/#title12
|
1025 |
-
*
|
1026 |
-
* @params int $order_id Real order id
|
1027 |
-
* @return object $this
|
1028 |
-
*/
|
1029 |
-
public function PaymentDetails($order_id)
|
1030 |
-
{
|
1031 |
-
$helper = Mage::helper('payson');
|
1032 |
-
|
1033 |
-
// Get the database connection
|
1034 |
-
$resource = Mage::getSingleton('core/resource');
|
1035 |
-
$db = $resource->getConnection('core_write');
|
1036 |
-
|
1037 |
-
$order_table = $resource->getTableName('payson_order');
|
1038 |
-
$order_log_table = $resource->getTableName('payson_order_log');
|
1039 |
-
|
1040 |
-
/* Save fetch mode so that we can reset it and not mess up Magento
|
1041 |
-
functionality */
|
1042 |
-
$old_fetch_mode = $db->getFetchMode();
|
1043 |
-
$db->setFetchMode(Zend_Db::FETCH_OBJ);
|
1044 |
-
|
1045 |
-
// Get payson order information and validate token
|
1046 |
-
$payson_order = $db->fetchRow(
|
1047 |
-
'SELECT
|
1048 |
id,
|
1049 |
token,
|
1050 |
store_id
|
@@ -1057,72 +919,68 @@ AND
|
|
1057 |
LIMIT
|
1058 |
0,1', $order_id);
|
1059 |
|
1060 |
-
|
1061 |
-
|
1062 |
-
|
1063 |
-
|
1064 |
-
|
1065 |
-
|
1066 |
-
|
1067 |
-
|
1068 |
-
|
1069 |
-
|
1070 |
-
|
1071 |
-
|
1072 |
-
|
1073 |
-
|
1074 |
-
|
1075 |
-
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
-
|
1080 |
-
|
1081 |
-
|
1082 |
-
|
1083 |
-
|
1084 |
-
|
1085 |
-
|
1086 |
-
|
1087 |
-
|
1088 |
-
|
1089 |
-
|
1090 |
-
|
1091 |
-
|
1092 |
-
|
1093 |
-
|
1094 |
-
|
1095 |
-
|
1096 |
-
|
1097 |
-
|
1098 |
-
|
1099 |
-
|
1100 |
-
|
1101 |
-
|
1102 |
-
|
1103 |
-
|
1104 |
-
|
1105 |
-
|
1106 |
-
|
1107 |
-
|
1108 |
-
|
1109 |
-
|
1110 |
-
|
1111 |
-
|
1112 |
-
|
1113 |
-
|
1114 |
-
|
1115 |
-
|
1116 |
-
|
1117 |
-
|
1118 |
-
|
1119 |
-
|
1120 |
-
|
1121 |
-
|
1122 |
-
|
1123 |
-
// Get payson order information and validate token
|
1124 |
-
$payson_order = $db->fetchRow(
|
1125 |
-
'SELECT
|
1126 |
id,
|
1127 |
token,
|
1128 |
store_id
|
@@ -1135,95 +993,88 @@ AND
|
|
1135 |
LIMIT
|
1136 |
0,1', $order_id);
|
1137 |
|
1138 |
-
|
1139 |
-
|
1140 |
-
Mage::throwException('Invalid order id (' . $order_id . ')');
|
1141 |
-
}
|
1142 |
-
|
1143 |
-
$db->setFetchMode($old_fetch_mode);
|
1144 |
-
|
1145 |
-
$args = array
|
1146 |
-
(
|
1147 |
-
'token' => $payson_order->token,
|
1148 |
-
'action' => $action
|
1149 |
-
);
|
1150 |
-
|
1151 |
-
$client = $this->GetHttpClient(vsprintf(self::API_CALL_PAYMENT_UPDATE, $this->GetFormatIfTest($payson_order->store_id)))
|
1152 |
-
->setParameterPost($args);
|
1153 |
-
|
1154 |
-
$response = Payson_Payson_Helper_Api_Response_Standard
|
1155 |
-
::FromHttpBody($client->request()->getBody());
|
1156 |
-
|
1157 |
-
$this->SetResponse($response);
|
1158 |
-
|
1159 |
-
$db->insert($order_log_table, array
|
1160 |
-
(
|
1161 |
-
'payson_order_id' => $payson_order->id,
|
1162 |
-
'added' => new Zend_Db_Expr('NOW()'),
|
1163 |
-
'api_call' => 'payment_update',
|
1164 |
-
'valid' => (int)$response->IsValid(),
|
1165 |
-
'response' => serialize($response->ToArray())
|
1166 |
-
));
|
1167 |
-
|
1168 |
-
/*if(!$response->IsValid())
|
1169 |
-
{
|
1170 |
-
// TODO: don't seem to return an errorList
|
1171 |
-
throw new Mage_Core_Exception(sprintf($helper->__(
|
1172 |
-
'Failed to update payment. Payson replied: %s'),
|
1173 |
-
$response->GetError()), $response->GetErrorId());
|
1174 |
-
}*/
|
1175 |
-
|
1176 |
-
return $this;
|
1177 |
-
}
|
1178 |
-
|
1179 |
-
private function GetFormatIfTest($storeID = null, $isForwardURL = FALSE)
|
1180 |
-
{
|
1181 |
-
$config = Mage::getModel('payson/config');
|
1182 |
-
$stack = array();
|
1183 |
-
/* @var $isTest bool */
|
1184 |
-
$isTest = ($config->get('test_mode', $storeID) == "1");
|
1185 |
-
|
1186 |
-
array_push($stack, self::DEBUG_MODE ? "http" : "https");
|
1187 |
-
array_push($stack, $isTest && !self::DEBUG_MODE ? "test-" : (self::DEBUG_MODE && !$isForwardURL ? "mvc" : ""));
|
1188 |
-
|
1189 |
-
if($isForwardURL == true)
|
1190 |
-
{
|
1191 |
-
array_push($stack, self::DEBUG_MODE ? "app" : "www");
|
1192 |
-
}
|
1193 |
-
|
1194 |
-
array_push($stack, self::DEBUG_MODE ? "local" : "se");
|
1195 |
-
array_push($stack, self::DEBUG_MODE ? "Payment" : "1.0");
|
1196 |
-
|
1197 |
-
array_push($stack, self::DEBUG_MODE ? "" : "Payment");
|
1198 |
-
//print_r($stack);exit;
|
1199 |
-
return $stack;
|
1200 |
-
|
1201 |
-
|
1202 |
}
|
1203 |
-
|
1204 |
-
|
1205 |
-
|
1206 |
-
|
1207 |
-
|
1208 |
-
|
1209 |
-
|
1210 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1211 |
}
|
1212 |
-
|
1213 |
-
|
1214 |
-
|
1215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1216 |
<head>
|
1217 |
<meta http-equiv="Content-Type" content="text/html" charset="utf-8" />
|
1218 |
<script type="text/javascript">
|
1219 |
-
alert("'
|
1220 |
-
window.location="'.('/index.php').'";
|
1221 |
</script>
|
1222 |
</head>
|
1223 |
</html>';
|
1224 |
-
|
1225 |
-
|
1226 |
-
|
1227 |
-
|
1228 |
}
|
1229 |
|
1 |
<?php
|
2 |
+
|
3 |
+
class Payson_Payson_Helper_Api {
|
4 |
+
/*
|
5 |
+
* Constants
|
6 |
+
*/
|
7 |
+
|
8 |
+
const DEBUG_MODE = false;
|
9 |
+
const API_CALL_PAY = '%s://%sapi.payson.%s/%s/Pay/';
|
10 |
+
const API_CALL_VALIDATE = '%s://%sapi.payson.%s/%s/Validate/';
|
11 |
+
const API_CALL_PAYMENT_DETAILS = '%s://%sapi.payson.%s/%s/%sDetails/';
|
12 |
+
const API_CALL_PAYMENT_UPDATE = '%s://%sapi.payson.%s/%s/%sUpdate/';
|
13 |
+
const PAY_FORWARD_URL = '%s://%s%s.payson.%s/paySecure/';
|
14 |
+
const APPLICATION_ID = 'Magento Module 1.0';
|
15 |
+
const MODULE_NAME = 'payson_magento';
|
16 |
+
const MODULE_VERSION = '1.0';
|
17 |
+
const DEBUG_MODE_MAIL = 'testagent-1@payson.se';
|
18 |
+
const DEBUG_MODE_AGENT_ID = '1';
|
19 |
+
const DEBUG_MODE_MD5 = 'fddb19ac-7470-42b6-a91d-072cb1495f0a';
|
20 |
+
const STATUS_CREATED = 'CREATED';
|
21 |
+
const STATUS_PENDING = 'PENDING';
|
22 |
+
const STATUS_PROCESSING = 'PROCESSING';
|
23 |
+
const STATUS_COMPLETED = 'COMPLETED';
|
24 |
+
const STATUS_CREDITED = 'CREDITED';
|
25 |
+
const STATUS_INCOMPLETE = 'INCOMPLETE';
|
26 |
+
const STATUS_ERROR = 'ERROR';
|
27 |
+
const STATUS_EXPIRED = 'EXPIRED';
|
28 |
+
const STATUS_REVERSALERROR = 'REVERSALERROR';
|
29 |
+
const PAYMENT_METHOD_BANK = 'BANK';
|
30 |
+
const PAYMENT_METHOD_CREDITCARD = 'CREDITCARD';
|
31 |
+
const PAYMENT_METHOD_INVOICE = 'INVOICE';
|
32 |
+
const GUARANTEE_STATUS_WAITINGFORSEND = 'WAITINGFORSEND';
|
33 |
+
const GUARANTEE_STATUS_WAITINGFORACCEPTANCE = 'WAITINGFORACCEPTANCE';
|
34 |
+
const GUARANTEE_STATUS_WAITINGFORRETURN = 'WAITINGFORRETURN';
|
35 |
+
const GUARANTEE_STATUS_WAITINGFORRETURNACCEPTANCE = 'WAITINGFORRETURNACCEPTANCE';
|
36 |
+
const GUARANTEE_STATUS_RETURNNOTACCEPTED = 'RETURNNOTACCEPTED';
|
37 |
+
const GUARANTEE_STATUS_NOTRECEIVED = 'NOTRECEIVED';
|
38 |
+
const GUARANTEE_STATUS_RETURNNOTRECEIVED = 'RETURNNOTRECEIVED';
|
39 |
+
const GUARANTEE_STATUS_MONEYRETURNEDTOSENDER = 'MONEYRETURNEDTOSENDER';
|
40 |
+
const GUARANTEE_STATUS_RETURNACCEPTED = 'RETURNACCEPTED';
|
41 |
+
const INVOICE_STATUS_PENDING = 'PENDING';
|
42 |
+
const INVOICE_STATUS_ORDERCREATED = 'ORDERCREATED';
|
43 |
+
const INVOICE_STATUS_ORDERCANCELLED = 'ORDERCANCELLED';
|
44 |
+
const INVOICE_STATUS_SHIPPED = 'SHIPPED';
|
45 |
+
const INVOICE_STATUS_DONE = 'DONE';
|
46 |
+
const UPDATE_ACTION_CANCELORDER = 'CANCELORDER';
|
47 |
+
const UPDATE_ACTION_SHIPORDER = 'SHIPORDER';
|
48 |
+
const UPDATE_ACTION_CREDITORDER = 'CREDITORDER';
|
49 |
+
const UPDATE_ACTION_REFUNDORDER = 'REFUND';
|
50 |
+
const GUARANTEE_REQUIRED = 'REQUIRED';
|
51 |
+
const GUARANTEE_OPTIONAL = 'OPTIONAL';
|
52 |
+
const GUARANTEE_NO = 'NO';
|
53 |
+
|
54 |
+
/*
|
55 |
+
* Private properties
|
56 |
+
*/
|
57 |
+
|
58 |
+
private $response;
|
59 |
+
private $order_discount_item = 0.0;
|
60 |
+
|
61 |
+
/*
|
62 |
+
* Private methods
|
63 |
+
*/
|
64 |
+
|
65 |
+
private function GetHttpClient($url) {
|
66 |
+
$config = Mage::getModel('payson/config');
|
67 |
+
|
68 |
+
$http_client = new Zend_Http_Client($url);
|
69 |
+
|
70 |
+
$http_client->setMethod(Zend_Http_Client::POST)
|
71 |
+
->setHeaders(array
|
72 |
+
(
|
73 |
+
'PAYSON-SECURITY-USERID' => $config->get('test_mode') ? self::DEBUG_MODE_AGENT_ID : $config->Get('agent_id'),
|
74 |
+
'PAYSON-SECURITY-PASSWORD' => $config->get('test_mode') ? self::DEBUG_MODE_MD5 : $config->Get('md5_key'),
|
75 |
+
'PAYSON-APPLICATION-ID' => self::APPLICATION_ID,
|
76 |
+
'PAYSON-MODULE-INFO' => self::MODULE_NAME . '|' . self::MODULE_VERSION . '|' . Mage::getVersion()
|
77 |
+
));
|
78 |
+
|
79 |
+
return $http_client->resetParameters();
|
80 |
+
}
|
81 |
+
|
82 |
+
private function SetResponse(
|
83 |
+
Payson_Payson_Helper_Api_Response_Interface $response) {
|
84 |
+
$this->response = $response;
|
85 |
+
|
86 |
+
return $this;
|
87 |
+
}
|
88 |
+
|
89 |
+
private function SetOrderDiscountItem($item, &$total) {
|
90 |
+
$total -= $item->getData('discount_amount');
|
91 |
+
$this->order_discount_item += $item->getData('discount_amount');
|
92 |
+
}
|
93 |
+
|
94 |
+
/**
|
95 |
+
* Helper for Pay()
|
96 |
+
*
|
97 |
+
* @param object $item
|
98 |
+
* @param int $i
|
99 |
+
* @param int $total
|
100 |
+
* @return array
|
101 |
+
*/
|
102 |
+
private function GetOrderItemInfo($item, $i, &$total) {
|
103 |
+
$product = Mage::getModel('catalog/product')
|
104 |
+
->load($item->getProductId());
|
105 |
+
$children = $item->getChildrenItems();
|
106 |
+
|
107 |
+
if (!$product->isConfigurable() && count($children) &&
|
108 |
+
!$item->isChildrenCalculated()) {
|
109 |
+
$args = array();
|
110 |
+
foreach ($children as $child) {
|
111 |
+
$args += $this->GetOrderItemInfo($child, $i++, $total);
|
112 |
+
}
|
113 |
+
return $args;
|
114 |
}
|
115 |
|
116 |
+
if ($product->isConfigurable() && (count($children) === 1)) {
|
117 |
+
$name = $children[0]->getData('name');
|
118 |
+
$sku = $children[0]->getData('sku');
|
119 |
+
} else {
|
120 |
+
$name = $product->getData('name');
|
121 |
+
$sku = $item->getData('sku');
|
122 |
+
}
|
123 |
+
|
124 |
+
/* TODO: If tax_percent is not set?
|
125 |
+
Mage::getSingleton('tax/calculation')->getRate(
|
126 |
+
$tax_rate_req->setProductClassId($product->getTaxClassId()))
|
127 |
+
*/
|
128 |
+
$tax_mod = (float) $item->getData('tax_percent');
|
129 |
+
$tax_mod /= 100;
|
130 |
+
$tax_mod = round($tax_mod, 5);
|
131 |
+
|
132 |
+
$qty = (float) $item->getData('qty_ordered');
|
133 |
+
$qty = round($qty, 2);
|
134 |
+
|
135 |
+
$price = (float) $item->getData('row_total_incl_tax');
|
136 |
+
|
137 |
+
$base_price = (($price / (1 + $tax_mod)) / $qty);
|
138 |
+
$base_price = round($base_price, 3);
|
139 |
+
|
140 |
+
$total += (($base_price * (1 + $tax_mod)) * $qty);
|
141 |
+
|
142 |
+
return array
|
143 |
+
(
|
144 |
+
'orderItemList.orderItem(' . $i . ').description' =>
|
145 |
+
$name,
|
146 |
+
'orderItemList.orderItem(' . $i . ').sku' =>
|
147 |
+
$sku,
|
148 |
+
'orderItemList.orderItem(' . $i . ').quantity' =>
|
149 |
+
$qty,
|
150 |
+
'orderItemList.orderItem(' . $i . ').unitPrice' =>
|
151 |
+
$base_price,
|
152 |
+
'orderItemList.orderItem(' . $i . ').taxPercentage' =>
|
153 |
+
$tax_mod
|
154 |
+
);
|
155 |
+
}
|
156 |
+
|
157 |
+
/**
|
158 |
+
* Helper for Pay()
|
159 |
+
*
|
160 |
+
* @param object $order
|
161 |
+
* @param object $customer
|
162 |
+
* @param object $store
|
163 |
+
* @param int $i
|
164 |
+
* @param int $total
|
165 |
+
* @return array
|
166 |
+
*/
|
167 |
+
private function GetOrderShippingInfo($order, $customer, $store, $i, &$total) {
|
168 |
+
$tax_calc = Mage::getSingleton('tax/calculation');
|
169 |
+
|
170 |
+
$tax_rate_req = $tax_calc->getRateRequest(
|
171 |
+
$order->getShippingAddress(), $order->getBillingAddress(), $customer->getTaxClassId(), $store);
|
172 |
+
|
173 |
+
$args = array();
|
174 |
+
|
175 |
+
if (($price = (float) $order->getData('shipping_incl_tax')) > 0) {
|
176 |
+
$tax_mod = $tax_calc->getRate($tax_rate_req->setProductClassId(
|
177 |
+
Mage::getStoreConfig('tax/classes/shipping_tax_class')));
|
178 |
+
$tax_mod /= 100;
|
179 |
+
$tax_mod = round($tax_mod, 5);
|
180 |
+
|
181 |
+
$price -= (float) $order->getData('shipping_discount_amount');
|
182 |
+
|
183 |
+
$base_price = ($price / (1 + $tax_mod));
|
184 |
+
$base_price = round($base_price, 3);
|
185 |
+
|
186 |
+
$total += ($base_price * (1 + $tax_mod));
|
187 |
+
|
188 |
+
$args = array
|
189 |
+
(
|
190 |
+
'orderItemList.orderItem(' . $i . ').description' =>
|
191 |
+
$order->getData('shipping_description'),
|
192 |
+
'orderItemList.orderItem(' . $i . ').sku' =>
|
193 |
+
$order->getData('shipping_method'),
|
194 |
+
'orderItemList.orderItem(' . $i . ').quantity' =>
|
195 |
+
1,
|
196 |
+
'orderItemList.orderItem(' . $i . ').unitPrice' =>
|
197 |
+
$base_price,
|
198 |
+
'orderItemList.orderItem(' . $i . ').taxPercentage' =>
|
199 |
+
$tax_mod
|
200 |
+
);
|
201 |
+
}
|
202 |
+
return $args;
|
203 |
+
}
|
204 |
+
|
205 |
+
/*
|
206 |
+
* Public methods
|
207 |
+
*/
|
208 |
+
|
209 |
+
/**
|
210 |
+
* Get API response
|
211 |
+
*
|
212 |
+
* @return object
|
213 |
+
*/
|
214 |
+
public function GetResponse() {
|
215 |
+
return $this->response;
|
216 |
+
}
|
217 |
+
|
218 |
+
/**
|
219 |
+
* Get forward/redirect url after a successful Pay() call
|
220 |
+
*
|
221 |
+
* @return string
|
222 |
+
*/
|
223 |
+
public function GetPayForwardUrl() {
|
224 |
+
$url = vsprintf(self::PAY_FORWARD_URL . '?token=' . $this->GetResponse()->TOKEN, $this->GetFormatIfTest(null, true));
|
225 |
+
return $url;
|
226 |
+
}
|
227 |
+
|
228 |
+
/**
|
229 |
+
* http://api.payson.se/#title8
|
230 |
+
*
|
231 |
+
* @param object $order
|
232 |
+
* @return object $this
|
233 |
+
*/
|
234 |
+
public function Pay(Mage_Sales_Model_Order $order) {
|
235 |
+
$payment_method = $order->getPayment()->getMethod();
|
236 |
+
$helper = Mage::helper('payson');
|
237 |
+
$config = Mage::getModel('payson/config');
|
238 |
+
$store = Mage::app()->getStore($order->getStoreId());
|
239 |
+
$customer = Mage::getModel('customer/customer')
|
240 |
+
->load($order->getCustomerId());
|
241 |
+
$billing_address = $order->getBillingAddress();
|
242 |
+
|
243 |
+
// Need a two character locale code
|
244 |
+
$locale_code = Mage::getSingleton('core/locale')->getLocaleCode();
|
245 |
+
$locale_code = strtoupper(substr($locale_code, 0, 2));
|
246 |
+
|
247 |
+
if (!in_array($locale_code, array('SV', 'FI', 'EN'))) {
|
248 |
+
switch ($locale_code) {
|
249 |
+
case 'DA':
|
250 |
+
case 'NO': {
|
251 |
+
$locale_code = 'SV';
|
252 |
+
break;
|
253 |
+
}
|
254 |
+
default: {
|
255 |
+
$locale_code = 'EN';
|
256 |
+
}
|
257 |
+
}
|
258 |
+
}
|
259 |
+
|
260 |
+
// $args will contain the arguments of the API request to Payson
|
261 |
+
$args = array
|
262 |
+
(
|
263 |
+
'returnUrl' =>
|
264 |
+
Mage::getUrl('payson/checkout/return', array('_secure' => true)),
|
265 |
+
'cancelUrl' =>
|
266 |
+
Mage::getUrl('payson/checkout/cancel', array('_secure' => true)),
|
267 |
+
'ipnNotificationUrl' =>
|
268 |
+
Mage::getUrl('payson/ipn/notify', array('_secure' => true)),
|
269 |
+
'localeCode' =>
|
270 |
+
$locale_code,
|
271 |
+
'currencyCode' =>
|
272 |
+
//$order->getOrderCurrency()->getCode(),
|
273 |
+
//$order->getBaseCurrencyCode(),
|
274 |
+
strtoupper(substr($order->getOrderCurrency()->getCode(), 0, 3)),
|
275 |
+
'memo' =>
|
276 |
+
sprintf($helper->__('Order from %s'), $store->getUrl()),
|
277 |
+
'senderEmail' =>
|
278 |
+
$order->getCustomerEmail(),
|
279 |
+
'senderFirstName' =>
|
280 |
+
$billing_address->getFirstname(),
|
281 |
+
'senderLastName' =>
|
282 |
+
$billing_address->getLastname(),
|
283 |
+
'receiverList.receiver(0).email' =>
|
284 |
+
$config->get('test_mode') ? self::DEBUG_MODE_MAIL : $config->Get('email'),
|
285 |
+
'trackingId' => $order->getRealOrderId()
|
286 |
+
);
|
287 |
+
|
288 |
+
if (!$config->CanPaymentGuarantee()) {
|
289 |
+
$args['guaranteeOffered'] = self::GUARANTEE_NO;
|
290 |
+
}
|
291 |
+
|
292 |
+
if (($payment_method === 'payson_invoice')) {
|
293 |
+
if (!$config->CanInvoicePayment()) {
|
294 |
+
Mage::throwException('Invoice payment is disabled');
|
295 |
+
}
|
296 |
+
|
297 |
+
$args['fundingList.fundingConstraint(0).constraint'] =
|
298 |
+
self::PAYMENT_METHOD_INVOICE;
|
299 |
+
}
|
300 |
+
|
301 |
+
$i = 0;
|
302 |
+
$total = 0;
|
303 |
+
|
304 |
+
// Calculate price of each item in the order
|
305 |
+
foreach ($order->getAllVisibleItems() as $item) {
|
306 |
+
$args += $this->GetOrderItemInfo($item, $i++, $total);
|
307 |
+
}
|
308 |
+
|
309 |
+
foreach ($order->getAllVisibleItems() as $item) {
|
310 |
+
$this->SetOrderDiscountItem($item, $total);
|
311 |
+
}
|
312 |
+
if ($this->order_discount_item >> 0) {
|
313 |
+
$args += array
|
314 |
+
(
|
315 |
+
'orderItemList.orderItem(' . $i . ').description' =>
|
316 |
+
'discount',
|
317 |
+
'orderItemList.orderItem(' . $i . ').sku' =>
|
318 |
+
'discount',
|
319 |
+
'orderItemList.orderItem(' . $i . ').quantity' =>
|
320 |
+
1,
|
321 |
+
'orderItemList.orderItem(' . $i . ').unitPrice' =>
|
322 |
+
-$this->order_discount_item,
|
323 |
+
'orderItemList.orderItem(' . $i . ').taxPercentage' =>
|
324 |
+
0.0
|
325 |
+
);
|
326 |
+
}
|
327 |
+
// Calculate price for shipping
|
328 |
+
$args += $this->GetOrderShippingInfo($order, $customer, $store, $i++, $total);
|
329 |
+
/* echo '<pre>';
|
330 |
+
print_r($args);
|
331 |
+
echo '</pre>';exit; */
|
332 |
+
if ($order->getPaysonInvoiceFee() > 0) {
|
333 |
+
$fee = $order->getPaysonInvoiceFee();
|
334 |
+
/* $args += array
|
335 |
+
(
|
336 |
+
'orderItemList.orderItem(' . $i . ').description' =>
|
337 |
+
$helper->__('Invoice fee'),
|
338 |
+
'orderItemList.orderItem(' . $i . ').sku' =>
|
339 |
+
'invoice_fee',
|
340 |
+
'orderItemList.orderItem(' . $i . ').quantity' =>
|
341 |
+
1,
|
342 |
+
'orderItemList.orderItem(' . $i . ').unitPrice' =>
|
343 |
+
$config->GetInvoiceFee($order),
|
344 |
+
'orderItemList.orderItem(' . $i . ').taxPercentage' =>
|
345 |
+
$config->GetInvoiceFeeTaxMod($order)
|
346 |
+
);
|
347 |
+
|
348 |
+
$total += $config->GetInvoiceFeeInclTax($order); */
|
349 |
+
|
350 |
+
$args['invoiceFee'] = round((float) $fee, 3);
|
351 |
+
$total += $fee;
|
352 |
+
}
|
353 |
+
|
354 |
+
$total = round($total, 2);
|
355 |
+
|
356 |
+
$args['receiverList.receiver(0).amount'] = $total;
|
357 |
+
|
358 |
+
//echo('<pre>');print_r($args);exit(PHP_EOL . $order->getData('grand_total') . '</pre>');
|
359 |
+
$url = vsprintf(self::API_CALL_PAY, $this->GetFormatIfTest($order->getStoreId()));
|
360 |
+
$client = $this->GetHttpClient($url)
|
361 |
+
->setParameterPost($args);
|
362 |
+
|
363 |
+
$response = Payson_Payson_Helper_Api_Response_Standard
|
364 |
+
::FromHttpBody($client->request()->getBody());
|
365 |
+
|
366 |
+
$this->SetResponse($response);
|
367 |
+
|
368 |
+
$resource = Mage::getSingleton('core/resource');
|
369 |
+
$db = $resource->getConnection('core_write');
|
370 |
+
|
371 |
+
$order_table = $resource->getTableName('payson_order');
|
372 |
+
$order_log_table = $resource->getTableName('payson_order_log');
|
373 |
+
|
374 |
+
$db->insert($order_table, array
|
375 |
+
(
|
376 |
+
'order_id' => $order->getRealOrderId(),
|
377 |
+
'added' => new Zend_Db_Expr('NOW()'),
|
378 |
+
'updated' => new Zend_Db_Expr('NOW()'),
|
379 |
+
'valid' => (int) $response->IsValid(),
|
380 |
+
'token' => (isset($response->TOKEN) ? $response->TOKEN :
|
381 |
+
new Zend_Db_Expr('NULL')),
|
382 |
+
'store_id' => $order->getStoreId()
|
383 |
+
));
|
384 |
+
|
385 |
+
$payson_order_id = $db->lastInsertId();
|
386 |
+
|
387 |
+
$db->insert($order_log_table, array
|
388 |
+
(
|
389 |
+
'payson_order_id' => $payson_order_id,
|
390 |
+
'added' => new Zend_Db_Expr('NOW()'),
|
391 |
+
'api_call' => 'pay',
|
392 |
+
'valid' => (int) $response->IsValid(),
|
393 |
+
'response' => serialize($response->ToArray())
|
394 |
+
));
|
395 |
+
|
396 |
+
if (!$response->IsValid()) {
|
397 |
+
|
398 |
+
throw new Mage_Core_Exception(sprintf($helper->__(
|
399 |
+
'Failed to initialize payment. Payson replied: %s'), $response->GetError()), $response->GetErrorId());
|
400 |
+
}
|
401 |
+
|
402 |
+
return $this;
|
403 |
+
}
|
404 |
+
|
405 |
+
/**
|
406 |
+
* Implements the IPN procedure
|
407 |
+
*
|
408 |
+
* http://api.payson.se/#title11
|
409 |
+
*
|
410 |
+
* @param string $http_body
|
411 |
+
* @param string $content_type
|
412 |
+
* @return object $this
|
413 |
+
*/
|
414 |
+
public function Validate($http_body, $content_type) {
|
415 |
+
$helper = Mage::helper('payson');
|
416 |
+
$config = Mage::getModel('payson/config');
|
417 |
+
// Parse request done by Payson to our IPN controller
|
418 |
+
$ipn_response = Payson_Payson_Helper_Api_Response_Standard
|
419 |
+
::FromHttpBody($http_body);
|
420 |
+
|
421 |
+
// Get the database connection
|
422 |
+
$resource = Mage::getSingleton('core/resource');
|
423 |
+
$db = $resource->getConnection('core_write');
|
424 |
+
|
425 |
+
$order_table = $resource->getTableName('payson_order');
|
426 |
+
$order_log_table = $resource->getTableName('payson_order_log');
|
427 |
+
|
428 |
+
/* Save data sent by Payson, log entry as invalid by default, this
|
429 |
+
value will be changed later in this method if successful. No payson
|
430 |
+
order id is set, because we dont have one yet */
|
431 |
+
$db->insert($order_log_table, array
|
432 |
+
(
|
433 |
+
'added' => new Zend_Db_Expr('NOW()'),
|
434 |
+
'api_call' => 'validate',
|
435 |
+
'valid' => 0,
|
436 |
+
'response' => serialize($ipn_response->ToArray())
|
437 |
+
));
|
438 |
+
|
439 |
+
$order_log_id = $db->lastInsertId();
|
440 |
+
|
441 |
+
/* $ipn_response will never contain responseEnvelope.ack, as I first
|
442 |
+
thought it would */
|
443 |
+
/* if(!$ipn_response->IsValid())
|
444 |
+
{
|
445 |
+
Mage::throwException('Invalid request');
|
446 |
+
} */
|
447 |
+
|
448 |
+
/* Save fetch mode so that we can reset it and not mess up Magento
|
449 |
+
functionality */
|
450 |
+
$old_fetch_mode = $db->getFetchMode();
|
451 |
+
$db->setFetchMode(Zend_Db::FETCH_OBJ);
|
452 |
+
|
453 |
+
// Get payson order information and validate token
|
454 |
+
$payson_order = $db->fetchRow(
|
455 |
+
'SELECT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
456 |
id,
|
457 |
order_id,
|
458 |
store_id
|
465 |
LIMIT
|
466 |
0,1', $ipn_response->token);
|
467 |
|
468 |
+
if ($payson_order === false) {
|
469 |
+
Mage::throwException('Invalid token');
|
470 |
+
}
|
471 |
+
|
472 |
+
// Do the validate API call
|
473 |
+
$client = $this->GetHttpClient(vsprintf(self::API_CALL_VALIDATE, $this->GetFormatIfTest($payson_order->store_id)))
|
474 |
+
->setRawData($http_body, $content_type);
|
475 |
+
|
476 |
+
$response = Payson_Payson_Helper_Api_Response_Validate
|
477 |
+
::FromHttpBody($client->request()->getBody());
|
478 |
+
|
479 |
+
$this->SetResponse($response);
|
480 |
+
|
481 |
+
if (!$response->IsValid()) {
|
482 |
+
Mage::throwException('Validate call was unsuccessful');
|
483 |
+
}
|
484 |
+
|
485 |
+
|
486 |
+
|
487 |
+
// Update order log with payson order id
|
488 |
+
$db->update($order_log_table, array
|
489 |
+
(
|
490 |
+
'payson_order_id' => $payson_order->id
|
491 |
+
), array
|
492 |
+
(
|
493 |
+
'id = ?' => $order_log_id
|
494 |
+
));
|
495 |
+
|
496 |
+
// the order model does not expect FETCH_OBJ!
|
497 |
+
$db->setFetchMode($old_fetch_mode);
|
498 |
+
|
499 |
+
/**
|
500 |
+
* @var Mage_Sales_Model_Order
|
501 |
+
*/
|
502 |
+
$order = Mage::getModel('sales/order')
|
503 |
+
->loadByIncrementId($payson_order->order_id);
|
504 |
+
|
505 |
+
// Stop if order dont exist
|
506 |
+
if (is_null($order->getId())) {
|
507 |
+
Mage::throwException('Invalid order');
|
508 |
+
}
|
509 |
+
|
510 |
+
if ($order->getState() === Mage_Sales_Model_Order::STATE_COMPLETE) {
|
511 |
+
Mage::throwException('Order is no longer active');
|
512 |
+
}
|
513 |
+
|
514 |
+
$receivers = $ipn_response->receiverList->receiver->ToArray();
|
515 |
+
|
516 |
+
/* Verify payment amount. floor() since there might be a precision
|
517 |
+
difference */
|
518 |
+
if (floor((float) $receivers[0]['amount']) !==
|
519 |
+
floor((float) $order->getTotalDue())) {
|
520 |
+
Mage::throwException('Invalid amount');
|
521 |
+
}
|
522 |
+
|
523 |
+
switch ($ipn_response->status) {
|
524 |
+
case self::STATUS_COMPLETED: {
|
525 |
+
//Changes the status of the order from pending_payment to processing
|
526 |
+
$order->setState(
|
527 |
+
Mage_Sales_Model_Order::STATE_PROCESSING, Mage_Sales_Model_Order::STATE_PROCESSING,
|
528 |
+
//$helper->__('Payson completed the order payment XXXXXXX'));
|
529 |
+
$config->get('test_mode') ? $helper->__('Payson test completed the order payment') : $helper->__('Payson completed the order payment'));
|
530 |
+
|
531 |
+
//It creates the invoice to the order
|
532 |
+
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
|
533 |
+
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
|
534 |
+
$invoice->register();
|
535 |
+
$transactionSave = Mage::getModel('core/resource_transaction')
|
536 |
+
->addObject($invoice)
|
537 |
+
->addObject($invoice->getOrder());
|
538 |
+
$transactionSave->save();
|
539 |
+
|
540 |
+
break;
|
541 |
+
}
|
542 |
+
case self::STATUS_CREATED:
|
543 |
+
case self::STATUS_PENDING:
|
544 |
+
case self::STATUS_PROCESSING:
|
545 |
+
case self::STATUS_CREDITED: {
|
546 |
+
if (($ipn_response->status === self::STATUS_PENDING) &&
|
547 |
+
($ipn_response->type === self::PAYMENT_METHOD_INVOICE) &&
|
548 |
+
($ipn_response->invoiceStatus ===
|
549 |
+
self::INVOICE_STATUS_ORDERCREATED)) {
|
550 |
+
//Changes the status of the order from pending to processing
|
551 |
+
$order->setState(
|
552 |
+
Mage_Sales_Model_Order::STATE_PROCESSING, Mage_Sales_Model_Order::STATE_PROCESSING,
|
553 |
+
//$helper->__('Payson created an invoice'));
|
554 |
+
$config->get('test_mode') ? $helper->__('Payson test created an invoice') : $helper->__('Payson created an invoice'));
|
555 |
+
|
556 |
+
|
557 |
+
|
558 |
+
if (isset($ipn_response->shippingAddress)) {
|
559 |
+
$address_info = $ipn_response->shippingAddress
|
560 |
+
->ToArray();
|
561 |
+
|
562 |
+
$address = $order->getShippingAddress();
|
563 |
+
|
564 |
+
if (isset($address_info['name'])) {
|
565 |
+
$address->setFirstname($address_info['name']);
|
566 |
+
$address->setMiddlename('');
|
567 |
+
$address->setLastname('');
|
568 |
+
}
|
569 |
+
|
570 |
+
if (isset($address_info['streetAddress'])) {
|
571 |
+
$address->setStreet($address_info['streetAddress']);
|
572 |
+
}
|
573 |
+
|
574 |
+
if (isset($address_info['postalCode'])) {
|
575 |
+
$address->setPostcode($address_info['streetAddress']);
|
576 |
+
}
|
577 |
+
|
578 |
+
if (isset($address_info['city'])) {
|
579 |
+
$address->setCity($address_info['city']);
|
580 |
+
}
|
581 |
+
|
582 |
+
if (isset($address_info['country'])) {
|
583 |
+
// :(
|
584 |
+
$foo = array
|
585 |
+
(
|
586 |
+
'afghanistan' => 'AF',
|
587 |
+
'albania' => 'AL',
|
588 |
+
'algeria' => 'DZ',
|
589 |
+
'american samoa' => 'AS',
|
590 |
+
'andorra' => 'AD',
|
591 |
+
'angola' => 'AO',
|
592 |
+
'anguilla' => 'AI',
|
593 |
+
'antarctica' => 'AQ',
|
594 |
+
'antigua and barbuda' => 'AG',
|
595 |
+
'argentina' => 'AR',
|
596 |
+
'armenia' => 'AM',
|
597 |
+
'aruba' => 'AW',
|
598 |
+
'australia' => 'AU',
|
599 |
+
'austria' => 'AT',
|
600 |
+
'azerbaijan' => 'AZ',
|
601 |
+
'bahamas' => 'BS',
|
602 |
+
'bahrain' => 'BH',
|
603 |
+
'bangladesh' => 'BD',
|
604 |
+
'barbados' => 'BB',
|
605 |
+
'belarus' => 'BY',
|
606 |
+
'belgium' => 'BE',
|
607 |
+
'belize' => 'BZ',
|
608 |
+
'benin' => 'BJ',
|
609 |
+
'bermuda' => 'BM',
|
610 |
+
'bhutan' => 'BT',
|
611 |
+
'bolivia' => 'BO',
|
612 |
+
'bosnia and herzegovina' => 'BA',
|
613 |
+
'botswana' => 'BW',
|
614 |
+
'bouvet island' => 'BV',
|
615 |
+
'brazil' => 'BR',
|
616 |
+
'british indian ocean territory' => 'IO',
|
617 |
+
'brunei darussalam' => 'BN',
|
618 |
+
'bulgaria' => 'BG',
|
619 |
+
'burkina faso' => 'BF',
|
620 |
+
'burundi' => 'BI',
|
621 |
+
'cambodia' => 'KH',
|
622 |
+
'cameroon' => 'CM',
|
623 |
+
'canada' => 'CA',
|
624 |
+
'cape verde' => 'CV',
|
625 |
+
'cayman islands' => 'KY',
|
626 |
+
'central african republic' => 'CF',
|
627 |
+
'chad' => 'TD',
|
628 |
+
'chile' => 'CL',
|
629 |
+
'china' => 'CN',
|
630 |
+
'christmas island' => 'CX',
|
631 |
+
'cocos (keeling) islands' => 'CC',
|
632 |
+
'colombia' => 'CO',
|
633 |
+
'comoros' => 'KM',
|
634 |
+
'congo' => 'CG',
|
635 |
+
'congo, the democratic republic of the' => 'CD',
|
636 |
+
'cook islands' => 'CK',
|
637 |
+
'costa rica' => 'CR',
|
638 |
+
'cote d ivoire' => 'CI',
|
639 |
+
'croatia' => 'HR',
|
640 |
+
'cuba' => 'CU',
|
641 |
+
'cyprus' => 'CY',
|
642 |
+
'czech republic' => 'CZ',
|
643 |
+
'denmark' => 'DK',
|
644 |
+
'djibouti' => 'DJ',
|
645 |
+
'dominica' => 'DM',
|
646 |
+
'dominican republic' => 'DO',
|
647 |
+
'east timor' => 'TP',
|
648 |
+
'ecuador' => 'EC',
|
649 |
+
'egypt' => 'EG',
|
650 |
+
'el salvador' => 'SV',
|
651 |
+
'equatorial guinea' => 'GQ',
|
652 |
+
'eritrea' => 'ER',
|
653 |
+
'estonia' => 'EE',
|
654 |
+
'ethiopia' => 'ET',
|
655 |
+
'falkland islands (malvinas)' => 'FK',
|
656 |
+
'faroe islands' => 'FO',
|
657 |
+
'fiji' => 'FJ',
|
658 |
+
'finland' => 'FI',
|
659 |
+
'france' => 'FR',
|
660 |
+
'french guiana' => 'GF',
|
661 |
+
'french polynesia' => 'PF',
|
662 |
+
'french southern territories' => 'TF',
|
663 |
+
'gabon' => 'GA',
|
664 |
+
'gambia' => 'GM',
|
665 |
+
'georgia' => 'GE',
|
666 |
+
'germany' => 'DE',
|
667 |
+
'ghana' => 'GH',
|
668 |
+
'gibraltar' => 'GI',
|
669 |
+
'greece' => 'GR',
|
670 |
+
'greenland' => 'GL',
|
671 |
+
'grenada' => 'GD',
|
672 |
+
'guadeloupe' => 'GP',
|
673 |
+
'guam' => 'GU',
|
674 |
+
'guatemala' => 'GT',
|
675 |
+
'guinea' => 'GN',
|
676 |
+
'guinea-bissau' => 'GW',
|
677 |
+
'guyana' => 'GY',
|
678 |
+
'haiti' => 'HT',
|
679 |
+
'heard island and mcdonald islands' => 'HM',
|
680 |
+
'holy see (vatican city state)' => 'VA',
|
681 |
+
'honduras' => 'HN',
|
682 |
+
'hong kong' => 'HK',
|
683 |
+
'hungary' => 'HU',
|
684 |
+
'iceland' => 'IS',
|
685 |
+
'india' => 'IN',
|
686 |
+
'indonesia' => 'ID',
|
687 |
+
'iran, islamic republic of' => 'IR',
|
688 |
+
'iraq' => 'IQ',
|
689 |
+
'ireland' => 'IE',
|
690 |
+
'israel' => 'IL',
|
691 |
+
'italy' => 'IT',
|
692 |
+
'jamaica' => 'JM',
|
693 |
+
'japan' => 'JP',
|
694 |
+
'jordan' => 'JO',
|
695 |
+
'kazakstan' => 'KZ',
|
696 |
+
'kenya' => 'KE',
|
697 |
+
'kiribati' => 'KI',
|
698 |
+
'korea democratic peoples republic of' => 'KP',
|
699 |
+
'korea republic of' => 'KR',
|
700 |
+
'kuwait' => 'KW',
|
701 |
+
'kyrgyzstan' => 'KG',
|
702 |
+
'lao peoples democratic republic' => 'LA',
|
703 |
+
'latvia' => 'LV',
|
704 |
+
'lebanon' => 'LB',
|
705 |
+
'lesotho' => 'LS',
|
706 |
+
'liberia' => 'LR',
|
707 |
+
'libyan arab jamahiriya' => 'LY',
|
708 |
+
'liechtenstein' => 'LI',
|
709 |
+
'lithuania' => 'LT',
|
710 |
+
'luxembourg' => 'LU',
|
711 |
+
'macau' => 'MO',
|
712 |
+
'macedonia, the former yugoslav republic of' => 'MK',
|
713 |
+
'madagascar' => 'MG',
|
714 |
+
'malawi' => 'MW',
|
715 |
+
'malaysia' => 'MY',
|
716 |
+
'maldives' => 'MV',
|
717 |
+
'mali' => 'ML',
|
718 |
+
'malta' => 'MT',
|
719 |
+
'marshall islands' => 'MH',
|
720 |
+
'martinique' => 'MQ',
|
721 |
+
'mauritania' => 'MR',
|
722 |
+
'mauritius' => 'MU',
|
723 |
+
'mayotte' => 'YT',
|
724 |
+
'mexico' => 'MX',
|
725 |
+
'micronesia, federated states of' => 'FM',
|
726 |
+
'moldova, republic of' => 'MD',
|
727 |
+
'monaco' => 'MC',
|
728 |
+
'mongolia' => 'MN',
|
729 |
+
'montserrat' => 'MS',
|
730 |
+
'morocco' => 'MA',
|
731 |
+
'mozambique' => 'MZ',
|
732 |
+
'myanmar' => 'MM',
|
733 |
+
'namibia' => 'NA',
|
734 |
+
'nauru' => 'NR',
|
735 |
+
'nepal' => 'NP',
|
736 |
+
'netherlands' => 'NL',
|
737 |
+
'netherlands antilles' => 'AN',
|
738 |
+
'new caledonia' => 'NC',
|
739 |
+
'new zealand' => 'NZ',
|
740 |
+
'nicaragua' => 'NI',
|
741 |
+
'niger' => 'NE',
|
742 |
+
'nigeria' => 'NG',
|
743 |
+
'niue' => 'NU',
|
744 |
+
'norfolk island' => 'NF',
|
745 |
+
'northern mariana islands' => 'MP',
|
746 |
+
'norway' => 'NO',
|
747 |
+
'oman' => 'OM',
|
748 |
+
'pakistan' => 'PK',
|
749 |
+
'palau' => 'PW',
|
750 |
+
'palestinian territory, occupied' => 'PS',
|
751 |
+
'panama' => 'PA',
|
752 |
+
'papua new guinea' => 'PG',
|
753 |
+
'paraguay' => 'PY',
|
754 |
+
'peru' => 'PE',
|
755 |
+
'philippines' => 'PH',
|
756 |
+
'pitcairn' => 'PN',
|
757 |
+
'poland' => 'PL',
|
758 |
+
'portugal' => 'PT',
|
759 |
+
'puerto rico' => 'PR',
|
760 |
+
'qatar' => 'QA',
|
761 |
+
'reunion' => 'RE',
|
762 |
+
'romania' => 'RO',
|
763 |
+
'russian federation' => 'RU',
|
764 |
+
'rwanda' => 'RW',
|
765 |
+
'saint helena' => 'SH',
|
766 |
+
'saint kitts and nevis' => 'KN',
|
767 |
+
'saint lucia' => 'LC',
|
768 |
+
'saint pierre and miquelon' => 'PM',
|
769 |
+
'saint vincent and the grenadines' => 'VC',
|
770 |
+
'samoa' => 'WS',
|
771 |
+
'san marino' => 'SM',
|
772 |
+
'sao tome and principe' => 'ST',
|
773 |
+
'saudi arabia' => 'SA',
|
774 |
+
'senegal' => 'SN',
|
775 |
+
'seychelles' => 'SC',
|
776 |
+
'sierra leone' => 'SL',
|
777 |
+
'singapore' => 'SG',
|
778 |
+
'slovakia' => 'SK',
|
779 |
+
'slovenia' => 'SI',
|
780 |
+
'solomon islands' => 'SB',
|
781 |
+
'somalia' => 'SO',
|
782 |
+
'south africa' => 'ZA',
|
783 |
+
'south georgia and the south sandwich islands' => 'GS',
|
784 |
+
'spain' => 'ES',
|
785 |
+
'sri lanka' => 'LK',
|
786 |
+
'sudan' => 'SD',
|
787 |
+
'suriname' => 'SR',
|
788 |
+
'svalbard and jan mayen' => 'SJ',
|
789 |
+
'swaziland' => 'SZ',
|
790 |
+
'sweden' => 'SE',
|
791 |
+
'switzerland' => 'CH',
|
792 |
+
'syrian arab republic' => 'SY',
|
793 |
+
'taiwan, province of china' => 'TW',
|
794 |
+
'tajikistan' => 'TJ',
|
795 |
+
'tanzania, united republic of' => 'TZ',
|
796 |
+
'thailand' => 'TH',
|
797 |
+
'togo' => 'TG',
|
798 |
+
'tokelau' => 'TK',
|
799 |
+
'tonga' => 'TO',
|
800 |
+
'trinidad and tobago' => 'TT',
|
801 |
+
'tunisia' => 'TN',
|
802 |
+
'turkey' => 'TR',
|
803 |
+
'turkmenistan' => 'TM',
|
804 |
+
'turks and caicos islands' => 'TC',
|
805 |
+
'tuvalu' => 'TV',
|
806 |
+
'uganda' => 'UG',
|
807 |
+
'ukraine' => 'UA',
|
808 |
+
'united arab emirates' => 'AE',
|
809 |
+
'united kingdom' => 'GB',
|
810 |
+
'united states' => 'US',
|
811 |
+
'united states minor outlying islands' => 'UM',
|
812 |
+
'uruguay' => 'UY',
|
813 |
+
'uzbekistan' => 'UZ',
|
814 |
+
'vanuatu' => 'VU',
|
815 |
+
'venezuela' => 'VE',
|
816 |
+
'viet nam' => 'VN',
|
817 |
+
'virgin islands, british' => 'VG',
|
818 |
+
'virgin islands, u.s.' => 'VI',
|
819 |
+
'wallis and futuna' => 'WF',
|
820 |
+
'western sahara' => 'EH',
|
821 |
+
'yemen' => 'YE',
|
822 |
+
'yugoslavia' => 'YU',
|
823 |
+
'zambia' => 'ZM',
|
824 |
+
'zimbabwe' => 'ZW'
|
825 |
+
);
|
826 |
+
|
827 |
+
$address_info['country'] = strtolower(
|
828 |
+
$address_info['country']);
|
829 |
+
|
830 |
+
if (isset($foo[$address_info['country']])) {
|
831 |
+
$address->setCountryId(
|
832 |
+
$foo[$address_info['country']]);
|
833 |
+
}
|
834 |
+
}
|
835 |
+
|
836 |
+
$address->save();
|
837 |
+
$order->addStatusHistoryComment(sprintf($helper->__(
|
838 |
+
'Payson updated the shipping address')));
|
839 |
+
}
|
840 |
+
} else {
|
841 |
+
$order->addStatusHistoryComment(sprintf(
|
842 |
+
$helper->__('Payson pinged the order with status %s'), $ipn_response->status));
|
843 |
+
}
|
844 |
+
|
845 |
+
break;
|
846 |
+
}
|
847 |
+
|
848 |
+
case self::STATUS_ERROR:
|
849 |
+
|
850 |
+
$order->cancel();
|
851 |
+
|
852 |
+
$order->addStatusHistoryComment($helper->__('The order was denied by Payson.'));
|
853 |
+
|
854 |
+
break;
|
855 |
+
|
856 |
+
case self::STATUS_INCOMPLETE:
|
857 |
+
case self::STATUS_EXPIRED:
|
858 |
+
case self::STATUS_REVERSALERROR:
|
859 |
+
default: {
|
860 |
+
$order->cancel();
|
861 |
+
}
|
862 |
+
}
|
863 |
+
|
864 |
+
$order->save();
|
865 |
+
|
866 |
+
// Update the database tables
|
867 |
+
$db->update($order_log_table, array
|
868 |
+
(
|
869 |
+
'valid' => 1
|
870 |
+
), array
|
871 |
+
(
|
872 |
+
'id = ?' => $order_log_id
|
873 |
+
));
|
874 |
+
|
875 |
+
$db->update($order_table, array
|
876 |
+
(
|
877 |
+
'ipn_status' => $ipn_response->status
|
878 |
+
), array
|
879 |
+
(
|
880 |
+
'id = ?' => $payson_order->id
|
881 |
+
));
|
882 |
+
|
883 |
+
return $this;
|
884 |
+
}
|
885 |
+
|
886 |
+
/**
|
887 |
+
* http://api.payson.se/#title12
|
888 |
+
*
|
889 |
+
* @params int $order_id Real order id
|
890 |
+
* @return object $this
|
891 |
+
*/
|
892 |
+
public function PaymentDetails($order_id) {
|
893 |
+
$helper = Mage::helper('payson');
|
894 |
+
|
895 |
+
// Get the database connection
|
896 |
+
$resource = Mage::getSingleton('core/resource');
|
897 |
+
$db = $resource->getConnection('core_write');
|
898 |
+
|
899 |
+
$order_table = $resource->getTableName('payson_order');
|
900 |
+
$order_log_table = $resource->getTableName('payson_order_log');
|
901 |
+
|
902 |
+
/* Save fetch mode so that we can reset it and not mess up Magento
|
903 |
+
functionality */
|
904 |
+
$old_fetch_mode = $db->getFetchMode();
|
905 |
+
$db->setFetchMode(Zend_Db::FETCH_OBJ);
|
906 |
+
|
907 |
+
// Get payson order information and validate token
|
908 |
+
$payson_order = $db->fetchRow(
|
909 |
+
'SELECT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
910 |
id,
|
911 |
token,
|
912 |
store_id
|
919 |
LIMIT
|
920 |
0,1', $order_id);
|
921 |
|
922 |
+
if ($payson_order === false) {
|
923 |
+
Mage::throwException('Invalid order id (' . $order_id . ')');
|
924 |
+
}
|
925 |
+
|
926 |
+
$db->setFetchMode($old_fetch_mode);
|
927 |
+
|
928 |
+
$args = array
|
929 |
+
(
|
930 |
+
'token' => $payson_order->token
|
931 |
+
);
|
932 |
+
$url = vsprintf(self::API_CALL_PAYMENT_DETAILS, $this->GetFormatIfTest($payson_order->store_id));
|
933 |
+
|
934 |
+
$client = $this->GetHttpClient($url)
|
935 |
+
->setParameterPost($args);
|
936 |
+
|
937 |
+
$response = Payson_Payson_Helper_Api_Response_Standard
|
938 |
+
::FromHttpBody($client->request()->getBody());
|
939 |
+
|
940 |
+
$this->SetResponse($response);
|
941 |
+
|
942 |
+
$db->insert($order_log_table, array
|
943 |
+
(
|
944 |
+
'payson_order_id' => $payson_order->id,
|
945 |
+
'added' => new Zend_Db_Expr('NOW()'),
|
946 |
+
'api_call' => 'payment_details',
|
947 |
+
'valid' => (int) $response->IsValid(),
|
948 |
+
'response' => serialize($response->ToArray())
|
949 |
+
));
|
950 |
+
|
951 |
+
if (!$response->IsValid()) {
|
952 |
+
throw new Mage_Core_Exception(sprintf($helper->__(
|
953 |
+
'Failed to retrieve payment details. Payson replied: %s'), $response->GetError()), $response->GetErrorId());
|
954 |
+
}
|
955 |
+
|
956 |
+
return $this;
|
957 |
+
}
|
958 |
+
|
959 |
+
/**
|
960 |
+
* http://api.payson.se/#title13
|
961 |
+
*
|
962 |
+
* @params int $order_id Real order id
|
963 |
+
* @params string $action
|
964 |
+
* @return object $this
|
965 |
+
*/
|
966 |
+
public function PaymentUpdate($order_id, $action) {
|
967 |
+
$helper = Mage::helper('payson');
|
968 |
+
|
969 |
+
// Get the database connection
|
970 |
+
$resource = Mage::getSingleton('core/resource');
|
971 |
+
$db = $resource->getConnection('core_write');
|
972 |
+
|
973 |
+
$order_table = $resource->getTableName('payson_order');
|
974 |
+
$order_log_table = $resource->getTableName('payson_order_log');
|
975 |
+
|
976 |
+
/* Save fetch mode so that we can reset it and not mess up Magento
|
977 |
+
functionality */
|
978 |
+
$old_fetch_mode = $db->getFetchMode();
|
979 |
+
$db->setFetchMode(Zend_Db::FETCH_OBJ);
|
980 |
+
|
981 |
+
// Get payson order information and validate token
|
982 |
+
$payson_order = $db->fetchRow(
|
983 |
+
'SELECT
|
|
|
|
|
|
|
|
|
984 |
id,
|
985 |
token,
|
986 |
store_id
|
993 |
LIMIT
|
994 |
0,1', $order_id);
|
995 |
|
996 |
+
if ($payson_order === false) {
|
997 |
+
Mage::throwException('Invalid order id (' . $order_id . ')');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
998 |
}
|
999 |
+
|
1000 |
+
$db->setFetchMode($old_fetch_mode);
|
1001 |
+
|
1002 |
+
$args = array
|
1003 |
+
(
|
1004 |
+
'token' => $payson_order->token,
|
1005 |
+
'action' => $action
|
1006 |
+
);
|
1007 |
+
|
1008 |
+
$client = $this->GetHttpClient(vsprintf(self::API_CALL_PAYMENT_UPDATE, $this->GetFormatIfTest($payson_order->store_id)))
|
1009 |
+
->setParameterPost($args);
|
1010 |
+
|
1011 |
+
$response = Payson_Payson_Helper_Api_Response_Standard
|
1012 |
+
::FromHttpBody($client->request()->getBody());
|
1013 |
+
|
1014 |
+
$this->SetResponse($response);
|
1015 |
+
|
1016 |
+
$db->insert($order_log_table, array
|
1017 |
+
(
|
1018 |
+
'payson_order_id' => $payson_order->id,
|
1019 |
+
'added' => new Zend_Db_Expr('NOW()'),
|
1020 |
+
'api_call' => 'payment_update',
|
1021 |
+
'valid' => (int) $response->IsValid(),
|
1022 |
+
'response' => serialize($response->ToArray())
|
1023 |
+
));
|
1024 |
+
|
1025 |
+
/* if(!$response->IsValid())
|
1026 |
+
{
|
1027 |
+
// TODO: don't seem to return an errorList
|
1028 |
+
throw new Mage_Core_Exception(sprintf($helper->__(
|
1029 |
+
'Failed to update payment. Payson replied: %s'),
|
1030 |
+
$response->GetError()), $response->GetErrorId());
|
1031 |
+
} */
|
1032 |
+
|
1033 |
+
return $this;
|
1034 |
+
}
|
1035 |
+
|
1036 |
+
private function GetFormatIfTest($storeID = null, $isForwardURL = FALSE) {
|
1037 |
+
$config = Mage::getModel('payson/config');
|
1038 |
+
$stack = array();
|
1039 |
+
/* @var $isTest bool */
|
1040 |
+
$isTest = ($config->get('test_mode', $storeID) == "1");
|
1041 |
+
|
1042 |
+
array_push($stack, self::DEBUG_MODE ? "http" : "https");
|
1043 |
+
array_push($stack, $isTest && !self::DEBUG_MODE ? "test-" : (self::DEBUG_MODE && !$isForwardURL ? "mvc" : ""));
|
1044 |
+
|
1045 |
+
if ($isForwardURL == true) {
|
1046 |
+
array_push($stack, self::DEBUG_MODE ? "app" : "www");
|
1047 |
}
|
1048 |
+
|
1049 |
+
array_push($stack, self::DEBUG_MODE ? "local" : "se");
|
1050 |
+
array_push($stack, self::DEBUG_MODE ? "Payment" : "1.0");
|
1051 |
+
|
1052 |
+
array_push($stack, self::DEBUG_MODE ? "" : "Payment");
|
1053 |
+
//print_r($stack);exit;
|
1054 |
+
return $stack;
|
1055 |
+
}
|
1056 |
+
|
1057 |
+
public function getIpnStatus($order_id) {
|
1058 |
+
$resource = Mage::getSingleton('core/resource');
|
1059 |
+
$db = $resource->getConnection('core_write');
|
1060 |
+
$order_table = $resource->getTableName('payson_order');
|
1061 |
+
$query = 'SELECT ipn_status FROM `' . $order_table . '` WHERE order_id = ' . $order_id;
|
1062 |
+
return $db->fetchRow($query);
|
1063 |
+
}
|
1064 |
+
|
1065 |
+
public function paysonApiError($error) {
|
1066 |
+
$error_code = '<html>
|
1067 |
<head>
|
1068 |
<meta http-equiv="Content-Type" content="text/html" charset="utf-8" />
|
1069 |
<script type="text/javascript">
|
1070 |
+
alert("' . $error . '");
|
1071 |
+
window.location="' . ('/index.php') . '";
|
1072 |
</script>
|
1073 |
</head>
|
1074 |
</html>';
|
1075 |
+
echo $error_code;
|
1076 |
+
exit;
|
1077 |
+
}
|
1078 |
+
|
1079 |
}
|
1080 |
|
app/code/community/Payson/Payson/Helper/Api/Response/Interface.php
CHANGED
@@ -1,19 +1,20 @@
|
|
1 |
<?php
|
2 |
-
interface Payson_Payson_Helper_Api_Response_Interface
|
3 |
-
{
|
4 |
-
/**
|
5 |
-
* Construct a response object from a string
|
6 |
-
*
|
7 |
-
* @param string $body
|
8 |
-
* @return object
|
9 |
-
*/
|
10 |
-
public static function FromHttpBody($body);
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
}
|
19 |
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
interface Payson_Payson_Helper_Api_Response_Interface {
|
4 |
+
|
5 |
+
/**
|
6 |
+
* Construct a response object from a string
|
7 |
+
*
|
8 |
+
* @param string $body
|
9 |
+
* @return object
|
10 |
+
*/
|
11 |
+
public static function FromHttpBody($body);
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Whether this response is valid
|
15 |
+
*
|
16 |
+
* @return bool
|
17 |
+
*/
|
18 |
+
public function IsValid();
|
19 |
}
|
20 |
|
app/code/community/Payson/Payson/Helper/Api/Response/Standard.php
CHANGED
@@ -1,153 +1,131 @@
|
|
1 |
<?php
|
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 |
-
* Get first error id
|
134 |
-
*
|
135 |
-
* @return int|null
|
136 |
-
*/
|
137 |
-
public function GetErrorId()
|
138 |
-
{
|
139 |
-
if(isset($this->errorList->error))
|
140 |
-
{
|
141 |
-
foreach($this->errorList->error->ToArray() as $error)
|
142 |
-
{
|
143 |
-
if(isset($error['errorId']))
|
144 |
-
{
|
145 |
-
return (int)$error['errorId'];
|
146 |
-
}
|
147 |
-
}
|
148 |
-
}
|
149 |
-
|
150 |
-
return null;
|
151 |
-
}
|
152 |
}
|
153 |
|
1 |
<?php
|
2 |
+
|
3 |
+
class Payson_Payson_Helper_Api_Response_Standard extends Payson_Payson_Helper_Api_Response_Standard_Parameters implements Payson_Payson_Helper_Api_Response_Interface {
|
4 |
+
/*
|
5 |
+
* Constants
|
6 |
+
*/
|
7 |
+
|
8 |
+
const ACK_SUCCESS = 'SUCCESS';
|
9 |
+
const ACK_FAILURE = 'FAILURE';
|
10 |
+
|
11 |
+
/*
|
12 |
+
* Public methods
|
13 |
+
*/
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Parse response object and instantiate
|
17 |
+
*
|
18 |
+
* @param string $response
|
19 |
+
* @return object
|
20 |
+
*/
|
21 |
+
static public function FromHttpBody($body) {
|
22 |
+
$params = array();
|
23 |
+
parse_str($body, $params);
|
24 |
+
|
25 |
+
foreach ($params as $key => $value) {
|
26 |
+
$sub_key = strtok($key, '_');
|
27 |
+
|
28 |
+
if ($sub_key === $key) {
|
29 |
+
continue;
|
30 |
+
}
|
31 |
+
|
32 |
+
$current = &$params;
|
33 |
+
|
34 |
+
do {
|
35 |
+
$matches = array();
|
36 |
+
|
37 |
+
if (preg_match('/\((\d)\)$/', $sub_key, $matches) === 1) {
|
38 |
+
$sub_key = substr($sub_key, 0, -3);
|
39 |
+
|
40 |
+
if (!strlen($sub_key)) {
|
41 |
+
continue;
|
42 |
+
}
|
43 |
+
}
|
44 |
+
|
45 |
+
if (!isset($current[$sub_key]) || !is_array($current[$sub_key])) {
|
46 |
+
$current[$sub_key] = array();
|
47 |
+
}
|
48 |
+
|
49 |
+
$current = &$current[$sub_key];
|
50 |
+
|
51 |
+
if (isset($matches[1])) {
|
52 |
+
if (!isset($current[$matches[1]]) ||
|
53 |
+
!is_array($current[$matches[1]])) {
|
54 |
+
$current[$matches[1]] = array();
|
55 |
+
}
|
56 |
+
|
57 |
+
$current = &$current[$matches[1]];
|
58 |
+
}
|
59 |
+
} while (($sub_key = strtok('_')) !== false);
|
60 |
+
|
61 |
+
$current = $value;
|
62 |
+
|
63 |
+
unset($params[$key]);
|
64 |
+
}
|
65 |
+
|
66 |
+
return new self($params);
|
67 |
+
}
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Populate parameters
|
71 |
+
*
|
72 |
+
* @param array $params
|
73 |
+
* @return void
|
74 |
+
*/
|
75 |
+
public function __construct(array $params) {
|
76 |
+
if (empty($params)) {
|
77 |
+
Mage::throwException('Invalid response');
|
78 |
+
}
|
79 |
+
|
80 |
+
parent::__construct($params);
|
81 |
+
}
|
82 |
+
|
83 |
+
/**
|
84 |
+
* @inheritDoc
|
85 |
+
*/
|
86 |
+
public function IsValid() {
|
87 |
+
return (isset($this->responseEnvelope->ack) &&
|
88 |
+
($this->responseEnvelope->ack === self::ACK_SUCCESS));
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Compile all errors into a string
|
93 |
+
*
|
94 |
+
* @return string
|
95 |
+
*/
|
96 |
+
public function GetError() {
|
97 |
+
$ret = '';
|
98 |
+
|
99 |
+
if (isset($this->errorList->error)) {
|
100 |
+
foreach ($this->errorList->error->ToArray() as $error) {
|
101 |
+
if (isset($error['parameter'])) {
|
102 |
+
$ret .= $error['parameter'] . ' ';
|
103 |
+
}
|
104 |
+
|
105 |
+
$ret .= '(' . $error['errorId'] . ') ' .
|
106 |
+
$error['message'] . ' ';
|
107 |
+
}
|
108 |
+
}
|
109 |
+
|
110 |
+
return rtrim($ret);
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Get first error id
|
115 |
+
*
|
116 |
+
* @return int|null
|
117 |
+
*/
|
118 |
+
public function GetErrorId() {
|
119 |
+
if (isset($this->errorList->error)) {
|
120 |
+
foreach ($this->errorList->error->ToArray() as $error) {
|
121 |
+
if (isset($error['errorId'])) {
|
122 |
+
return (int) $error['errorId'];
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
|
127 |
+
return null;
|
128 |
+
}
|
129 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
}
|
131 |
|
app/code/community/Payson/Payson/Helper/Api/Response/Standard/Parameters.php
CHANGED
@@ -1,78 +1,66 @@
|
|
1 |
<?php
|
2 |
-
class Payson_Payson_Helper_Api_Response_Standard_Parameters
|
3 |
-
{
|
4 |
-
/*
|
5 |
-
* Protected properties
|
6 |
-
*/
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
*/
|
13 |
-
protected $params = array();
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
* @param arary $params
|
23 |
-
* @return void
|
24 |
-
*/
|
25 |
-
public function __construct(array $params)
|
26 |
-
{
|
27 |
-
foreach($params as $key => $value)
|
28 |
-
{
|
29 |
-
if(is_array($value))
|
30 |
-
{
|
31 |
-
$this->params[$key] = new self($value);
|
32 |
-
}
|
33 |
-
else
|
34 |
-
{
|
35 |
-
$this->params[$key] = $value;
|
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 |
-
return $arr;
|
76 |
-
}
|
77 |
}
|
78 |
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
class Payson_Payson_Helper_Api_Response_Standard_Parameters {
|
4 |
+
/*
|
5 |
+
* Protected properties
|
6 |
+
*/
|
|
|
|
|
7 |
|
8 |
+
/**
|
9 |
+
* Multi-dimensional array containing parameters from the response
|
10 |
+
*
|
11 |
+
* @var array
|
12 |
+
*/
|
13 |
+
protected $params = array();
|
14 |
|
15 |
+
/*
|
16 |
+
* Public methods
|
17 |
+
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
+
/**
|
20 |
+
* Constructor!
|
21 |
+
*
|
22 |
+
* @param arary $params
|
23 |
+
* @return void
|
24 |
+
*/
|
25 |
+
public function __construct(array $params) {
|
26 |
+
foreach ($params as $key => $value) {
|
27 |
+
if (is_array($value)) {
|
28 |
+
$this->params[$key] = new self($value);
|
29 |
+
} else {
|
30 |
+
$this->params[$key] = $value;
|
31 |
+
}
|
32 |
+
}
|
33 |
+
}
|
34 |
|
35 |
+
public function __get($name) {
|
36 |
+
return (isset($this->params[$name]) ? $this->params[$name] : null);
|
37 |
+
}
|
|
|
38 |
|
39 |
+
public function __set($name, $value) {
|
40 |
+
$this->params[$name] = $value;
|
41 |
+
}
|
|
|
42 |
|
43 |
+
public function __isset($name) {
|
44 |
+
return isset($this->params[$name]);
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Compile the parameters into an array
|
49 |
+
*
|
50 |
+
* @return array
|
51 |
+
*/
|
52 |
+
public function ToArray() {
|
53 |
+
foreach ($this->params as $key => $value) {
|
54 |
+
if ($value instanceof
|
55 |
+
Payson_Payson_Helper_Api_Response_Standard_Parameters) {
|
56 |
+
$arr[$key] = $value->ToArray();
|
57 |
+
} else {
|
58 |
+
$arr[$key] = $value;
|
59 |
+
}
|
60 |
+
}
|
61 |
+
|
62 |
+
return $arr;
|
63 |
+
}
|
64 |
|
|
|
|
|
65 |
}
|
66 |
|
app/code/community/Payson/Payson/Helper/Api/Response/Validate.php
CHANGED
@@ -1,49 +1,46 @@
|
|
1 |
<?php
|
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 |
-
return ($this->data === self::VERIFIED);
|
47 |
-
}
|
48 |
}
|
49 |
|
1 |
<?php
|
2 |
+
|
3 |
+
class Payson_Payson_Helper_Api_Response_Validate implements Payson_Payson_Helper_Api_Response_Interface {
|
4 |
+
/*
|
5 |
+
* Constants
|
6 |
+
*/
|
7 |
+
|
8 |
+
const VERIFIED = 'VERIFIED';
|
9 |
+
const INVALID = 'INVALID';
|
10 |
+
|
11 |
+
/*
|
12 |
+
* Private properties
|
13 |
+
*/
|
14 |
+
|
15 |
+
private $data;
|
16 |
+
|
17 |
+
/*
|
18 |
+
* Public methods
|
19 |
+
*/
|
20 |
+
|
21 |
+
/**
|
22 |
+
* @inheritDoc
|
23 |
+
*/
|
24 |
+
static public function FromHttpBody($data) {
|
25 |
+
return new self($data);
|
26 |
+
}
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Constructor!
|
30 |
+
*
|
31 |
+
* @param string $data
|
32 |
+
* @return void
|
33 |
+
*/
|
34 |
+
public function __construct($data) {
|
35 |
+
$this->data = $data;
|
36 |
+
}
|
37 |
+
|
38 |
+
/**
|
39 |
+
* @inheritDoc
|
40 |
+
*/
|
41 |
+
public function IsValid() {
|
42 |
+
return ($this->data === self::VERIFIED);
|
43 |
+
}
|
44 |
+
|
|
|
|
|
|
|
45 |
}
|
46 |
|
app/code/community/Payson/Payson/Helper/Data.php
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
<?php
|
2 |
-
class Payson_Payson_Helper_Data extends Mage_Core_Helper_Abstract
|
3 |
-
{
|
4 |
|
|
|
|
|
5 |
}
|
6 |
|
1 |
<?php
|
|
|
|
|
2 |
|
3 |
+
class Payson_Payson_Helper_Data extends Mage_Core_Helper_Abstract {
|
4 |
+
|
5 |
}
|
6 |
|
app/code/community/Payson/Payson/Model/Config.php
CHANGED
@@ -1,235 +1,220 @@
|
|
1 |
<?php
|
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 |
-
return false;
|
221 |
-
}*/
|
222 |
-
|
223 |
-
return $this->GetConfig('active', $store, false,
|
224 |
-
'payment/payson_invoice/');
|
225 |
-
}
|
226 |
-
|
227 |
-
/* public function ActivateInvoiceOnPurchase($store = null)
|
228 |
-
{
|
229 |
-
return $this->GetConfig('activate_invoice', $store, false,
|
230 |
-
'payment/payson_invoice/');
|
231 |
-
}*/
|
232 |
-
|
233 |
-
|
234 |
}
|
235 |
|
1 |
<?php
|
2 |
+
|
3 |
+
class Payson_Payson_Model_Config {
|
4 |
+
/*
|
5 |
+
* Constants
|
6 |
+
*/
|
7 |
+
|
8 |
+
//const PAYMENT_GUARANTEE = 'payment_guarantee';
|
9 |
+
|
10 |
+
const PAYMENT_GUARANTEE = 'NO';
|
11 |
+
const DIRECT_PAYMENT = 'direct_payment';
|
12 |
+
const CREDIT_CARD_PAYMENT = 'credit_card_payment';
|
13 |
+
const INVOICE_PAYMENT = 'invoice_payment';
|
14 |
+
|
15 |
+
/*
|
16 |
+
* Private properties
|
17 |
+
*/
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Default store id used in GetConfig()
|
21 |
+
*
|
22 |
+
* @var int
|
23 |
+
*/
|
24 |
+
private $default_store_id;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Supported currency codes
|
28 |
+
*
|
29 |
+
* @var array
|
30 |
+
*/
|
31 |
+
private $supported_currencies = array
|
32 |
+
(
|
33 |
+
'SEK', 'EUR'
|
34 |
+
);
|
35 |
+
|
36 |
+
/*
|
37 |
+
* Public methods
|
38 |
+
*/
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Constructor!
|
42 |
+
*
|
43 |
+
* @return void
|
44 |
+
*/
|
45 |
+
public function __construct() {
|
46 |
+
$this->SetDefaultStoreId(Mage::app()->getStore()->getId());
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Set default store id
|
51 |
+
*
|
52 |
+
* @param int $store
|
53 |
+
* @return object $this
|
54 |
+
*/
|
55 |
+
public function SetDefaultStoreId($store) {
|
56 |
+
$this->default_store_id = $store;
|
57 |
+
|
58 |
+
return $this;
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Get default store id
|
63 |
+
*
|
64 |
+
* @return int
|
65 |
+
*/
|
66 |
+
public function GetDefaultStoreId() {
|
67 |
+
return $this->default_store_id;
|
68 |
+
}
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Whether $currency is supported
|
72 |
+
*
|
73 |
+
* @param string $currency
|
74 |
+
* @return bool
|
75 |
+
*/
|
76 |
+
public function IsCurrencySupported($currency) {
|
77 |
+
return in_array(strtoupper($currency), $this->supported_currencies);
|
78 |
+
}
|
79 |
+
|
80 |
+
/**
|
81 |
+
* Get configuration value
|
82 |
+
*
|
83 |
+
* @param mixed $name
|
84 |
+
* @param int|null $store [optional]
|
85 |
+
* @param mixed $default [optional]
|
86 |
+
* @param string $prefix [optional]
|
87 |
+
*/
|
88 |
+
public function GetConfig($name, $store = null, $default = null, $prefix = 'payment/payson_standard/') {
|
89 |
+
if (!isset($store)) {
|
90 |
+
$store = $this->GetDefaultStoreId();
|
91 |
+
}
|
92 |
+
|
93 |
+
$name = $prefix . $name;
|
94 |
+
// Mage::getStoreConfigFlag
|
95 |
+
$value = Mage::getStoreConfig($name, $store);
|
96 |
+
|
97 |
+
return (isset($value) ? $value : $default);
|
98 |
+
}
|
99 |
+
|
100 |
+
/**
|
101 |
+
* @see GetConfig
|
102 |
+
*/
|
103 |
+
public function Get($name, $store = null, $default = null, $prefix = 'payment/payson_standard/') {
|
104 |
+
return $this->GetConfig($name, $store, $default, $prefix);
|
105 |
+
}
|
106 |
+
|
107 |
+
/**
|
108 |
+
* Get Payson specific invoice fee excluding tax
|
109 |
+
*
|
110 |
+
* @param object $order
|
111 |
+
* @return float
|
112 |
+
*/
|
113 |
+
public function GetInvoiceFee($order) {
|
114 |
+
$currency = $order->getBaseCurrencyCode();
|
115 |
+
$currency = strtolower($currency);
|
116 |
+
|
117 |
+
if (!$this->IsCurrencySupported($currency)) {
|
118 |
+
return 0;
|
119 |
+
}
|
120 |
+
|
121 |
+
$store = Mage::app()->getStore($order->getStoreId());
|
122 |
+
|
123 |
+
$fee = $this->GetConfig('invoice_fee_' . $currency, $store->getId(), 0, 'payment/payson_invoice/');
|
124 |
+
$fee = round((float) $fee, 3);
|
125 |
+
|
126 |
+
return $fee;
|
127 |
+
}
|
128 |
+
|
129 |
+
/**
|
130 |
+
* Get Payson specific invoice fee including tax
|
131 |
+
*
|
132 |
+
* @param object $order
|
133 |
+
* @return float
|
134 |
+
*/
|
135 |
+
public function GetInvoiceFeeInclTax($order) {
|
136 |
+
$fee = $this->GetInvoiceFee($order);
|
137 |
+
$fee *= (1 + $this->GetInvoiceFeeTaxMod($order));
|
138 |
+
$fee = round($fee, 3);
|
139 |
+
|
140 |
+
return $fee;
|
141 |
+
}
|
142 |
+
|
143 |
+
/**
|
144 |
+
* Get Payson specific invoice fee tax modifier
|
145 |
+
*
|
146 |
+
* @param object $order
|
147 |
+
* @return float
|
148 |
+
*/
|
149 |
+
public function GetInvoiceFeeTaxMod($order) {
|
150 |
+
$store = Mage::app()->getStore($order->getStoreId());
|
151 |
+
|
152 |
+
$tax_calc = Mage::getSingleton('tax/calculation');
|
153 |
+
$customer = Mage::getModel('customer/customer')
|
154 |
+
->load($order->getCustomerId());
|
155 |
+
|
156 |
+
$tax_class = $this->GetConfig('invoice_fee_tax', $store->getId(), 0, 'payment/payson_invoice/');
|
157 |
+
|
158 |
+
$tax_rate_req = $tax_calc->getRateRequest(
|
159 |
+
$order->getShippingAddress(), $order->getBillingAddress(), $customer->getTaxClassId(), $store)
|
160 |
+
->setProductClassId($tax_class);
|
161 |
+
|
162 |
+
$tax_mod = (float) $tax_calc->getRate($tax_rate_req);
|
163 |
+
$tax_mod /= 100;
|
164 |
+
$tax_mod = round($tax_mod, 5);
|
165 |
+
|
166 |
+
return $tax_mod;
|
167 |
+
}
|
168 |
+
|
169 |
+
/**
|
170 |
+
* Does this store support payment guarantee?
|
171 |
+
*
|
172 |
+
* @param int|null $store [optional]
|
173 |
+
* @return bool
|
174 |
+
*/
|
175 |
+
public function CanPaymentGuarantee($store = null) {
|
176 |
+
return (bool) $this->GetConfig(self::PAYMENT_GUARANTEE, $store, false);
|
177 |
+
}
|
178 |
+
|
179 |
+
/**
|
180 |
+
* Is standard payment enabled?
|
181 |
+
*
|
182 |
+
* @param int|null $store [optional]
|
183 |
+
* @return bool
|
184 |
+
*/
|
185 |
+
public function CanStandardPayment($store = null) {
|
186 |
+
return $this->GetConfig('active', $store, false, 'payment/payson_standard/');
|
187 |
+
}
|
188 |
+
|
189 |
+
/**
|
190 |
+
* Is invoice payment enabled?
|
191 |
+
*
|
192 |
+
* @param int|null $store [optional]
|
193 |
+
* @return bool
|
194 |
+
*/
|
195 |
+
public function CanInvoicePayment($store = null) {
|
196 |
+
/* if(!$this->CanStandardPayment($store))
|
197 |
+
{
|
198 |
+
return false;
|
199 |
+
} */
|
200 |
+
|
201 |
+
return $this->GetConfig('active', $store, false, 'payment/payson_invoice/');
|
202 |
+
}
|
203 |
+
|
204 |
+
public function restoreCartOnCancel($store = null) {
|
205 |
+
if (!$store)
|
206 |
+
$store = Mage::app()->getStore()->getId();
|
207 |
+
$configValue = $this->GetConfig("restore_on_cancel", $store);
|
208 |
+
|
209 |
+
return $configValue == 1;
|
210 |
+
}
|
211 |
+
|
212 |
+
public function restoreCartOnError($store = null) {
|
213 |
+
if (!$store)
|
214 |
+
$store = Mage::app()->getStore()->getId();
|
215 |
+
$configValue = $this->GetConfig("restore_on_error", $store);
|
216 |
+
|
217 |
+
return $configValue == 1;
|
218 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
}
|
220 |
|
app/code/community/Payson/Payson/Model/Method/Abstract.php
CHANGED
@@ -1,179 +1,164 @@
|
|
1 |
<?php
|
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 |
-
$helper = Mage::helper('payson');
|
98 |
-
$order_id = $order->getData('increment_id');
|
99 |
-
$api = Mage::helper('payson/api');
|
100 |
-
|
101 |
-
$api->PaymentUpdate($order_id, $method == "payson_invoice" ?
|
102 |
-
Payson_Payson_Helper_Api::UPDATE_ACTION_CREDITORDER :
|
103 |
Payson_Payson_Helper_Api::UPDATE_ACTION_REFUNDORDER);
|
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 |
-
$session->setData('payson_payment_method',
|
171 |
-
$_POST['payment']['method']);
|
172 |
-
}
|
173 |
-
else
|
174 |
-
{
|
175 |
-
$session->unsetData('payson_payment_method');
|
176 |
-
}
|
177 |
-
}*/
|
178 |
}
|
179 |
|
1 |
<?php
|
2 |
+
|
3 |
+
abstract class Payson_Payson_Model_Method_Abstract extends Mage_Payment_Model_Method_Abstract {
|
4 |
+
|
5 |
+
/**
|
6 |
+
* @inheritDoc
|
7 |
+
*/
|
8 |
+
protected $_isGateway = false;
|
9 |
+
protected $_canAuthorize = false;
|
10 |
+
protected $_canCapture = false;
|
11 |
+
protected $_canCapturePartial = false;
|
12 |
+
protected $_canRefund = false;
|
13 |
+
protected $_canRefundInvoicePartial = false;
|
14 |
+
protected $_canVoid = false;
|
15 |
+
protected $_canUseInternal = false; // true
|
16 |
+
protected $_canUseCheckout = true; // true
|
17 |
+
protected $_canUseForMultishipping = false; // true
|
18 |
+
protected $_isInitializeNeeded = false;
|
19 |
+
protected $_canFetchTransactionInfo = false;
|
20 |
+
protected $_canReviewPayment = false;
|
21 |
+
protected $_canCreateBillingAgreement = false;
|
22 |
+
protected $_canManageRecurringProfiles = false; // true
|
23 |
+
|
24 |
+
/**
|
25 |
+
* @inheritDoc
|
26 |
+
*/
|
27 |
+
protected $_canCancelInvoice = false;
|
28 |
+
|
29 |
+
/*
|
30 |
+
* Protected methods
|
31 |
+
*/
|
32 |
+
|
33 |
+
protected function GetCheckout() {
|
34 |
+
return Mage::getSingleton('checkout/session');
|
35 |
+
}
|
36 |
+
|
37 |
+
protected function GetQuote() {
|
38 |
+
return $this->GetCheckout()->getQuote();
|
39 |
+
}
|
40 |
+
|
41 |
+
/*
|
42 |
+
* Public methods
|
43 |
+
*/
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Redirect url when user place order
|
47 |
+
*
|
48 |
+
* @return string
|
49 |
+
*/
|
50 |
+
public function getOrderPlaceRedirectUrl() {
|
51 |
+
return Mage::getUrl('payson/checkout/redirect', array('_secure' => true));
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* @inheritDoc
|
56 |
+
*/
|
57 |
+
/* public function initialize($payment_action, $state_object)
|
58 |
+
{
|
59 |
+
$state_object->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT);
|
60 |
+
$state_object->setStatus(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT);
|
61 |
+
$state_object->setIsNotified(false);
|
62 |
+
|
63 |
+
return $this;
|
64 |
+
} */
|
65 |
+
|
66 |
+
/**
|
67 |
+
* Whether this paymend method is available for specified currency
|
68 |
+
*
|
69 |
+
* @param string $currency
|
70 |
+
* @return bool
|
71 |
+
*/
|
72 |
+
public function canUseForCurrency($currency) {
|
73 |
+
return Mage::getModel('payson/config')->IsCurrencySupported($currency);
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* @inheritDoc
|
78 |
+
*/
|
79 |
+
public function refund(Varien_Object $payment, $amount) {
|
80 |
+
|
81 |
+
/* @var $order Mage_Sales_Model_Order */
|
82 |
+
$order = $payment->getOrder();
|
83 |
+
|
84 |
+
$method = $payment->getMethod();
|
85 |
+
|
86 |
+
if ($order->getBaseGrandTotal() != $amount) {
|
87 |
+
Mage::throwException('Invalid amount');
|
88 |
+
}
|
89 |
+
|
90 |
+
$helper = Mage::helper('payson');
|
91 |
+
$order_id = $order->getData('increment_id');
|
92 |
+
$api = Mage::helper('payson/api');
|
93 |
+
|
94 |
+
$api->PaymentUpdate($order_id, $method == "payson_invoice" ?
|
95 |
+
Payson_Payson_Helper_Api::UPDATE_ACTION_CREDITORDER :
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
Payson_Payson_Helper_Api::UPDATE_ACTION_REFUNDORDER);
|
97 |
|
98 |
+
$order->addStatusHistoryComment($helper->__(
|
99 |
+
'Payment was credited at Payson'));
|
100 |
+
|
101 |
+
return $this;
|
102 |
+
}
|
103 |
+
|
104 |
+
/**
|
105 |
+
* @inheritDoc
|
106 |
+
*/
|
107 |
+
public function void(Varien_Object $payment) {
|
108 |
+
$payment->setTransactionId('auth')
|
109 |
+
->setIsTransactionClosed(0);
|
110 |
+
return $this;
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* @inheritDoc
|
115 |
+
*/
|
116 |
+
public function cancel(Varien_Object $payment) {
|
117 |
+
$order = $payment->getOrder();
|
118 |
+
$order_id = $order->getData('increment_id');
|
119 |
+
|
120 |
+
$api = Mage::helper('payson/api');
|
121 |
+
$helper = Mage::helper('payson');
|
122 |
+
$api->PaymentDetails($order_id);
|
123 |
+
$details = $api->GetResponse();
|
124 |
+
|
125 |
+
if (($details->type === Payson_Payson_Helper_Api::PAYMENT_METHOD_INVOICE) ||
|
126 |
+
($details->invoiceStatus === Payson_Payson_Helper_Api::INVOICE_STATUS_ORDERCREATED) ||
|
127 |
+
($details->type !== Payson_Payson_Helper_Api::PAYMENT_METHOD_INVOICE && $details->status === Payson_Payson_Helper_Api::STATUS_CREATED) ||
|
128 |
+
$order->getState() === Mage_Sales_Model_Order::STATE_PROCESSING) {
|
129 |
+
$api->PaymentUpdate($order_id, Payson_Payson_Helper_Api::UPDATE_ACTION_CANCELORDER);
|
130 |
+
|
131 |
+
$order->addStatusHistoryComment($helper->__(
|
132 |
+
'Order was canceled at Payson'));
|
133 |
+
|
134 |
+
$payment->setTransactionId('auth')
|
135 |
+
->setIsTransactionClosed(1);
|
136 |
+
//->setShouldCloseParentTransaction(1);
|
137 |
+
} else {
|
138 |
+
Mage::throwException($helper->__('Payson is not ready to cancel the order. Please try again later.'));
|
139 |
+
}
|
140 |
+
|
141 |
+
return $this;
|
142 |
+
}
|
143 |
+
|
144 |
+
/**
|
145 |
+
* Is run when payment method is selected
|
146 |
+
*
|
147 |
+
* @return void
|
148 |
+
*/
|
149 |
+
/* public function validate()
|
150 |
+
{
|
151 |
+
$session = Mage::getSingleton('checkout/session');
|
152 |
+
|
153 |
+
if(isset($_POST['payment']['method']))
|
154 |
+
{
|
155 |
+
$session->setData('payson_payment_method',
|
156 |
+
$_POST['payment']['method']);
|
157 |
+
}
|
158 |
+
else
|
159 |
+
{
|
160 |
+
$session->unsetData('payson_payment_method');
|
161 |
+
}
|
162 |
+
} */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
}
|
164 |
|
app/code/community/Payson/Payson/Model/Method/Invoice.php
CHANGED
@@ -1,138 +1,118 @@
|
|
1 |
<?php
|
2 |
-
class Payson_Payson_Model_Method_Invoice
|
3 |
-
extends Payson_Payson_Model_Method_Abstract
|
4 |
-
{
|
5 |
-
/*
|
6 |
-
* Protected properties
|
7 |
-
*/
|
8 |
-
|
9 |
-
/**
|
10 |
-
* @inheritDoc
|
11 |
-
*/
|
12 |
-
protected $_code = 'payson_invoice';
|
13 |
-
protected $_formBlockType = 'payson/invoice_form';
|
14 |
-
|
15 |
-
/**
|
16 |
-
* @inheritDoc
|
17 |
-
*/
|
18 |
-
protected $_canCapture = true;
|
19 |
-
protected $_canRefund = true;
|
20 |
-
protected $_canVoid = true;
|
21 |
-
//protected $_canUseCheckout = true;
|
22 |
-
private $invoiceAmountMinLimit = 30;
|
23 |
-
|
24 |
-
/*
|
25 |
-
* Public methods
|
26 |
-
*/
|
27 |
-
|
28 |
-
/**
|
29 |
-
* @inheritDoc
|
30 |
-
*/
|
31 |
-
public function capture(Varien_Object $payment, $amount)
|
32 |
-
{
|
33 |
-
$order = $payment->getOrder();
|
34 |
-
$order_id = $order->getData('increment_id');
|
35 |
-
|
36 |
-
$api = Mage::helper('payson/api');
|
37 |
-
$helper = Mage::helper('payson');
|
38 |
-
$api->PaymentDetails($order_id);
|
39 |
-
$details = $api->GetResponse();
|
40 |
-
|
41 |
-
if(($details->type ===
|
42 |
-
Payson_Payson_Helper_Api::PAYMENT_METHOD_INVOICE) ||
|
43 |
-
($details->invoiceStatus ===
|
44 |
-
Payson_Payson_Helper_Api::INVOICE_STATUS_ORDERCREATED))
|
45 |
-
{
|
46 |
-
$api->PaymentUpdate($order_id,
|
47 |
-
Payson_Payson_Helper_Api::UPDATE_ACTION_SHIPORDER);
|
48 |
-
|
49 |
-
$order->addStatusHistoryComment($helper->__(
|
50 |
-
'Order was activated at Payson'));
|
51 |
-
}
|
52 |
-
else
|
53 |
-
{
|
54 |
-
Mage::throwException($helper->__('Payson is not ready to create an invoice. Please try again later.'));
|
55 |
-
}
|
56 |
-
|
57 |
-
return $this;
|
58 |
-
}
|
59 |
-
|
60 |
-
/**
|
61 |
-
* @inheritDoc
|
62 |
-
*/
|
63 |
-
public function authorize(Varien_Object $payment, $amount)
|
64 |
-
{
|
65 |
-
$payment->setTransactionId('auth')->setIsTransactionClosed(0);
|
66 |
-
|
67 |
-
return $this;
|
68 |
-
}
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
/**
|
73 |
-
* @inheritDoc
|
74 |
-
*/
|
75 |
-
public function getTitle()
|
76 |
-
{
|
77 |
-
//if(Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal() >> 30)
|
78 |
-
// echo Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal(); //$this->_canUseCheckout = false;
|
79 |
-
$order = Mage::registry('current_order');
|
80 |
-
|
81 |
-
if(!isset($order) && ($invoice = Mage::registry('current_invoice')))
|
82 |
-
{
|
83 |
-
$order = $invoice->getOrder();
|
84 |
-
}
|
85 |
-
|
86 |
-
if(isset($order))
|
87 |
-
{
|
88 |
-
$invoice_fee = $order->getPaysonInvoiceFee();
|
89 |
-
|
90 |
-
if($invoice_fee)
|
91 |
-
{
|
92 |
-
$invoice_fee = $order->formatPrice($invoice_fee);
|
93 |
-
}
|
94 |
-
}
|
95 |
-
else
|
96 |
-
{
|
97 |
-
$invoice_fee = Mage::getModel('payson/config')
|
98 |
-
->GetInvoiceFeeInclTax($this->getQuote());
|
99 |
-
|
100 |
-
if($invoice_fee)
|
101 |
-
{
|
102 |
-
$invoice_fee = Mage::app()->getStore()
|
103 |
-
->formatPrice($invoice_fee);
|
104 |
-
}
|
105 |
-
}
|
106 |
-
|
107 |
-
$invoice_fee = strip_tags($invoice_fee);
|
108 |
-
|
109 |
-
return sprintf(Mage::helper('payson')
|
110 |
-
->__('Checkout with Payson invoice %s invoice fee'),
|
111 |
-
($invoice_fee ? '+' . $invoice_fee : ''));
|
112 |
-
}
|
113 |
-
|
114 |
-
public function canUseCheckout()
|
115 |
-
{
|
116 |
-
if($this->isSweden()){
|
117 |
-
if(Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal() < $this->invoiceAmountMinLimit)
|
118 |
-
return false;
|
119 |
-
else
|
120 |
-
return true;
|
121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
}
|
123 |
-
return false;
|
124 |
}
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
|
|
|
|
|
|
132 |
return false;
|
133 |
-
else
|
134 |
return true;
|
135 |
-
|
136 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
}
|
138 |
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
class Payson_Payson_Model_Method_Invoice extends Payson_Payson_Model_Method_Abstract {
|
4 |
+
/*
|
5 |
+
* Protected properties
|
6 |
+
*/
|
7 |
+
|
8 |
+
/**
|
9 |
+
* @inheritDoc
|
10 |
+
*/
|
11 |
+
protected $_code = 'payson_invoice';
|
12 |
+
protected $_formBlockType = 'payson/invoice_form';
|
13 |
+
|
14 |
+
/**
|
15 |
+
* @inheritDoc
|
16 |
+
*/
|
17 |
+
protected $_canCapture = true;
|
18 |
+
protected $_canRefund = true;
|
19 |
+
protected $_canVoid = true;
|
20 |
+
//protected $_canUseCheckout = true;
|
21 |
+
private $invoiceAmountMinLimit = 30;
|
22 |
+
|
23 |
+
/*
|
24 |
+
* Public methods
|
25 |
+
*/
|
26 |
+
|
27 |
+
/**
|
28 |
+
* @inheritDoc
|
29 |
+
*/
|
30 |
+
public function capture(Varien_Object $payment, $amount) {
|
31 |
+
$order = $payment->getOrder();
|
32 |
+
$order_id = $order->getData('increment_id');
|
33 |
+
|
34 |
+
$api = Mage::helper('payson/api');
|
35 |
+
$helper = Mage::helper('payson');
|
36 |
+
$api->PaymentDetails($order_id);
|
37 |
+
$details = $api->GetResponse();
|
38 |
+
|
39 |
+
if (($details->type ===
|
40 |
+
Payson_Payson_Helper_Api::PAYMENT_METHOD_INVOICE) ||
|
41 |
+
($details->invoiceStatus ===
|
42 |
+
Payson_Payson_Helper_Api::INVOICE_STATUS_ORDERCREATED)) {
|
43 |
+
$api->PaymentUpdate($order_id, Payson_Payson_Helper_Api::UPDATE_ACTION_SHIPORDER);
|
44 |
+
|
45 |
+
$order->addStatusHistoryComment($helper->__(
|
46 |
+
'Order was activated at Payson'));
|
47 |
+
} else {
|
48 |
+
Mage::throwException($helper->__('Payson is not ready to create an invoice. Please try again later.'));
|
49 |
+
}
|
50 |
+
|
51 |
+
return $this;
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* @inheritDoc
|
56 |
+
*/
|
57 |
+
public function authorize(Varien_Object $payment, $amount) {
|
58 |
+
$payment->setTransactionId('auth')->setIsTransactionClosed(0);
|
59 |
+
|
60 |
+
return $this;
|
61 |
+
}
|
62 |
+
|
63 |
+
/**
|
64 |
+
* @inheritDoc
|
65 |
+
*/
|
66 |
+
public function getTitle() {
|
67 |
+
//if(Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal() >> 30)
|
68 |
+
// echo Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal(); //$this->_canUseCheckout = false;
|
69 |
+
$order = Mage::registry('current_order');
|
70 |
+
|
71 |
+
if (!isset($order) && ($invoice = Mage::registry('current_invoice'))) {
|
72 |
+
$order = $invoice->getOrder();
|
73 |
+
}
|
74 |
+
|
75 |
+
if (isset($order)) {
|
76 |
+
$invoice_fee = $order->getPaysonInvoiceFee();
|
77 |
+
|
78 |
+
if ($invoice_fee) {
|
79 |
+
$invoice_fee = $order->formatPrice($invoice_fee);
|
80 |
+
}
|
81 |
+
} else {
|
82 |
+
$invoice_fee = Mage::getModel('payson/config')
|
83 |
+
->GetInvoiceFeeInclTax($this->getQuote());
|
84 |
+
|
85 |
+
if ($invoice_fee) {
|
86 |
+
$invoice_fee = Mage::app()->getStore()
|
87 |
+
->formatPrice($invoice_fee);
|
88 |
}
|
|
|
89 |
}
|
90 |
+
|
91 |
+
$invoice_fee = strip_tags($invoice_fee);
|
92 |
+
|
93 |
+
return sprintf(Mage::helper('payson')
|
94 |
+
->__('Checkout with Payson invoice %s invoice fee'), ($invoice_fee ? '+' . $invoice_fee : ''));
|
95 |
+
}
|
96 |
+
|
97 |
+
public function canUseCheckout() {
|
98 |
+
if ($this->isSweden()) {
|
99 |
+
if (Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal() < $this->invoiceAmountMinLimit)
|
100 |
return false;
|
101 |
+
else
|
102 |
return true;
|
|
|
103 |
}
|
104 |
+
return false;
|
105 |
+
}
|
106 |
+
|
107 |
+
public function isSweden() {
|
108 |
+
$checkout = Mage::getSingleton('checkout/session')->getQuote();
|
109 |
+
$billing = $checkout->getBillingAddress();
|
110 |
+
//$shipping = $checkout->getShippingAddress();
|
111 |
+
if (strtoupper($billing->getCountry()) != 'SE')
|
112 |
+
return false;
|
113 |
+
else
|
114 |
+
return true;
|
115 |
+
}
|
116 |
+
|
117 |
}
|
118 |
|
app/code/community/Payson/Payson/Model/Method/Standard.php
CHANGED
@@ -1,40 +1,39 @@
|
|
1 |
<?php
|
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 |
|
1 |
<?php
|
2 |
+
|
3 |
+
class Payson_Payson_Model_Method_Standard extends Payson_Payson_Model_Method_Abstract {
|
4 |
+
/*
|
5 |
+
* Protected properties
|
6 |
+
*/
|
7 |
+
|
8 |
+
protected $_canCapture = true;
|
9 |
+
protected $_canRefund = true;
|
10 |
+
protected $_canVoid = true;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* @inheritDoc
|
14 |
+
*/
|
15 |
+
protected $_code = 'payson_standard';
|
16 |
+
protected $_formBlockType = 'payson/standard_form';
|
17 |
+
|
18 |
+
/*
|
19 |
+
* Public methods
|
20 |
+
*/
|
21 |
+
|
22 |
+
/**
|
23 |
+
* @inheritDoc
|
24 |
+
*/
|
25 |
+
public function getTitle() {
|
26 |
+
return Mage::helper('payson')->__('Checkout with Payson');
|
27 |
+
}
|
28 |
+
|
29 |
+
/**
|
30 |
+
* @inheritDoc
|
31 |
+
*/
|
32 |
+
public function authorize(Varien_Object $payment, $amount) {
|
33 |
+
$payment->setTransactionId('auth')->setIsTransactionClosed(0);
|
34 |
+
|
35 |
+
return $this;
|
36 |
+
}
|
37 |
+
|
|
|
38 |
}
|
39 |
|
app/code/community/Payson/Payson/Model/Mysql4/Setup.php
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
{
|
|
|
4 |
}
|
5 |
|
1 |
<?php
|
2 |
+
|
3 |
+
class Payson_Payson_Model_Mysql4_Setup extends Mage_Sales_Model_Mysql4_Setup {
|
4 |
+
|
5 |
}
|
6 |
|
app/code/community/Payson/Payson/Model/Order/Creditmemo/Total/Invoice.php
CHANGED
@@ -1,45 +1,44 @@
|
|
1 |
<?php
|
2 |
-
class Payson_Payson_Model_Order_Creditmemo_Total_Invoice extends
|
3 |
-
Mage_Sales_Model_Order_Creditmemo_Total_Abstract
|
4 |
-
{
|
5 |
-
protected $_code = 'payson_invoice';
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
$order = $invoice->getOrder();
|
10 |
|
11 |
-
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
return $this;
|
16 |
-
}
|
17 |
|
18 |
-
|
19 |
-
{
|
20 |
-
return $this;
|
21 |
-
}*/
|
22 |
|
23 |
-
|
24 |
-
|
|
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
$grand_total = $invoice->getGrandTotal();
|
34 |
-
$grand_total += $fee;
|
35 |
|
36 |
-
|
37 |
-
|
|
|
38 |
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
-
return $this;
|
43 |
-
}
|
44 |
}
|
45 |
|
1 |
<?php
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
class Payson_Payson_Model_Order_Creditmemo_Total_Invoice extends
|
4 |
+
Mage_Sales_Model_Order_Creditmemo_Total_Abstract {
|
|
|
5 |
|
6 |
+
protected $_code = 'payson_invoice';
|
7 |
|
8 |
+
public function collect(Mage_Sales_Model_Order_Creditmemo $invoice) {
|
9 |
+
$order = $invoice->getOrder();
|
|
|
|
|
10 |
|
11 |
+
$method = $order->getPayment()->getMethodInstance()->getCode(); /* Should be getMethod() */
|
|
|
|
|
|
|
12 |
|
13 |
+
if ($method !== 'payson_invoice') {
|
14 |
+
return $this;
|
15 |
+
}
|
16 |
|
17 |
+
/* if($order->hasInvoices() !== 0)
|
18 |
+
{
|
19 |
+
return $this;
|
20 |
+
} */
|
21 |
|
22 |
+
$base_fee = $order->getBasePaysonInvoiceFee();
|
23 |
+
$fee = $order->getPaysonInvoiceFee();
|
|
|
|
|
24 |
|
25 |
+
if (!$base_fee || !$fee) {
|
26 |
+
return $this;
|
27 |
+
}
|
28 |
|
29 |
+
$base_grand_total = $invoice->getBaseGrandTotal();
|
30 |
+
$base_grand_total += $base_fee;
|
31 |
+
$grand_total = $invoice->getGrandTotal();
|
32 |
+
$grand_total += $fee;
|
33 |
+
|
34 |
+
$invoice->setBasePaysonInvoiceFee($base_fee);
|
35 |
+
$invoice->setPaysonInvoiceFee($fee);
|
36 |
+
|
37 |
+
$invoice->setBaseGrandTotal($base_grand_total);
|
38 |
+
$invoice->setGrandTotal($grand_total);
|
39 |
+
|
40 |
+
return $this;
|
41 |
+
}
|
42 |
|
|
|
|
|
43 |
}
|
44 |
|
app/code/community/Payson/Payson/Model/Order/Invoice/Total/Invoice.php
CHANGED
@@ -1,45 +1,43 @@
|
|
1 |
<?php
|
2 |
-
class Payson_Payson_Model_Order_Invoice_Total_Invoice extends
|
3 |
-
Mage_Sales_Model_Order_Invoice_Total_Abstract
|
4 |
-
{
|
5 |
-
protected $_code = 'payson_invoice';
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
$order = $invoice->getOrder();
|
10 |
|
11 |
-
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
return $this;
|
16 |
-
}
|
17 |
|
18 |
-
|
19 |
-
{
|
20 |
-
return $this;
|
21 |
-
}
|
22 |
|
23 |
-
|
24 |
-
|
|
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
}
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
$grand_total = $invoice->getGrandTotal();
|
34 |
-
$grand_total += $fee;
|
35 |
|
36 |
-
|
37 |
-
|
|
|
38 |
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
-
return $this;
|
43 |
-
}
|
44 |
}
|
45 |
|
1 |
<?php
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
class Payson_Payson_Model_Order_Invoice_Total_Invoice extends
|
4 |
+
Mage_Sales_Model_Order_Invoice_Total_Abstract {
|
|
|
5 |
|
6 |
+
protected $_code = 'payson_invoice';
|
7 |
|
8 |
+
public function collect(Mage_Sales_Model_Order_Invoice $invoice) {
|
9 |
+
$order = $invoice->getOrder();
|
|
|
|
|
10 |
|
11 |
+
$method = $order->getPayment()->getMethodInstance()->getCode(); /* Should be getMethod() */
|
|
|
|
|
|
|
12 |
|
13 |
+
if ($method !== 'payson_invoice') {
|
14 |
+
return $this;
|
15 |
+
}
|
16 |
|
17 |
+
if ($order->hasInvoices() == 0) {
|
18 |
+
return $this;
|
19 |
+
}
|
|
|
20 |
|
21 |
+
$base_fee = $order->getBasePaysonInvoiceFee();
|
22 |
+
$fee = $order->getPaysonInvoiceFee();
|
|
|
|
|
23 |
|
24 |
+
if (!$base_fee || !$fee) {
|
25 |
+
return $this;
|
26 |
+
}
|
27 |
|
28 |
+
$base_grand_total = $invoice->getBaseGrandTotal();
|
29 |
+
$base_grand_total += $base_fee;
|
30 |
+
$grand_total = $invoice->getGrandTotal();
|
31 |
+
$grand_total += $fee;
|
32 |
+
|
33 |
+
$invoice->setBasePaysonInvoiceFee($base_fee);
|
34 |
+
$invoice->setPaysonInvoiceFee($fee);
|
35 |
+
|
36 |
+
$invoice->setBaseGrandTotal($base_grand_total);
|
37 |
+
$invoice->setGrandTotal($grand_total);
|
38 |
+
|
39 |
+
return $this;
|
40 |
+
}
|
41 |
|
|
|
|
|
42 |
}
|
43 |
|
app/code/community/Payson/Payson/Model/Quote/Address/Total/Invoice.php
CHANGED
@@ -1,68 +1,64 @@
|
|
1 |
<?php
|
2 |
-
class Payson_Payson_Model_Quote_Address_Total_Invoice extends
|
3 |
-
Mage_Sales_Model_Quote_Address_Total_Abstract
|
4 |
-
{
|
5 |
-
protected $_code = 'payson_invoice';
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
if($address->getAddressType() !== 'shipping')
|
10 |
-
{
|
11 |
-
return $this;
|
12 |
-
}
|
13 |
|
14 |
-
|
15 |
-
$address->setPaysonInvoiceFee(0);
|
16 |
|
17 |
-
|
|
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
return $this;
|
22 |
-
}
|
23 |
|
24 |
-
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
}
|
30 |
|
31 |
-
|
32 |
-
$config = Mage::getModel('payson/config');
|
33 |
|
34 |
-
|
|
|
|
|
35 |
|
36 |
-
|
37 |
-
|
38 |
|
39 |
-
|
40 |
|
41 |
-
|
42 |
-
|
43 |
|
44 |
-
|
45 |
-
$address->setGrandTotal($store->convertPrice($base_grand_total, false));
|
46 |
|
47 |
-
|
48 |
-
|
49 |
|
50 |
-
|
51 |
-
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
-
return $this;
|
66 |
-
}
|
67 |
}
|
68 |
|
1 |
<?php
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
class Payson_Payson_Model_Quote_Address_Total_Invoice extends
|
4 |
+
Mage_Sales_Model_Quote_Address_Total_Abstract {
|
|
|
|
|
|
|
|
|
5 |
|
6 |
+
protected $_code = 'payson_invoice';
|
|
|
7 |
|
8 |
+
public function collect(Mage_Sales_Model_Quote_Address $address) {
|
9 |
+
if ($address->getAddressType() !== 'shipping') {
|
10 |
+
return $this;
|
11 |
+
}
|
12 |
|
13 |
+
$address->setBasePaysonInvoiceFee(0);
|
14 |
+
$address->setPaysonInvoiceFee(0);
|
|
|
|
|
15 |
|
16 |
+
$quote = $address->getQuote();
|
17 |
|
18 |
+
if (is_null($quote->getId())) {
|
19 |
+
return $this;
|
20 |
+
}
|
|
|
21 |
|
22 |
+
$method = $address->getQuote()->getPayment()->getMethod();
|
|
|
23 |
|
24 |
+
if ($method !== 'payson_invoice') {
|
25 |
+
return $this;
|
26 |
+
}
|
27 |
|
28 |
+
$store = $quote->getStore();
|
29 |
+
$config = Mage::getModel('payson/config');
|
30 |
|
31 |
+
$fee = $config->GetInvoiceFeeInclTax($quote);
|
32 |
|
33 |
+
$base_grand_total = $address->getBaseGrandTotal();
|
34 |
+
$base_grand_total += $fee;
|
35 |
|
36 |
+
// TODO: update tax in another model?
|
|
|
37 |
|
38 |
+
$address->setBasePaysonInvoiceFee($fee);
|
39 |
+
$address->setPaysonInvoiceFee($store->convertPrice($fee, false));
|
40 |
|
41 |
+
$address->setBaseGrandTotal($base_grand_total);
|
42 |
+
$address->setGrandTotal($store->convertPrice($base_grand_total, false));
|
43 |
|
44 |
+
//$this->_addBaseAmount($fee);
|
45 |
+
//$this->_addAmount($fee);
|
46 |
+
|
47 |
+
return $this;
|
48 |
+
}
|
49 |
+
|
50 |
+
public function fetch(Mage_Sales_Model_Quote_Address $address) {
|
51 |
+
if (($fee = $address->getPaysonInvoiceFee()) > 0) {
|
52 |
+
$address->addTotal(array
|
53 |
+
(
|
54 |
+
'code' => $this->getCode(),
|
55 |
+
'title' => Mage::helper('payson')->__('Invoice fee'),
|
56 |
+
'value' => $fee
|
57 |
+
));
|
58 |
+
}
|
59 |
+
|
60 |
+
return $this;
|
61 |
+
}
|
62 |
|
|
|
|
|
63 |
}
|
64 |
|
app/code/community/Payson/Payson/Model/Standard.php
CHANGED
@@ -1,131 +1,118 @@
|
|
1 |
<?php
|
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 |
-
else
|
118 |
-
{
|
119 |
-
$session->unsetData('payson_payment_method');
|
120 |
-
}
|
121 |
-
}
|
122 |
-
|
123 |
-
/**
|
124 |
-
* @inheritDoc
|
125 |
-
*/
|
126 |
-
public function getTitle()
|
127 |
-
{
|
128 |
-
return Mage::Helper('payson')->__('Checkout with Payson');
|
129 |
-
}
|
130 |
}
|
131 |
|
1 |
<?php
|
2 |
+
|
3 |
+
class Payson_Payson_Model_Standard extends Mage_Payment_Model_Method_Abstract {
|
4 |
+
/*
|
5 |
+
* Protected properties
|
6 |
+
*/
|
7 |
+
|
8 |
+
/**
|
9 |
+
* @inheritDoc
|
10 |
+
*/
|
11 |
+
protected $_code = 'payson';
|
12 |
+
protected $_formBlockType = 'payson/form';
|
13 |
+
//protected $_infoBlockType = 'payson/info';
|
14 |
+
|
15 |
+
/**
|
16 |
+
* @inheritDoc
|
17 |
+
*/
|
18 |
+
protected $_isGateway = false;
|
19 |
+
protected $_canAuthorize = false;
|
20 |
+
protected $_canCapture = true;
|
21 |
+
protected $_canCapturePartial = false;
|
22 |
+
protected $_canRefund = false;
|
23 |
+
protected $_canRefundInvoicePartial = false;
|
24 |
+
protected $_canVoid = false;
|
25 |
+
protected $_canUseInternal = true;
|
26 |
+
protected $_canUseCheckout = true;
|
27 |
+
protected $_canUseForMultishipping = false;
|
28 |
+
protected $_isInitializeNeeded = false;
|
29 |
+
protected $_canFetchTransactionInfo = false;
|
30 |
+
protected $_canReviewPayment = false;
|
31 |
+
protected $_canCreateBillingAgreement = false;
|
32 |
+
protected $_canManageRecurringProfiles = false;
|
33 |
+
|
34 |
+
/**
|
35 |
+
* @inheritDoc
|
36 |
+
*/
|
37 |
+
protected $_canCancelInvoice = false;
|
38 |
+
|
39 |
+
/*
|
40 |
+
* Public methods
|
41 |
+
*/
|
42 |
+
|
43 |
+
/**
|
44 |
+
* @inheritDoc
|
45 |
+
*/
|
46 |
+
public function initialize($payment_action, $state_object) {
|
47 |
+
$state_object->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT);
|
48 |
+
$state_object->setStatus(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT);
|
49 |
+
$state_object->setIsNotified(false);
|
50 |
+
|
51 |
+
return $this;
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* @inheritDoc
|
56 |
+
*/
|
57 |
+
public function capture(Varien_Object $payment, $amount) {
|
58 |
+
$order = $payment->getOrder();
|
59 |
+
$order_id = $order->getData('increment_id');
|
60 |
+
|
61 |
+
$api = Mage::helper('payson/api');
|
62 |
+
|
63 |
+
$api->PaymentDetails($order_id);
|
64 |
+
$details = $api->GetResponse();
|
65 |
+
|
66 |
+
if (($details->type ===
|
67 |
+
Payson_Payson_Helper_Api::PAYMENT_METHOD_INVOICE) ||
|
68 |
+
($details->invoiceStatus ===
|
69 |
+
Payson_Payson_Helper_Api::INVOICE_STATUS_ORDERCREATED)) {
|
70 |
+
$api->PaymentUpdate($order_id, Payson_Payson_Helper_Api::UPDATE_ACTION_SHIPORDER);
|
71 |
+
}
|
72 |
+
|
73 |
+
return $this;
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Redirect url when user place order
|
78 |
+
*
|
79 |
+
* @return string
|
80 |
+
*/
|
81 |
+
public function getOrderPlaceRedirectUrl() {
|
82 |
+
return Mage::getUrl('payson/checkout/redirect', array('_secure' => true));
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Whether this paymend method is available for specified currency
|
87 |
+
*
|
88 |
+
* @param string $currency
|
89 |
+
* @return bool
|
90 |
+
*/
|
91 |
+
public function canUseForCurrency($currency) {
|
92 |
+
return Mage::getModel('payson/config')->IsCurrencySupported($currency);
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Is run when payment method is selected
|
97 |
+
*
|
98 |
+
* @return void
|
99 |
+
*/
|
100 |
+
public function validate() {
|
101 |
+
$session = Mage::getSingleton('checkout/session');
|
102 |
+
|
103 |
+
if (isset($_POST['payment']['payson_payment_method'])) {
|
104 |
+
$session->setData('payson_payment_method', $_POST['payment']['payson_payment_method']);
|
105 |
+
} else {
|
106 |
+
$session->unsetData('payson_payment_method');
|
107 |
+
}
|
108 |
+
}
|
109 |
+
|
110 |
+
/**
|
111 |
+
* @inheritDoc
|
112 |
+
*/
|
113 |
+
public function getTitle() {
|
114 |
+
return Mage::Helper('payson')->__('Checkout with Payson');
|
115 |
+
}
|
116 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
}
|
118 |
|
app/code/community/Payson/Payson/controllers/CheckoutController.php
CHANGED
@@ -1,135 +1,137 @@
|
|
1 |
<?php
|
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 |
}
|
1 |
<?php
|
2 |
+
|
3 |
+
class Payson_Payson_CheckoutController extends Mage_Core_Controller_Front_Action {
|
4 |
+
/*
|
5 |
+
* Private properties
|
6 |
+
*/
|
7 |
+
|
8 |
+
private $session;
|
9 |
+
private $order = null;
|
10 |
+
|
11 |
+
/*
|
12 |
+
* Private methods
|
13 |
+
*/
|
14 |
+
|
15 |
+
private function GetSession() {
|
16 |
+
if (!isset($this->session)) {
|
17 |
+
$this->session = Mage::getSingleton('checkout/session');
|
18 |
+
}
|
19 |
+
|
20 |
+
return $this->session;
|
21 |
+
}
|
22 |
+
|
23 |
+
/**
|
24 |
+
*
|
25 |
+
* @return Mage_Sales_Model_Order
|
26 |
+
*/
|
27 |
+
private function GetOrder() {
|
28 |
+
if (!isset($this->order)) {
|
29 |
+
$increment_id = $this->GetSession()->getData('last_real_order_id');
|
30 |
+
|
31 |
+
if ($increment_id) {
|
32 |
+
$this->order = Mage::getModel('sales/order')
|
33 |
+
->loadByIncrementId($increment_id);
|
34 |
+
|
35 |
+
if (is_null($this->order->getId())) {
|
36 |
+
$this->order = null;
|
37 |
+
}
|
38 |
+
}
|
39 |
+
}
|
40 |
+
|
41 |
+
return $this->order;
|
42 |
+
}
|
43 |
+
|
44 |
+
private function CancelOrder($message = '') {
|
45 |
+
$order = $this->GetOrder();
|
46 |
+
|
47 |
+
if (!is_null($order = $this->GetOrder())) {
|
48 |
+
$order->cancel();
|
49 |
+
|
50 |
+
if ($message != '')
|
51 |
+
$order->addStatusHistoryComment($message);
|
52 |
+
}
|
53 |
+
|
54 |
+
$order->save();
|
55 |
+
return $this;
|
56 |
+
}
|
57 |
+
|
58 |
+
/*
|
59 |
+
* Public methods
|
60 |
+
*/
|
61 |
+
|
62 |
+
public function redirectAction() {
|
63 |
+
$order = $this->GetOrder();
|
64 |
+
|
65 |
+
if (is_null($order)) {
|
66 |
+
$this->_redirect('checkout/cart');
|
67 |
+
|
68 |
+
return;
|
69 |
+
}
|
70 |
+
|
71 |
+
try {
|
72 |
+
$api = Mage::helper('payson/api')->Pay($order);
|
73 |
+
|
74 |
+
$order->addStatusHistoryComment(Mage::helper('payson')->__(
|
75 |
+
'The customer was redirected to Payson'))
|
76 |
+
->save();
|
77 |
+
|
78 |
+
$this->GetResponse()->setRedirect($api->GetPayForwardUrl());
|
79 |
+
} catch (Exception $e) {
|
80 |
+
$this->CancelOrder($e->getMessage());
|
81 |
+
|
82 |
+
Mage::logException($e);
|
83 |
+
|
84 |
+
Mage::getSingleton('core/session')->addError($e->getMessage());
|
85 |
+
$this->_redirect('checkout/cart');
|
86 |
+
}
|
87 |
+
}
|
88 |
+
|
89 |
+
public function returnAction() {
|
90 |
+
$config = Mage::getModel('payson/config');
|
91 |
+
$paymentDetailsResponse = Mage::helper('payson/api')->PaymentDetails(Mage::getSingleton('checkout/session')->getLastRealOrderId())->getResponse();
|
92 |
+
$paymentStatus = $paymentDetailsResponse->status;
|
93 |
+
switch ($paymentStatus) {
|
94 |
+
case 'COMPLETED':
|
95 |
+
case 'PENDING':
|
96 |
+
case 'PROCESSING':
|
97 |
+
case 'CREDITED': {
|
98 |
+
$this->GetOrder()->sendNewOrderEmail();
|
99 |
+
$this->_redirect('checkout/onepage/success');
|
100 |
+
break;
|
101 |
+
}
|
102 |
+
case 'ERROR': {
|
103 |
+
$errorMessage = Mage::helper('payson')->__('The payment was denied by Payson. Please, try a different payment method');
|
104 |
+
Mage::getSingleton('core/session')->addError($errorMessage);
|
105 |
+
if ($config->restoreCartOnError())
|
106 |
+
$this->restoreCart();
|
107 |
+
|
108 |
+
$this->_redirect('checkout');
|
109 |
+
break;
|
110 |
+
}
|
111 |
+
default: {
|
112 |
+
Mage::getSingleton('core/session')->addError(sprintf(Mage::helper('payson')->__('Something went wrong with the payment. Please, try a different payment method')));
|
113 |
+
$this->_redirect('checkout');
|
114 |
+
break;
|
115 |
+
}
|
116 |
+
}
|
117 |
+
}
|
118 |
+
|
119 |
+
public function cancelAction() {
|
120 |
+
$config = Mage::getModel('payson/config');
|
121 |
+
$cancelMessage = Mage::helper('payson')->__('Something went wrong with the payment. Please, try a different payment method');
|
122 |
+
Mage::getSingleton('core/session')->addError($cancelMessage);
|
123 |
+
$this->CancelOrder($cancelMessage);
|
124 |
+
if ($config->restoreCartOnCancel())
|
125 |
+
$this->restoreCart();
|
126 |
+
|
127 |
+
|
128 |
+
$this->_redirect('checkout');
|
129 |
+
}
|
130 |
+
|
131 |
+
private function restoreCart() {
|
132 |
+
$quoteId = $this->GetOrder()->getQuoteId();
|
133 |
+
$quote = Mage::getModel('sales/quote')->load($quoteId);
|
134 |
+
$quote->setIsActive(true)->save();
|
135 |
+
}
|
136 |
+
|
137 |
}
|
app/code/community/Payson/Payson/controllers/IpnController.php
CHANGED
@@ -1,29 +1,25 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
{
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
return;
|
26 |
-
}
|
27 |
-
}
|
28 |
}
|
29 |
|
1 |
<?php
|
2 |
+
|
3 |
+
class Payson_Payson_IpnController extends Mage_Core_Controller_Front_Action {
|
4 |
+
|
5 |
+
public function notifyAction() {
|
6 |
+
$request = $this->getRequest();
|
7 |
+
$response = $this->getResponse();
|
8 |
+
|
9 |
+
if (!$request->isPost()) {
|
10 |
+
$response->setHttpResponseCode(503)->setBody('No!');
|
11 |
+
|
12 |
+
return;
|
13 |
+
}
|
14 |
+
|
15 |
+
try {
|
16 |
+
$api = Mage::helper('payson/api')->Validate($request->getRawBody(), $request->getHeader('Content-Type'));
|
17 |
+
} catch (Exception $e) {
|
18 |
+
$response->setHttpResponseCode(503)->setBody($e->getMessage());
|
19 |
+
|
20 |
+
return;
|
21 |
+
}
|
22 |
+
}
|
23 |
+
|
|
|
|
|
|
|
|
|
24 |
}
|
25 |
|
app/code/community/Payson/Payson/etc/config.xml
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Payson_Payson>
|
5 |
-
<version>
|
6 |
</Payson_Payson>
|
7 |
</modules>
|
8 |
<admin>
|
@@ -92,21 +92,21 @@
|
|
92 |
</payson_invoice_fee>
|
93 |
</sales_convert_quote_address>
|
94 |
<!--<sales_convert_order>
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
</fieldsets>
|
111 |
</global>
|
112 |
<frontend>
|
@@ -166,6 +166,8 @@
|
|
166 |
<payment_action>authorize</payment_action>
|
167 |
<order_status>pending_payment</order_status>
|
168 |
<payment_guarantee>1</payment_guarantee>
|
|
|
|
|
169 |
</payson_standard>
|
170 |
<payson_invoice>
|
171 |
<active>0</active>
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Payson_Payson>
|
5 |
+
<version>1.0</version>
|
6 |
</Payson_Payson>
|
7 |
</modules>
|
8 |
<admin>
|
92 |
</payson_invoice_fee>
|
93 |
</sales_convert_quote_address>
|
94 |
<!--<sales_convert_order>
|
95 |
+
<base_payson_invoice_fee>
|
96 |
+
<to_quote>*</to_quote>
|
97 |
+
</base_payson_invoice_fee>
|
98 |
+
<payson_invoice_fee>
|
99 |
+
<to_quote>*</to_quote>
|
100 |
+
</payson_invoice_fee>
|
101 |
+
</sales_convert_order>
|
102 |
+
<sales_convert_quote>
|
103 |
+
<base_payson_invoice_fee>
|
104 |
+
<to_order>*</to_order>
|
105 |
+
</base_payson_invoice_fee>
|
106 |
+
<payson_invoice_fee>
|
107 |
+
<to_order>*</to_order>
|
108 |
+
</payson_invoice_fee>
|
109 |
+
</sales_convert_quote>-->
|
110 |
</fieldsets>
|
111 |
</global>
|
112 |
<frontend>
|
166 |
<payment_action>authorize</payment_action>
|
167 |
<order_status>pending_payment</order_status>
|
168 |
<payment_guarantee>1</payment_guarantee>
|
169 |
+
<restore_on_cancel>1</restore_on_cancel>
|
170 |
+
<restore_on_error>1</restore_on_error>
|
171 |
</payson_standard>
|
172 |
<payson_invoice>
|
173 |
<active>0</active>
|
app/code/community/Payson/Payson/etc/system.xml
CHANGED
@@ -1,144 +1,164 @@
|
|
1 |
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
<config>
|
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 |
</config>
|
144 |
|
1 |
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
<config>
|
3 |
+
<sections>
|
4 |
+
<payment>
|
5 |
+
<groups>
|
6 |
+
<payson_standard translate="label" module="payson">
|
7 |
+
<label>Payson</label>
|
8 |
+
<sort_order>-100</sort_order>
|
9 |
+
<show_in_default>1</show_in_default>
|
10 |
+
<show_in_website>1</show_in_website>
|
11 |
+
<show_in_store>1</show_in_store>
|
12 |
+
<fields>
|
13 |
+
<test_mode translate="label,comment">
|
14 |
+
<label>Test mode</label>
|
15 |
+
<comment>Enable/disable test mode.</comment>
|
16 |
+
<frontend_type>select</frontend_type>
|
17 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
18 |
+
<sort_order>5</sort_order>
|
19 |
+
<show_in_default>1</show_in_default>
|
20 |
+
<show_in_website>1</show_in_website>
|
21 |
+
<show_in_store>1</show_in_store>
|
22 |
+
</test_mode>
|
23 |
+
<active translate="label,comment">
|
24 |
+
<label>Enabled</label>
|
25 |
+
<comment>Enable/disable payment with Payson.</comment>
|
26 |
+
<frontend_type>select</frontend_type>
|
27 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
28 |
+
<sort_order>10</sort_order>
|
29 |
+
<show_in_default>1</show_in_default>
|
30 |
+
<show_in_website>1</show_in_website>
|
31 |
+
<show_in_store>1</show_in_store>
|
32 |
+
</active>
|
33 |
+
<email translate="label,comment">
|
34 |
+
<label>Email</label>
|
35 |
+
<comment>Email address bound to your Payson account.</comment>
|
36 |
+
<frontend_type>text</frontend_type>
|
37 |
+
<validate>validate-email</validate>
|
38 |
+
<sort_order>20</sort_order>
|
39 |
+
<show_in_default>1</show_in_default>
|
40 |
+
<show_in_website>0</show_in_website>
|
41 |
+
<show_in_store>0</show_in_store>
|
42 |
+
</email>
|
43 |
+
<agent_id translate="label,comment">
|
44 |
+
<label>Agent ID</label>
|
45 |
+
<comment>Agent ID is found on your Payson profile page.</comment>
|
46 |
+
<frontend_type>text</frontend_type>
|
47 |
+
<sort_order>30</sort_order>
|
48 |
+
<show_in_default>1</show_in_default>
|
49 |
+
<show_in_website>0</show_in_website>
|
50 |
+
<show_in_store>0</show_in_store>
|
51 |
+
</agent_id>
|
52 |
+
<md5_key translate="label,comment">
|
53 |
+
<label>MD5 key</label>
|
54 |
+
<comment>MD5 key is found on your Payson profile page.</comment>
|
55 |
+
<frontend_type>text</frontend_type>
|
56 |
+
<sort_order>40</sort_order>
|
57 |
+
<show_in_default>1</show_in_default>
|
58 |
+
<show_in_website>0</show_in_website>
|
59 |
+
<show_in_store>0</show_in_store>
|
60 |
+
</md5_key>
|
61 |
+
<payment_guarantee translate="label,comment">
|
62 |
+
<label>Enable payment guarantee</label>
|
63 |
+
<comment>Enable/disable payment guarantee.</comment>
|
64 |
+
<frontend_type>select</frontend_type>
|
65 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
66 |
+
<sort_order>50</sort_order>
|
67 |
+
<show_in_default>0</show_in_default>
|
68 |
+
<show_in_website>0</show_in_website>
|
69 |
+
<show_in_store>0</show_in_store>
|
70 |
+
</payment_guarantee>
|
71 |
+
<restore_on_cancel translate="label,comment">
|
72 |
+
<label>Restore cart on cancel</label>
|
73 |
+
<comment>Restore cart when customer cancel the payment</comment>
|
74 |
+
<frontend_type>select</frontend_type>
|
75 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
76 |
+
<sort_order>100</sort_order>
|
77 |
+
<show_in_default>1</show_in_default>
|
78 |
+
<show_in_website>1</show_in_website>
|
79 |
+
<show_in_store>1</show_in_store>
|
80 |
+
</restore_on_cancel>
|
81 |
+
<restore_on_error translate="label,comment">
|
82 |
+
<label>Restore cart on error</label>
|
83 |
+
<comment>Restore cart when status from Payson is error</comment>
|
84 |
+
<frontend_type>select</frontend_type>
|
85 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
86 |
+
<sort_order>150</sort_order>
|
87 |
+
<show_in_default>1</show_in_default>
|
88 |
+
<show_in_website>1</show_in_website>
|
89 |
+
<show_in_store>1</show_in_store>
|
90 |
+
</restore_on_error>
|
91 |
+
</fields>
|
92 |
+
</payson_standard>
|
93 |
+
<payson_invoice translate="label" module="payson">
|
94 |
+
<label>Payson invoice</label>
|
95 |
+
<sort_order>-99</sort_order>
|
96 |
+
<show_in_default>1</show_in_default>
|
97 |
+
<show_in_website>1</show_in_website>
|
98 |
+
<show_in_store>1</show_in_store>
|
99 |
+
<fields>
|
100 |
+
<active translate="label,comment">
|
101 |
+
<label>Enabled</label>
|
102 |
+
<comment>Enable/disable invoice payment with Payson.</comment>
|
103 |
+
<frontend_type>select</frontend_type>
|
104 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
105 |
+
<sort_order>10</sort_order>
|
106 |
+
<show_in_default>1</show_in_default>
|
107 |
+
<show_in_website>1</show_in_website>
|
108 |
+
<show_in_store>1</show_in_store>
|
109 |
+
</active>
|
110 |
+
<!--<activate_invoice translate="label,comment">
|
111 |
+
<label>Activate invoice on purchase</label>
|
112 |
+
<comment>Enable this to send Payson invoice to customer instantly after purchase. Disabling this means you have to mark the goods as Shipped in Admin to activate the invoice</comment>
|
113 |
+
<frontend_type>select</frontend_type>
|
114 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
115 |
+
<sort_order>15</sort_order>
|
116 |
+
<show_in_default>1</show_in_default>
|
117 |
+
<show_in_website>1</show_in_website>
|
118 |
+
<show_in_store>1</show_in_store>
|
119 |
+
</activate_invoice>-->
|
120 |
+
<invoice_fee_tax translate="label,comment">
|
121 |
+
<label>Invoice fee tax</label>
|
122 |
+
<comment>Tax class for invoice fees.</comment>
|
123 |
+
<frontend_type>select</frontend_type>
|
124 |
+
<source_model>adminhtml/system_config_source_shipping_taxclass</source_model>
|
125 |
+
<sort_order>20</sort_order>
|
126 |
+
<show_in_default>1</show_in_default>
|
127 |
+
<show_in_website>1</show_in_website>
|
128 |
+
<show_in_store>1</show_in_store>
|
129 |
+
</invoice_fee_tax>
|
130 |
+
<invoice_fee_sek translate="label,comment">
|
131 |
+
<label>Invoice fee (SEK)</label>
|
132 |
+
<comment>Invoice fee for SEK excluding tax.</comment>
|
133 |
+
<frontend_type>text</frontend_type>
|
134 |
+
<sort_order>30</sort_order>
|
135 |
+
<show_in_default>1</show_in_default>
|
136 |
+
<show_in_website>1</show_in_website>
|
137 |
+
<show_in_store>1</show_in_store>
|
138 |
+
</invoice_fee_sek>
|
139 |
+
<invoice_fee_eur translate="label,comment">
|
140 |
+
<label>Invoice fee (EUR)</label>
|
141 |
+
<comment>Invoice fee for EUR excluding tax.</comment>
|
142 |
+
<frontend_type>text</frontend_type>
|
143 |
+
<sort_order>40</sort_order>
|
144 |
+
<show_in_default>1</show_in_default>
|
145 |
+
<show_in_website>1</show_in_website>
|
146 |
+
<show_in_store>1</show_in_store>
|
147 |
+
</invoice_fee_eur>
|
148 |
|
149 |
+
<!--<invoice_minimum_amount translate="label,comment">
|
150 |
+
<label>Invoice minimum amount (SEK)</label>
|
151 |
+
<comment>Invoice minimum amount</comment>
|
152 |
+
<frontend_type>text</frontend_type>
|
153 |
+
<sort_order>42</sort_order>
|
154 |
+
<show_in_default>1</show_in_default>
|
155 |
+
<show_in_website>1</show_in_website>
|
156 |
+
<show_in_store>1</show_in_store>
|
157 |
+
</invoice_minimum_amount>-->
|
158 |
+
</fields>
|
159 |
+
</payson_invoice>
|
160 |
+
</groups>
|
161 |
+
</payment>
|
162 |
+
</sections>
|
163 |
</config>
|
164 |
|
app/code/community/Payson/Payson/sql/payson_setup/mysql4-install-0.1.0.php
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
<?php
|
|
|
2 |
$this->startSetup();
|
3 |
$this->run('
|
4 |
CREATE TABLE IF NOT EXISTS `' . $this->getTable('payson_order') . '`
|
@@ -24,20 +25,8 @@ CREATE TABLE IF NOT EXISTS `' . $this->getTable('payson_order_log') . '`
|
|
24 |
PRIMARY KEY (`id`)
|
25 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
$this->addAttribute('quote', 'base_payson_invoice_fee',
|
30 |
-
array('type' => 'decimal(12,4)', 'grid' => false));*/
|
31 |
-
|
32 |
-
$this->addAttribute('order', 'payson_invoice_fee',
|
33 |
-
array('type' => 'decimal', 'grid' => false));
|
34 |
-
$this->addAttribute('order', 'base_payson_invoice_fee',
|
35 |
-
array('type' => 'decimal', 'grid' => false));
|
36 |
-
|
37 |
-
/*$this->addAttribute('invoice', 'payson_invoice_fee',
|
38 |
-
array('type' => 'decimal', 'grid' => false));
|
39 |
-
$this->addAttribute('invoice', 'base_payson_invoice_fee',
|
40 |
-
array('type' => 'decimal', 'grid' => false));*/
|
41 |
|
42 |
$this->endSetup();
|
43 |
|
1 |
<?php
|
2 |
+
|
3 |
$this->startSetup();
|
4 |
$this->run('
|
5 |
CREATE TABLE IF NOT EXISTS `' . $this->getTable('payson_order') . '`
|
25 |
PRIMARY KEY (`id`)
|
26 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
|
27 |
|
28 |
+
$this->addAttribute('order', 'payson_invoice_fee', array('type' => 'decimal', 'grid' => false));
|
29 |
+
$this->addAttribute('order', 'base_payson_invoice_fee', array('type' => 'decimal', 'grid' => false));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
$this->endSetup();
|
32 |
|
app/code/community/Payson/Payson/sql/payson_setup/mysql4-upgrade-0.1.0-0.1.2.php
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
<?php
|
|
|
2 |
$this->startSetup();
|
3 |
$this->run('alter table `' . $this->getTable('payson_order') . '` add store_id int;
|
4 |
');
|
1 |
<?php
|
2 |
+
|
3 |
$this->startSetup();
|
4 |
$this->run('alter table `' . $this->getTable('payson_order') . '` add store_id int;
|
5 |
');
|
app/design/adminhtml/default/default/Payson/Payson/total.phtml
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
<tr>
|
2 |
-
|
3 |
-
|
4 |
</tr>
|
5 |
|
1 |
<tr>
|
2 |
+
<td class="label"><?php echo($this->__('Invoice Fee')); ?></td>
|
3 |
+
<td><?php echo($this->displayPriceAttribute('payson_invoice_fee')); ?></td>
|
4 |
</tr>
|
5 |
|
app/design/adminhtml/default/default/layout/Payson.xml
CHANGED
@@ -1,34 +1,24 @@
|
|
1 |
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
<layout>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
<adminhtml_sales_order_creditmemo_new>
|
24 |
-
<reference name="creditmemo_totals">
|
25 |
-
<block type="adminhtml/sales_order_totals_item" name="payson_invoice_fee" template="Payson/Payson/total.phtml" />
|
26 |
-
</reference>
|
27 |
-
</adminhtml_sales_order_creditmemo_new>
|
28 |
-
<!--<adminhtml_sales_order_creditmemo_view>
|
29 |
-
<reference name="creditmemo_totals">
|
30 |
-
<block type="adminhtml/sales_order_totals_item" name="payson_invoice_fee" template="Payson/Payson/total.phtml" />
|
31 |
-
</reference>
|
32 |
-
</adminhtml_sales_order_creditmemo_view>-->
|
33 |
</layout>
|
34 |
|
1 |
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
<layout>
|
3 |
+
<adminhtml_sales_order_view>
|
4 |
+
<reference name="order_totals">
|
5 |
+
<block type="adminhtml/sales_order_totals_item" name="payson_invoice_fee" template="Payson/Payson/total.phtml" />
|
6 |
+
</reference>
|
7 |
+
</adminhtml_sales_order_view>
|
8 |
+
<adminhtml_sales_order_invoice_new>
|
9 |
+
<reference name="invoice_totals">
|
10 |
+
<block type="adminhtml/sales_order_totals_item" name="payson_invoice_fee" template="Payson/Payson/total.phtml" />
|
11 |
+
</reference>
|
12 |
+
</adminhtml_sales_order_invoice_new>
|
13 |
+
<adminhtml_sales_order_invoice_view>
|
14 |
+
<reference name="invoice_totals">
|
15 |
+
<block type="adminhtml/sales_order_totals_item" name="payson_invoice_fee" template="Payson/Payson/total.phtml" />
|
16 |
+
</reference>
|
17 |
+
</adminhtml_sales_order_invoice_view>
|
18 |
+
<adminhtml_sales_order_creditmemo_new>
|
19 |
+
<reference name="creditmemo_totals">
|
20 |
+
<block type="adminhtml/sales_order_totals_item" name="payson_invoice_fee" template="Payson/Payson/total.phtml" />
|
21 |
+
</reference>
|
22 |
+
</adminhtml_sales_order_creditmemo_new>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
</layout>
|
24 |
|
app/design/frontend/base/default/layout/Payson.xml
CHANGED
@@ -1,45 +1,45 @@
|
|
1 |
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
<layout version="0.1.0">
|
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 |
</layout>
|
45 |
|
1 |
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
<layout version="0.1.0">
|
3 |
+
<sales_order_print>
|
4 |
+
<reference name="order_totals">
|
5 |
+
<block type="payson/order_totals_fee" name="payson_invoice_fee" />
|
6 |
+
</reference>
|
7 |
+
</sales_order_print>
|
8 |
+
<sales_order_view>
|
9 |
+
<reference name="order_totals">
|
10 |
+
<block type="payson/order_totals_fee" name="payson_invoice_fee" />
|
11 |
+
</reference>
|
12 |
+
</sales_order_view>
|
13 |
+
<sales_order_invoice>
|
14 |
+
<reference name="invoice_totals">
|
15 |
+
<block type="payson/order_totals_fee" name="payson_invoice_fee" />
|
16 |
+
</reference>
|
17 |
+
</sales_order_invoice>
|
18 |
+
<sales_order_printinvoice>
|
19 |
+
<reference name="invoice_totals">
|
20 |
+
<block type="payson/order_totals_fee" name="payson_invoice_fee" />
|
21 |
+
</reference>
|
22 |
+
</sales_order_printinvoice>
|
23 |
+
<sales_order_creditmemo>
|
24 |
+
<reference name="creditmemo_totals">
|
25 |
+
<block type="payson/order_totals_fee" name="payson_invoice_fee" />
|
26 |
+
</reference>
|
27 |
+
</sales_order_creditmemo>
|
28 |
+
<sales_order_printcreditmemo>
|
29 |
+
<reference name="creditmemo_totals">
|
30 |
+
<block type="payson/order_totals_fee" name="payson_invoice_fee" />
|
31 |
+
</reference>
|
32 |
+
</sales_order_printcreditmemo>
|
33 |
+
<sales_email_order_items>
|
34 |
+
<reference name="order_totals">
|
35 |
+
<block type="payson/order_totals_fee" name="payson_invoice_fee" />
|
36 |
+
</reference>
|
37 |
+
</sales_email_order_items>
|
38 |
+
<sales_email_order_invoice_items>
|
39 |
+
<reference name="invoice_totals">
|
40 |
+
<block type="payson/order_totals_fee" name="payson_invoice_fee" />
|
41 |
+
</reference>
|
42 |
+
</sales_email_order_invoice_items>
|
43 |
+
<!-- sales_email_order_shipment_items sales_email_order_creditmemo_items -->
|
44 |
</layout>
|
45 |
|
app/design/frontend/base/default/template/Payson/Payson/invoice_form.phtml
CHANGED
@@ -1,15 +1,15 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
?>
|
5 |
<fieldset class="form-list">
|
6 |
-
|
7 |
-
|
8 |
-
<?php
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
?>
|
13 |
-
|
14 |
</fieldset>
|
15 |
|
1 |
<?php
|
2 |
+
$helper = Mage::Helper('payson');
|
3 |
+
$code = $this->getMethodCode();
|
4 |
?>
|
5 |
<fieldset class="form-list">
|
6 |
+
<label for="p_method_<?php echo($code); ?>" style="float: none"><img src="<?php echo(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN)); ?>frontend/base/default/Payson/Payson/payson_faktura.png" alt="Payson" style="margin: 10px 0; display: block" /></label>
|
7 |
+
<p id="payment_form_<?php echo($code); ?>" style="display: none">
|
8 |
+
<?php
|
9 |
+
echo($helper->__('You will be redirected to Payson\'s website.'));
|
10 |
+
echo '<br /><br />';
|
11 |
+
echo($helper->__('If you choose to pay by Paysoninvoice so there is a fee. Payment terms are 10 days and the invoice will be sent separately by email to the email address you specify. To pay by Paysoninvoice You must be 18 years old and be registered in Sweden as well as authorized in the credit assessment carried out at purchase.'));
|
12 |
?>
|
13 |
+
</p>
|
14 |
</fieldset>
|
15 |
|
app/design/frontend/base/default/template/Payson/Payson/standard_form.phtml
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
?>
|
5 |
<fieldset class="form-list">
|
6 |
-
|
7 |
-
|
8 |
</fieldset>
|
9 |
|
1 |
<?php
|
2 |
+
$helper = Mage::Helper('payson');
|
3 |
+
$code = $this->getMethodCode();
|
4 |
?>
|
5 |
<fieldset class="form-list">
|
6 |
+
<label for="p_method_<?php echo($code); ?>" style="float: none"><img src="<?php echo(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN)); ?>frontend/base/default/Payson/Payson/payson.png" alt="Payson" style="margin: 10px 0; display: block" /></label>
|
7 |
+
<p id="payment_form_<?php echo($code); ?>" style="display: none"><?php echo($helper->__('You will be redirected to Payson\'s website.')); ?></p>
|
8 |
</fieldset>
|
9 |
|
app/etc/modules/Payson_Payson.xml
CHANGED
@@ -1,14 +1,14 @@
|
|
1 |
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
<config>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
</config>
|
14 |
|
1 |
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
<config>
|
3 |
+
<modules>
|
4 |
+
<Payson_Payson>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>community</codePool>
|
7 |
+
<version>1.0</version>
|
8 |
+
<depends>
|
9 |
+
<Mage_Payment />
|
10 |
+
</depends>
|
11 |
+
</Payson_Payson>
|
12 |
+
</modules>
|
13 |
</config>
|
14 |
|
package.xml
CHANGED
@@ -1,27 +1,23 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Payson</name>
|
4 |
-
<version>0.
|
5 |
<stability>stable</stability>
|
6 |
<license>BSD</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
<summary>Official Payson module for Magento. Use this to be able to handle invoice, card and direct bank transfers in your store. 
|
10 |

|
11 |
-
! Requires a contract with Payson. Read more here (https://www.payson.se/ebutik)</summary>
|
12 |
<description>Make it easy to charge your customers. Chose Payson.
|
13 |

|
14 |
-
This module integrates with Payson and allows you to charge your customers via Invoice, Card and direct bank transfers.</description>
|
15 |
-
<notes>*
|
16 |
-
|
17 |
-
* An issue with the cancel URL has been fixed
|
18 |
-
<br />
|
19 |
-
* When selecting test mode the module will be using test credentials automatically
|
20 |
-
</notes>
|
21 |
<authors><author><name>Daniel Hansen</name><user>PaysonAB</user><email>integration@payson.se</email></author></authors>
|
22 |
-
<date>2013-
|
23 |
-
<time>
|
24 |
-
<contents><target name="mage"><dir name="app"><dir name="code"><dir name="community"><dir name="Payson"><dir name="Payson"><dir name="Block"><file name="Form.php" hash="
|
25 |
<compatible/>
|
26 |
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
27 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Payson</name>
|
4 |
+
<version>1.0.0</version>
|
5 |
<stability>stable</stability>
|
6 |
<license>BSD</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
<summary>Official Payson module for Magento. Use this to be able to handle invoice, card and direct bank transfers in your store. 
|
10 |

|
11 |
+
! Requires a contract with Payson. Read more here (https://www.payson.se/ebutik)</summary>
|
12 |
<description>Make it easy to charge your customers. Chose Payson.
|
13 |

|
14 |
+
This module integrates with Payson and allows you to charge your customers via Invoice, Card and direct bank transfers.</description>
|
15 |
+
<notes>* When order is cancelled product is credited to inventory
|
16 |
+
* Cart is now restored when returning from Payson and payment failed</notes>
|
|
|
|
|
|
|
|
|
17 |
<authors><author><name>Daniel Hansen</name><user>PaysonAB</user><email>integration@payson.se</email></author></authors>
|
18 |
+
<date>2013-05-28</date>
|
19 |
+
<time>13:26:26</time>
|
20 |
+
<contents><target name="mage"><dir name="app"><dir name="code"><dir name="community"><dir name="Payson"><dir name="Payson"><dir name="Block"><file name="Form.php" hash="5ad3b8115583fbd8b5fd0ac24440325b"/><dir name="Invoice"><file name="Form.php" hash="8e9bc849ecbb21c3cdf709b2ba074a87"/></dir><dir name="Order"><dir name="Totals"><file name="Fee.php" hash="0ea99606a8f5e80a2a5f80208c683e44"/></dir></dir><dir name="Standard"><file name="Form.php" hash="eb63196829d96c6da7309eadd87c707e"/></dir></dir><dir name="Helper"><dir name="Api"><dir name="Response"><file name="Interface.php" hash="50bda3e73b646165c325e5aa38811554"/><dir name="Standard"><file name="Parameters.php" hash="3fa48fd19ca86ce96613047038e70a2f"/></dir><file name="Standard.php" hash="8d4a4960a8110338a2a0f9b162b52b37"/><file name="Validate.php" hash="35d82eef0cf69983f3ffd9fcc3692e25"/></dir></dir><file name="Api.php" hash="2f85ea4724e4fad6ea6cd15f7ddf55ed"/><file name="Data.php" hash="3e3492d7136d77ff61876d2b4d729c20"/></dir><dir name="Model"><file name="Config.php" hash="d39090c646bc4d973d30084a21ca0353"/><dir name="Method"><file name="Abstract.php" hash="55be4eda8833b5434ffb30beb61e32f5"/><file name="Invoice.php" hash="4a97c381dc250e1b0e0e3084057c356a"/><file name="Standard.php" hash="48b4aa062bf5490937c6c68de0b79a2b"/></dir><dir name="Mysql4"><file name="Setup.php" hash="64d97efb592c665290ae4a13015c2df5"/></dir><dir name="Order"><dir name="Creditmemo"><dir name="Total"><file name="Invoice.php" hash="883c7d27f035a9284c6624a741a3fe31"/></dir></dir><dir name="Invoice"><dir name="Total"><file name="Invoice.php" hash="c357815cc2eeb6836946ea3a13528029"/></dir></dir></dir><dir name="Quote"><dir name="Address"><dir name="Total"><file name="Invoice.php" hash="423a7c2f9a61e47b8d8a0155d624488a"/></dir></dir></dir><file name="Standard.php" hash="a154909d27639455270b9c2d1a22b1bc"/></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><file name="ShipmentController.php" hash="56118704e788b2b53086f7c9be71c996"/></dir></dir></dir><file name="CheckoutController.php" hash="d8dfb135ada18c213052e3dc613c34e7"/><file name="IpnController.php" hash="9b724b278793d5fc8e64f0a49f7914c7"/></dir><dir name="etc"><file name="config.xml" hash="c2ac51d643757dc151591b2834088378"/><file name="system.xml" hash="80254a7bf100e003d15b3f47ffbe06e5"/></dir><dir name="sql"><dir name="payson_setup"><file name="mysql4-install-0.1.0.php" hash="8422dccd6ccb5ce214f17bfa8ae08bd3"/><file name="mysql4-upgrade-0.1.0-0.1.2.php" hash="cc846d866a93167c79d3286f512e6bf6"/></dir></dir></dir></dir></dir></dir><dir name="design"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="Payson"><dir name="Payson"><file name="total.phtml" hash="795e38fb672ffd23f38ed28578c7ee2f"/></dir></dir><dir name="layout"><file name="Payson.xml" hash=""/></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="Payson"><dir name="Payson"><file name="invoice_form.phtml" hash="2b69133eb3c04f582535e3a80ba76229"/><file name="standard_form.phtml" hash="147fd545564940747b2e8a85a23c1dd6"/></dir></dir></dir><dir name="layout"><file name="Payson.xml" hash=""/></dir></dir></dir></dir></dir><dir name="etc"><dir name="modules"><file name="Payson_Payson.xml" hash=""/></dir></dir><dir name="locale"><dir name="sv_SE"><file name="Payson_Payson.csv" hash=""/></dir></dir></dir><dir name="skin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="Payson"><dir name="Payson"><file name="payson.gif" hash="638d0055cbc1a4bdc32e9fa1156b722a"/><file name="payson.png" hash="308916345711a4520313c94218c5bda7"/><file name="payson_faktura.png" hash="fa218c9949c05c6f3452d9f4c541da2c"/></dir></dir></dir></dir></dir></dir></target></contents>
|
21 |
<compatible/>
|
22 |
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
23 |
</package>
|