/
ProcessingController.php
146 lines (135 loc) · 4.72 KB
/
ProcessingController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* @category Phoenix
* @package Phoenix_Moneybookers
* @copyright Copyright (c) 2013 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
class Phoenix_Moneybookers_ProcessingController extends Mage_Core_Controller_Front_Action
{
/**
* Get singleton of Checkout Session Model
*
* @return Mage_Checkout_Model_Session
*/
protected function _getCheckout()
{
return Mage::getSingleton('checkout/session');
}
/**
* Iframe page which submits the payment data to Moneybookers.
*/
public function placeformAction()
{
$this->loadLayout();
$this->renderLayout();
}
/**
* Show orderPlaceRedirect page which contains the Moneybookers iframe.
*/
public function paymentAction()
{
try {
$session = $this->_getCheckout();
$order = Mage::getModel('sales/order');
$order->loadByIncrementId($session->getLastRealOrderId());
if (!$order->getId()) {
Mage::throwException('No order for processing found');
}
$order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, Mage_Sales_Model_Order::STATE_PENDING_PAYMENT,
Mage::helper('moneybookers')->__('The customer was redirected to Moneybookers.')
);
$order->save();
$session->setMoneybookersQuoteId($session->getQuoteId());
$session->setMoneybookersRealOrderId($session->getLastRealOrderId());
$session->getQuote()->setIsActive(false)->save();
$session->clear();
$this->loadLayout();
$this->renderLayout();
} catch (Exception $e){
Mage::logException($e);
parent::_redirect('checkout/cart');
}
}
/**
* Action to which the customer will be returned when the payment is made.
*/
public function successAction()
{
$event = Mage::getModel('moneybookers/event')
->setEventData($this->getRequest()->getParams());
try {
$quoteId = $event->successEvent();
$this->_getCheckout()->setLastSuccessQuoteId($quoteId);
$this->_redirect('checkout/onepage/success');
return;
} catch (Mage_Core_Exception $e) {
$this->_getCheckout()->addError($e->getMessage());
} catch(Exception $e) {
Mage::logException($e);
}
$this->_redirect('checkout/cart');
}
/**
* Action to which the customer will be returned if the payment process is
* cancelled.
* Cancel order and redirect user to the shopping cart.
*/
public function cancelAction()
{
$event = Mage::getModel('moneybookers/event')
->setEventData($this->getRequest()->getParams());
$message = $event->cancelEvent();
// set quote to active
$session = $this->_getCheckout();
if ($quoteId = $session->getMoneybookersQuoteId()) {
$quote = Mage::getModel('sales/quote')->load($quoteId);
if ($quote->getId()) {
$quote->setIsActive(true)->save();
$session->setQuoteId($quoteId);
}
}
$session->addError($message);
$this->_redirect('checkout/cart');
}
/**
* Action to which the transaction details will be posted after the payment
* process is complete.
*/
public function statusAction()
{
$event = Mage::getModel('moneybookers/event')
->setEventData($this->getRequest()->getParams());
$message = $event->processStatusEvent();
$this->getResponse()->setBody($message);
}
/**
* Set redirect into responce. This has to be encapsulated in an JavaScript
* call to jump out of the iframe.
*
* @param string $path
* @param array $arguments
*/
protected function _redirect($path, $arguments=array())
{
$this->getResponse()->setBody(
$this->getLayout()
->createBlock('moneybookers/redirect')
->setRedirectUrl(Mage::getUrl($path, $arguments))
->toHtml()
);
return $this;
}
}