Trustly - Version 2.0.10

Version Notes

Download this release

Release Info

Developer Trustly
Extension Trustly
Version 2.0.10
Comparing to
See all releases


Code changes from version 2.0.8 to 2.0.10

app/code/community/Trustly/Trustly/Block/Form.php CHANGED
@@ -45,3 +45,4 @@ class Trustly_Trustly_Block_Form extends Mage_Payment_Block_Form
45
  }
46
 
47
  }
 
45
  }
46
 
47
  }
48
+ /* vim: set noet cindent ts=4 ts=4 sw=4: */
app/code/community/Trustly/Trustly/Block/Redirect.php CHANGED
@@ -29,7 +29,7 @@ class Trustly_Trustly_Block_Redirect extends Mage_Core_Block_Template
29
  public function getIframe()
30
  {
31
  $session = Mage::getSingleton('checkout/session');
32
- $url = $session->getUrlTrustly();
33
 
34
  if (!isset($url) || empty($url)) {
35
  return false;
@@ -38,3 +38,4 @@ class Trustly_Trustly_Block_Redirect extends Mage_Core_Block_Template
38
  }
39
  }
40
  }
 
29
  public function getIframe()
30
  {
31
  $session = Mage::getSingleton('checkout/session');
32
+ $url = $session->getTrustlyIframeUrl();
33
 
34
  if (!isset($url) || empty($url)) {
35
  return false;
38
  }
39
  }
40
  }
41
+ /* vim: set noet cindent ts=4 ts=4 sw=4: */
app/code/community/Trustly/Trustly/Block/System/Config/About.php CHANGED
@@ -36,3 +36,4 @@ class Trustly_Trustly_Block_System_Config_About extends Mage_Adminhtml_Block_Abs
36
  return $html;
37
  }
38
  }
 
36
  return $html;
37
  }
38
  }
39
+ /* vim: set noet cindent ts=4 ts=4 sw=4: */
app/code/community/Trustly/Trustly/Helper/Data.php CHANGED
@@ -220,3 +220,4 @@ class Trustly_Trustly_Helper_Data extends Mage_Core_Helper_Abstract
220
  }
221
 
222
  }
 
220
  }
221
 
222
  }
223
+ /* vim: set noet cindent ts=4 ts=4 sw=4: */
app/code/community/Trustly/Trustly/Model/Mysql4/Ordermappings.php CHANGED
@@ -70,4 +70,4 @@ class Trustly_Trustly_Model_Mysql4_Ordermappings extends Mage_Core_Model_Mysql4_
70
  return TRUE;
71
  }
72
  }
73
- ?>
70
  return TRUE;
71
  }
72
  }
73
+ /* vim: set noet cindent ts=4 ts=4 sw=4: */
app/code/community/Trustly/Trustly/Model/Ordermappings.php CHANGED
@@ -36,13 +36,22 @@ class Trustly_Trustly_Model_Ordermappings extends Mage_Core_Model_Abstract
36
  return $this->load($trustlyOrderId, 'trustly_order_id');
37
  }
38
 
39
- public function lockIncrementForProcessing($incrementId) {
 
 
 
 
 
 
 
 
 
40
  return $this->getResource()->lockIncrementForProcessing($incrementId);
41
  }
42
 
43
- public function unlockIncrementAfterProcessing($incrementId, $lockid) {
 
44
  return $this->getResource()->unlockIncrementAfterProcessing($incrementId, $lockid);
45
  }
46
  }
47
-
48
- ?>
36
  return $this->load($trustlyOrderId, 'trustly_order_id');
37
  }
38
 
39
+ public function unmapOrderIncrement($incrementid)
40
+ {
41
+ $this->load($incrementid, 'magento_increment_id');
42
+ if($this->getTrustlyOrderId()) {
43
+ $this->delete();
44
+ }
45
+ }
46
+
47
+ public function lockIncrementForProcessing($incrementId)
48
+ {
49
  return $this->getResource()->lockIncrementForProcessing($incrementId);
50
  }
51
 
52
+ public function unlockIncrementAfterProcessing($incrementId, $lockid)
53
+ {
54
  return $this->getResource()->unlockIncrementAfterProcessing($incrementId, $lockid);
55
  }
56
  }
57
+ /* vim: set noet cindent ts=4 ts=4 sw=4: */
 
app/code/community/Trustly/Trustly/Model/Standard.php CHANGED
@@ -62,6 +62,11 @@ class Trustly_Trustly_Model_Standard extends Mage_Payment_Model_Method_Abstract
62
  */
63
  protected $_canRefund = true;
64
 
 
 
 
 
 
65
  /**
66
  * Can void transactions online?
67
  */
@@ -85,9 +90,9 @@ class Trustly_Trustly_Model_Standard extends Mage_Payment_Model_Method_Abstract
85
  /**
86
  * Can save credit card information for future processing?
87
  */
88
- protected $_canSaveCc = false;
89
 
90
- protected $_formBlockType = 'trustly/form';
91
 
92
 
93
  const PAYMENT_TYPE_AUTH = 'AUTHORIZATION';
@@ -106,33 +111,6 @@ class Trustly_Trustly_Model_Standard extends Mage_Payment_Model_Method_Abstract
106
  }
107
 
108
 
109
- /**
110
- * Get session namespace
111
- */
112
- public function getSession()
113
- {
114
- return Mage::getSingleton('trustly/session');
115
- }
116
-
117
-
118
- /**
119
- * Get checkout namespace
120
- */
121
- public function getCheckout()
122
- {
123
- return Mage::getSingleton('checkout/session');
124
- }
125
-
126
-
127
- /**
128
- * Get actual quote
129
- */
130
- public function getQuote()
131
- {
132
- return $this->getCheckout()->getQuote();
133
- }
134
-
135
-
136
  public function getOrderPlaceRedirectUrl()
137
  {
138
  return Mage::getUrl('trustly/payment/redirect', array('_secure' => true));
@@ -173,10 +151,15 @@ class Trustly_Trustly_Model_Standard extends Mage_Payment_Model_Method_Abstract
173
  return false;
174
  }
175
 
176
- $orderId = $this->getCheckout()->getLastRealOrderId();
 
 
177
  $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
178
 
179
- $session = Mage::getSingleton('checkout/session');
 
 
 
180
 
181
  $notificationUrl = Mage::getUrl('trustly/payment/update');
182
 
@@ -230,7 +213,7 @@ class Trustly_Trustly_Model_Standard extends Mage_Payment_Model_Method_Abstract
230
 
231
  if (!isset($response)) {
232
  Mage::log("Could not connect to Trustly (no response)", Zend_Log::WARN, self::LOG_FILE);
233
- Mage::getSingleton('core/session')->addError(Mage::helper('trustly')->__('Could not connect to Trustly.'));
234
  return false;
235
  } elseif (isset($response) && $response->isSuccess()) {
236
  $url = $response->getData('url');
@@ -238,8 +221,6 @@ class Trustly_Trustly_Model_Standard extends Mage_Payment_Model_Method_Abstract
238
 
239
  Mage::log("Got response with orderid $trustlyOrderId from Trustly, redirecting user to url: $url", Zend_Log::DEBUG, self::LOG_FILE);
240
 
241
- Mage::getSingleton('checkout/session')->setData('orderid_trustly', $trustlyOrderId);
242
-
243
  $incrementId = $order->getIncrementId();
244
  $orderMapping = Mage::getModel('trustly/ordermappings');
245
  $omData = array(
@@ -249,7 +230,7 @@ class Trustly_Trustly_Model_Standard extends Mage_Payment_Model_Method_Abstract
249
  );
250
  $orderMapping->setData($omData);
251
  $orderMapping->save();
252
- Mage::log("Saved mapping between Trustly orderid $trustlyOrderId and increment id $incrementId", Zend_Log::DEBUG, self::LOG_FILE);
253
 
254
  return $url;
255
  } else {
@@ -259,11 +240,11 @@ class Trustly_Trustly_Model_Standard extends Mage_Payment_Model_Method_Abstract
259
  if ($message) {
260
  Mage::log(sprintf("Trustly pay call failed: %s - %s", $code, $message), Zend_Log::WARN, self::LOG_FILE);
261
  $_msjError = Mage::helper('trustly')->getErrorMsg($message, $code);
262
- Mage::getSingleton('core/session')->addError(Mage::helper('trustly')->__($_msjError));
263
  return false;
264
  } else {
265
  Mage::log("Trustly pay call failed without returning a proper error", Zend_Log::WARN, self::LOG_FILE);
266
- Mage::getSingleton('core/session')->addError(Mage::helper('trustly')->__('Error processing Trustly communication.'));
267
  return false;
268
  }
269
  }
@@ -272,3 +253,4 @@ class Trustly_Trustly_Model_Standard extends Mage_Payment_Model_Method_Abstract
272
  return false;
273
  }
274
  }
 
62
  */
63
  protected $_canRefund = true;
64
 
65
+ /**
66
+ * Can refund parts of the invoice?
67
+ */
68
+ protected $_canRefundInvoicePartial = true;
69
+
70
  /**
71
  * Can void transactions online?
72
  */
90
  /**
91
  * Can save credit card information for future processing?
92
  */
93
+ protected $_canSaveCc = false;
94
 
95
+ protected $_formBlockType = 'trustly/form';
96
 
97
 
98
  const PAYMENT_TYPE_AUTH = 'AUTHORIZATION';
111
  }
112
 
113
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  public function getOrderPlaceRedirectUrl()
115
  {
116
  return Mage::getUrl('trustly/payment/redirect', array('_secure' => true));
151
  return false;
152
  }
153
 
154
+ $session = Mage::getSingleton('checkout/session');
155
+
156
+ $orderId = $session->getLastRealOrderId();
157
  $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
158
 
159
+ # Unmap this order from any previous trustly orders to prevent previous
160
+ # order updates coming into this order. The latest payment should be
161
+ # the one.
162
+ Mage::getModel('trustly/ordermappings')->unmapOrderIncrement($orderId);
163
 
164
  $notificationUrl = Mage::getUrl('trustly/payment/update');
165
 
213
 
214
  if (!isset($response)) {
215
  Mage::log("Could not connect to Trustly (no response)", Zend_Log::WARN, self::LOG_FILE);
216
+ $session->addError(Mage::helper('trustly')->__('Could not connect to Trustly.'));
217
  return false;
218
  } elseif (isset($response) && $response->isSuccess()) {
219
  $url = $response->getData('url');
221
 
222
  Mage::log("Got response with orderid $trustlyOrderId from Trustly, redirecting user to url: $url", Zend_Log::DEBUG, self::LOG_FILE);
223
 
 
 
224
  $incrementId = $order->getIncrementId();
225
  $orderMapping = Mage::getModel('trustly/ordermappings');
226
  $omData = array(
230
  );
231
  $orderMapping->setData($omData);
232
  $orderMapping->save();
233
+ Mage::log("Saved mapping between Trustly orderid $trustlyOrderId and increment id $incrementId", Zend_Log::INFO, self::LOG_FILE);
234
 
235
  return $url;
236
  } else {
240
  if ($message) {
241
  Mage::log(sprintf("Trustly pay call failed: %s - %s", $code, $message), Zend_Log::WARN, self::LOG_FILE);
242
  $_msjError = Mage::helper('trustly')->getErrorMsg($message, $code);
243
+ $session->addError(Mage::helper('trustly')->__($_msjError));
244
  return false;
245
  } else {
246
  Mage::log("Trustly pay call failed without returning a proper error", Zend_Log::WARN, self::LOG_FILE);
247
+ $session->addError(Mage::helper('trustly')->__('Error processing Trustly communication.'));
248
  return false;
249
  }
250
  }
253
  return false;
254
  }
255
  }
256
+ /* vim: set noet cindent ts=4 ts=4 sw=4: */
app/code/community/Trustly/Trustly/controllers/PaymentController.php CHANGED
@@ -33,12 +33,6 @@ class Trustly_Trustly_PaymentController extends Mage_Core_Controller_Front_Actio
33
  return Mage::getSingleton('trustly/standard');
34
  }
35
 
36
- protected function _getCheckout() {
37
-
38
- return Mage::getSingleton('order/checkout');
39
- }
40
-
41
-
42
  public function _expireSession()
43
  {
44
  if(!Mage::getSingleton('customer/session')->isLoggedIn()) {
@@ -52,46 +46,95 @@ class Trustly_Trustly_PaymentController extends Mage_Core_Controller_Front_Actio
52
 
53
  public function redirectAction()
54
  {
55
-
56
  Mage::log("redirectAction()", Zend_Log::DEBUG, self::LOG_FILE);
57
  $session = Mage::getSingleton('checkout/session');
58
- $session->setTrustlyQuoteId($session->getQuoteId());
59
 
60
- $session->unsUrlTrustly();
61
- /* Clear all the error messages before we checkout, or previous errors might linger on */
62
- $session->getMessages(true);
 
 
 
63
 
64
- $standard = Mage::getModel('trustly/standard');
65
- $redirectError = NULL;
66
- $response = NULL;
67
- try {
68
- $response = $standard->redirectProcess();
69
- } catch(Trustly_DataException $e) {
70
- Mage::log("Got Trustly_DataException when communicating with Trustly: " . (string)$e, Zend_Log::DEBUG, self::LOG_FILE);
71
- Mage::logException($e);
72
- $redirectError = Mage::helper('trustly')->__("Failed to communicate with Trustly.");
73
- } catch(Trustly_ConnectionException $e) {
74
- Mage::log("Got Trustly_ConnectionException when communicating with Trustly: " . (string)$e, Zend_Log::DEBUG, self::LOG_FILE);
75
- Mage::logException($e);
76
- $redirectError = Mage::helper('trustly')->__("Cannot connect to Trustly services.");
77
- } catch(Trustly_SignatureException $e) {
78
- Mage::log("Got Trustly_SignatureException when communicating with Trustly: " . (string)$e, Zend_Log::DEBUG, self::LOG_FILE);
79
- Mage::logException($e);
80
- $redirectError = Mage::helper('trustly')->__("Cannot verify the authenticity of Trustly communication.");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  }
 
 
82
 
83
- if (!isset($response)) {
84
- Mage::log("No response from redirectProcess()", Zend_Log::DEBUG, self::LOG_FILE);
85
- if(!isset($redirectError)) {
 
 
 
 
 
 
86
  $redirectError = Mage::helper('trustly')->__("Failed to communicate with Trustly.");
 
 
 
 
 
 
 
 
87
  }
88
- }
89
 
90
- if($redirectError) {
91
- $session->addError($redirectError);
92
- } else {
93
- $session->setUrlTrustly($response);
94
- $session->setOrderTrustly($session->getLastOrderId());
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  }
96
 
97
  $this->loadLayout();
@@ -159,14 +202,14 @@ class Trustly_Trustly_PaymentController extends Mage_Core_Controller_Front_Actio
159
  $incrementId = $orderMapping->getMagentoIncrementId();
160
  }else {
161
  # If we cannot find the mapping here, check to see if the
162
- # enduserid seems to be a valid incrment id, in old code this
163
  # used to be the case. So to handle the transition between the
164
  # old module and this one, allow for this.
165
  # We always use email for enduserid, so we will not match something by accident.
166
  $enduserid = $notification->getData('enduserid');
167
 
168
  if(preg_match('/^[0-9]+$/', $enduserid)) {
169
- Mage::log("Falling back to using enduserid as the incrmentid for enduserid $enduserid", Zend_Log::WARN, self::LOG_FILE);
170
  $incrementId = $enduserid;
171
  }
172
  }
@@ -331,7 +374,7 @@ class Trustly_Trustly_PaymentController extends Mage_Core_Controller_Front_Actio
331
 
332
  $trustly_payment->unsCreatedInvoice();
333
 
334
- Mage::log(sprintf("Recieved %s notification for order with increment %s for orderid %s", $_method, $incrementId, $trustlyOrderId), Zend_Log::DEBUG, self::LOG_FILE);
335
 
336
  if (((int)Mage::getModel('trustly/standard')->getConfigData('sendmailorderconfirmation')) == 1) {
337
  Mage::log('Sending new order email', Zend_Log::DEBUG, self::LOG_FILE);
@@ -478,8 +521,7 @@ class Trustly_Trustly_PaymentController extends Mage_Core_Controller_Front_Actio
478
  $notification_transaction = $this->addChildTransaction($trustly_payment, $trustlyNotificationId, $trustlyOrderId,
479
  Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID, true);
480
 
481
- $orderStatus = Mage_Sales_Model_Order::STATE_CANCELED;
482
- $order->setState($orderStatus, true, NULL, false);
483
 
484
  $transactionSave->addObject($order)
485
  ->addObject($trustly_payment);
@@ -525,33 +567,123 @@ class Trustly_Trustly_PaymentController extends Mage_Core_Controller_Front_Actio
525
  {
526
  Mage::log("successAction()", Zend_Log::DEBUG, self::LOG_FILE);
527
 
 
 
 
 
 
 
528
  $this->_redirect('checkout/onepage/success', array('_secure'=>true));
529
  }
530
 
531
 
532
  public function failAction()
533
  {
534
- Mage::log("failAction()", Zend_Log::DEBUG, self::LOG_FILE);
 
 
 
 
 
 
 
535
 
536
- $orderId = Mage::getSingleton('checkout/session')->getData('orderid_trustly');
537
- $order = Mage::getModel('sales/order')->load($orderId);
 
 
 
 
 
 
 
 
538
 
539
- if ($order) {
540
- $order->cancel()->save();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
541
  }
 
542
  $this->_redirect('checkout/cart', array('_secure'=>Mage::app()->getStore()->isCurrentlySecure()));
543
  }
544
 
545
- public function cancelAction()
 
546
  {
547
- Mage::log("cancelAction()", Zend_Log::DEBUG, self::LOG_FILE);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
548
 
549
- $orderId = Mage::getSingleton('checkout/session')->getData('orderid_trustly');
550
- $order = Mage::getModel('sales/order')->load($orderId);
 
551
 
552
- if ($order) {
553
- $order->cancel()->save();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
554
  }
555
- $this->_redirect('checkout/cart', array('_secure'=>Mage::app()->getStore()->isCurrentlySecure()));
556
  }
557
  }
 
33
  return Mage::getSingleton('trustly/standard');
34
  }
35
 
 
 
 
 
 
 
36
  public function _expireSession()
37
  {
38
  if(!Mage::getSingleton('customer/session')->isLoggedIn()) {
46
 
47
  public function redirectAction()
48
  {
 
49
  Mage::log("redirectAction()", Zend_Log::DEBUG, self::LOG_FILE);
50
  $session = Mage::getSingleton('checkout/session');
51
+ $quoteid = $session->getQuoteId();
52
 
53
+ # Sanity check
54
+ if(!$session->getLastRealOrderId()) {
55
+ Mage::log("Attempting to reload the directpage without valid order", Zend_Log::DEBUG, self::LOG_FILE);
56
+ $this->_redirect('checkout/cart', array('_secure'=>Mage::app()->getStore()->isCurrentlySecure()));
57
+ return ;
58
+ }
59
 
60
+ Mage::log("Processing order for quote $quoteid", Zend_Log::DEBUG, self::LOG_FILE);
61
+
62
+ # If the user reloads the payment page we should not create a new
63
+ # order, instead we should reuse the existing order and iframe
64
+ # redirection url. To prevent the user from cancelling the order,
65
+ # adding more to the same quote and then piggyback on the same payment
66
+ # use the fact that the increment id of the order will change when
67
+ # doing this. If we get a new increment id from when the iframe was
68
+ # loaded the last time then create a new order.
69
+ $lastiframeurl = $session->getTrustlyIframeUrl();
70
+ if($lastiframeurl) {
71
+ $lastincrementid = $session->getTrustlyIncrementId();
72
+
73
+ $currentorder = NULL;
74
+ $currentincrementid = NULL;
75
+
76
+ $lastrealorderid = $session->getLastRealOrderId();
77
+ if($lastrealorderid) {
78
+ $currentorder = Mage::getModel('sales/order')->loadByIncrementId($lastrealorderid);
79
+ }
80
+
81
+ if($currentorder and $currentorder->getId()) {
82
+ # Yes, same as the lastrealorderid above, this just load:s it to make sure it is good.
83
+ $currentincrementid = $currentorder->getIncrementId();
84
+ }
85
+
86
+ if ($currentincrementid and $lastincrementid == $currentincrementid) {
87
+ Mage::log("Reusing the iframeurl for increment $currentincrementid, reloading the redirect page?", Zend_Log::DEBUG, self::LOG_FILE);
88
+ } else {
89
+ $lastiframeurl = NULL;
90
+ }
91
  }
92
+ /* Clear all the error messages before we checkout, or previous errors might linger on */
93
+ $session->getMessages(true);
94
 
95
+ if(!$lastiframeurl) {
96
+ $standard = Mage::getModel('trustly/standard');
97
+ $redirectError = NULL;
98
+ $response = NULL;
99
+ try {
100
+ $response = $standard->redirectProcess();
101
+ } catch(Trustly_DataException $e) {
102
+ Mage::log("Got Trustly_DataException when communicating with Trustly: " . (string)$e, Zend_Log::WARN, self::LOG_FILE);
103
+ Mage::logException($e);
104
  $redirectError = Mage::helper('trustly')->__("Failed to communicate with Trustly.");
105
+ } catch(Trustly_ConnectionException $e) {
106
+ Mage::log("Got Trustly_ConnectionException when communicating with Trustly: " . (string)$e, Zend_Log::WARN, self::LOG_FILE);
107
+ Mage::logException($e);
108
+ $redirectError = Mage::helper('trustly')->__("Cannot connect to Trustly services.");
109
+ } catch(Trustly_SignatureException $e) {
110
+ Mage::log("Got Trustly_SignatureException when communicating with Trustly: " . (string)$e, Zend_Log::WARN, self::LOG_FILE);
111
+ Mage::logException($e);
112
+ $redirectError = Mage::helper('trustly')->__("Cannot verify the authenticity of Trustly communication.");
113
  }
 
114
 
115
+ if (!isset($response)) {
116
+ Mage::log("No response from redirectProcess()", Zend_Log::WARN, self::LOG_FILE);
117
+ if(!isset($redirectError)) {
118
+ $redirectError = Mage::helper('trustly')->__("Failed to communicate with Trustly.");
119
+ }
120
+ }
121
+
122
+ if($redirectError) {
123
+ $session->addError($redirectError);
124
+ $this->unmapQuote();
125
+ $this->restoreQuote();
126
+ } else {
127
+ # We use this to keep track of the current quote we have
128
+ # transformed into an order, use it when cancelling (to restore
129
+ # quote) or when finishing order (to finalize quote).
130
+ $session->setTrustlyQuoteId($quoteid);
131
+ # We use these to handle the reload of the redirect action
132
+ # page. Incrementid is the increment of the current order
133
+ # displayed in the page and the url is the trustly iframe url
134
+ # for this increment.
135
+ $session->setTrustlyIncrementId($session->getLastRealOrderId());
136
+ $session->setTrustlyIframeUrl($response);
137
+ }
138
  }
139
 
140
  $this->loadLayout();
202
  $incrementId = $orderMapping->getMagentoIncrementId();
203
  }else {
204
  # If we cannot find the mapping here, check to see if the
205
+ # enduserid seems to be a valid increment id, in old code this
206
  # used to be the case. So to handle the transition between the
207
  # old module and this one, allow for this.
208
  # We always use email for enduserid, so we will not match something by accident.
209
  $enduserid = $notification->getData('enduserid');
210
 
211
  if(preg_match('/^[0-9]+$/', $enduserid)) {
212
+ Mage::log("Falling back to using enduserid as the incrementid for enduserid $enduserid", Zend_Log::WARN, self::LOG_FILE);
213
  $incrementId = $enduserid;
214
  }
215
  }
374
 
375
  $trustly_payment->unsCreatedInvoice();
376
 
377
+ Mage::log(sprintf("Recieved %s notification for order with increment %s for orderid %s", $_method, $incrementId, $trustlyOrderId), Zend_Log::INFO, self::LOG_FILE);
378
 
379
  if (((int)Mage::getModel('trustly/standard')->getConfigData('sendmailorderconfirmation')) == 1) {
380
  Mage::log('Sending new order email', Zend_Log::DEBUG, self::LOG_FILE);
521
  $notification_transaction = $this->addChildTransaction($trustly_payment, $trustlyNotificationId, $trustlyOrderId,
522
  Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID, true);
523
 
524
+ $order->cancel();
 
525
 
526
  $transactionSave->addObject($order)
527
  ->addObject($trustly_payment);
567
  {
568
  Mage::log("successAction()", Zend_Log::DEBUG, self::LOG_FILE);
569
 
570
+ $session = Mage::getSingleton('checkout/session');
571
+ $session->setQuoteId($session->getTrustlyQuoteId(true));
572
+ $session->getQuote()->setIsActive(false)->save();
573
+ $session->unsTrustlyIncrementId();
574
+ $session->unsTrustlyIframeUrl();
575
+
576
  $this->_redirect('checkout/onepage/success', array('_secure'=>true));
577
  }
578
 
579
 
580
  public function failAction()
581
  {
582
+ Mage::log("failAction() -> cancelAction", Zend_Log::DEBUG, self::LOG_FILE);
583
+ $this->cancelAction();
584
+ }
585
+
586
+
587
+ public function cancelAction()
588
+ {
589
+ Mage::log("cancelAction()", Zend_Log::DEBUG, self::LOG_FILE);
590
 
591
+ $session = Mage::getSingleton('checkout/session');
592
+ try {
593
+ $orderId = $session->getLastOrderId();
594
+ Mage::log("Attempting to cancel order $orderId", Zend_Log::DEBUG, self::LOG_FILE);
595
+ $order = ($orderId) ? Mage::getModel('sales/order')->load($orderId) : false;
596
+
597
+ $sess_quoteid = $session->getTrustlyQuoteId();
598
+ if(!isset($sess_quoteid)) {
599
+ $sess_quoteid = $session->getQuoteId();
600
+ }
601
 
602
+ if ($order && $order->getId() && $order->getQuoteId() == $sess_quoteid) {
603
+ $incrementid = $order->getIncrementId();
604
+ $order->cancel()->save();
605
+ Mage::log("Cancel order $orderId, incrementid $incrementid", Zend_Log::INFO, self::LOG_FILE);
606
+
607
+ $session->unsTrustlyQuoteId();
608
+ $session->unsTrustlyIncrementId();
609
+ $session->unsTrustlyIframeUrl();
610
+ Mage::getModel('trustly/ordermappings')->unmapOrderIncrement($order->getIncrementId());
611
+ $this->restoreQuote();
612
+ $session->addSuccess(Mage::helper('trustly')->__('Trustly order has been canceled.'));
613
+ } else {
614
+ Mage::log(sprintf("No order found to cancel (order=%s, orderid=%s, orderquoteid=%s, sessionquoteid=%s)",
615
+ ($order?'YES':'NO'),
616
+ ($order->getId()?$order->getId():''),
617
+ ($order->getQuoteId()?$order->getQuoteId():''),
618
+ ($sess_quoteid?$sess_quoteid:'')),
619
+ Zend_Log::WARN, self::LOG_FILE);
620
+ $session->addSuccess(Mage::helper('trustly')->__('Trustly order has been canceled.'));
621
+ }
622
+ } catch (Mage_Core_Exception $e) {
623
+ Mage::log("Got Mage_Core_Exception when cancelling order: " . $e->getMessage(), Zend_Log::WARN, self::LOG_FILE);
624
+ $session->addError($e->getMessage());
625
+ } catch (Exception $e) {
626
+ $session->addError(Mage::helper('trustly')->__('Unable to cancel Trustly order.'));
627
+ Mage::log("Got Exception when cancelling order: " . $e->getMessage(), Zend_Log::WARN, self::LOG_FILE);
628
+ Mage::logException($e);
629
  }
630
+
631
  $this->_redirect('checkout/cart', array('_secure'=>Mage::app()->getStore()->isCurrentlySecure()));
632
  }
633
 
634
+
635
+ public function restoreQuote()
636
  {
637
+ $session = Mage::getSingleton('checkout/session');
638
+ $lastrealorderid = $session->getLastRealOrderId();
639
+
640
+ if($lastrealorderid) {
641
+ $order = Mage::getModel('sales/order')->loadByIncrementId($lastrealorderid);
642
+
643
+ if ($order and $order->getId()) {
644
+ $quote = Mage::getModel('sales/quote')->load($order->getQuoteId());
645
+ if ($quote->getId()) {
646
+ Mage::log("Restoring session quote " . $order->getQuoteId(), Zend_Log::DEBUG, self::LOG_FILE);
647
+ $quote->setIsActive(1);
648
+ $quote->setReservedOrderId(null);
649
+ $quote->save();
650
+
651
+ $session->replaceQuote($quote);
652
+ $session->unsLastRealOrderId();
653
+ return true;
654
+ }
655
+ } else {
656
+ Mage::log("Failed to restore session quote, order $lastrealorderid could not be loaded", Zend_Log::WARN, self::LOG_FILE);
657
+ }
658
+ } else {
659
+ Mage::log("Failed to restore session quote, no last order defined", Zend_Log::DEBUG, self::LOG_FILE);
660
+ }
661
+ return false;
662
+ }
663
+
664
 
665
+ public function unmapQuote()
666
+ {
667
+ $session = Mage::getSingleton('checkout/session');
668
 
669
+ $lastrealorderid = $session->getLastRealOrderId();
670
+ $order = NULL;
671
+ if($lastrealorderid) {
672
+ $order = Mage::getModel('sales/order')->loadByIncrementId($lastrealorderid);
673
+
674
+ if($order and $order->getId()) {
675
+ # Yes, this is the same value as above ($lastrealorderid), just verify it's correctness first...
676
+ $incrementid = $order->getIncrementId();
677
+ if ($incrementid) {
678
+ Mage::getModel('trustly/ordermappings')->unmapOrderIncrement($incrementid);
679
+ }
680
+ } else {
681
+ Mage::log("Could not unmap quote, order $lastrealorderid could not be loaded", Zend_Log::WARN, self::LOG_FILE);
682
+ }
683
+ } else {
684
+ Mage::log("Could not unmap quote, no last order defined", Zend_Log::DEBUG, self::LOG_FILE);
685
  }
686
+ return false;
687
  }
688
  }
689
+ /* vim: set noet cindent ts=4 ts=4 sw=4: */
app/code/community/Trustly/Trustly/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Trustly_Trustly>
5
- <version>2.0.8</version>
6
  </Trustly_Trustly>
7
  </modules>
8
  <global>
2
  <config>
3
  <modules>
4
  <Trustly_Trustly>
5
+ <version>2.0.10</version>
6
  </Trustly_Trustly>
7
  </modules>
8
  <global>
app/locale/en_US/Trustly_Trustly.csv CHANGED
@@ -16,9 +16,9 @@
16
  "Failed to communicate with Trustly.","Failed to communicate with Trustly."
17
  "Failed to display the payment method.","Failed to display the payment method."
18
  "Invalid payment.","Invalid payment."
19
- "Invoiced from Trustly payment","Invoiced from Trustly payment"
20
  "Invoice for Trustly OrderId #%s created","Invoice for Trustly OrderId #%s created"
21
  "Invoice: %s","Invoice: %s"
 
22
  "It is free and you don’t have to register. You have to have your login details to your online bank to pay with Trustly.","It is free and you don’t have to register. You have to have your login details to your online bank to pay with Trustly."
23
  "New payment method!","New payment method!"
24
  "Notification id: %s","Notification id: %s"
@@ -26,11 +26,13 @@
26
  "Payment failed, debit received.","Payment failed, debit received."
27
  "Pending payment.","Pending payment."
28
  "Trustly is a payment method that allows you to pay with your online bank account. All you need is your regular online bank credentials. It's fast, easy and secure!", "Trustly is a payment method that allows you to pay with your online bank account. All you need is your regular online bank credentials. It's fast, easy and secure!"
 
29
  "Trustly orderid: %s","Trustly orderid: %s"
30
  "Trustly payment module has not been configured.","Trustly payment module has not been configured."
31
  "Trustly payment","Trustly payment"
32
  "Trustly","Trustly"
 
33
  "Unable to set payment method.","Unable to set payment method."
34
- "What is Trustly?","What is Trustly?"
35
  "Use order currency", "Use order currency"
36
  "Use the currency the user has selected in the store when placing the order rather then the store base currency.", "Use the currency the user has selected in the store when placing the order rather then the store base currency."
 
16
  "Failed to communicate with Trustly.","Failed to communicate with Trustly."
17
  "Failed to display the payment method.","Failed to display the payment method."
18
  "Invalid payment.","Invalid payment."
 
19
  "Invoice for Trustly OrderId #%s created","Invoice for Trustly OrderId #%s created"
20
  "Invoice: %s","Invoice: %s"
21
+ "Invoiced from Trustly payment","Invoiced from Trustly payment"
22
  "It is free and you don’t have to register. You have to have your login details to your online bank to pay with Trustly.","It is free and you don’t have to register. You have to have your login details to your online bank to pay with Trustly."
23
  "New payment method!","New payment method!"
24
  "Notification id: %s","Notification id: %s"
26
  "Payment failed, debit received.","Payment failed, debit received."
27
  "Pending payment.","Pending payment."
28
  "Trustly is a payment method that allows you to pay with your online bank account. All you need is your regular online bank credentials. It's fast, easy and secure!", "Trustly is a payment method that allows you to pay with your online bank account. All you need is your regular online bank credentials. It's fast, easy and secure!"
29
+ "Trustly order has been canceled.", "Trustly order has been canceled."
30
  "Trustly orderid: %s","Trustly orderid: %s"
31
  "Trustly payment module has not been configured.","Trustly payment module has not been configured."
32
  "Trustly payment","Trustly payment"
33
  "Trustly","Trustly"
34
+ "Unable to cancel Trustly order.", "Unable to cancel Trustly order."
35
  "Unable to set payment method.","Unable to set payment method."
 
36
  "Use order currency", "Use order currency"
37
  "Use the currency the user has selected in the store when placing the order rather then the store base currency.", "Use the currency the user has selected in the store when placing the order rather then the store base currency."
38
+ "What is Trustly?","What is Trustly?"
app/locale/es_ES/Trustly_Trustly.csv CHANGED
@@ -16,9 +16,9 @@
16
  "Failed to communicate with Trustly.","Error al comunicarse con Trustly."
17
  "Failed to display the payment method.", "Ha ocurrido un error al mostrar el m&eacute;todo de pago."
18
  "Invalid payment.", "Pago no v&aacute;lido."
19
- "Invoiced from Trustly payment","Facturado con Trustly"
20
  "Invoice for Trustly OrderId #%s created","Factura para la OrderId #%s de Trustly creada"
21
  "Invoice: %s","Factura: %s"
 
22
  "It is free and you don’t have to register. You have to have your login details to your online bank to pay with Trustly.", "Servicio gratuito y sin necesidad de registrarse. Necesitas tus datos de acceso a tu banca online para pagar con Trustly."
23
  "New payment method!", "&iexcl;Nuevo m&eacute;todo de pago!"
24
  "Notification id: %s","Identificador de la notificación: %s"
@@ -26,9 +26,11 @@
26
  "Payment failed, debit received.","Error en el pago, abono recibido."
27
  "Pending payment.","Pago pendiente."
28
  "Trustly is a payment method that allows you to pay with your online bank account. All you need is your regular online bank credentials. It's fast, easy and secure!", "Trustly es el método de pago seguro que te permite pagar directamente desde tu banca online. Todo lo que necesitas son las contraseñas habituales de tu cuenta. ¡Es fácil, rapido y seguro!"
29
- "Trustly","Trustly"
30
  "Trustly orderid: %s","Trustly orderid: %s"
31
- "Trustly payment","Pago con Trustly"
32
  "Trustly payment module has not been configured.","El módulo de pago de Trustly no se ha configurado."
 
 
 
33
  "Unable to set payment method.","No se puede establecer la forma de pago."
34
  "What is Trustly?", "¿Qué es Trustly?"
16
  "Failed to communicate with Trustly.","Error al comunicarse con Trustly."
17
  "Failed to display the payment method.", "Ha ocurrido un error al mostrar el m&eacute;todo de pago."
18
  "Invalid payment.", "Pago no v&aacute;lido."
 
19
  "Invoice for Trustly OrderId #%s created","Factura para la OrderId #%s de Trustly creada"
20
  "Invoice: %s","Factura: %s"
21
+ "Invoiced from Trustly payment","Facturado con Trustly"
22
  "It is free and you don’t have to register. You have to have your login details to your online bank to pay with Trustly.", "Servicio gratuito y sin necesidad de registrarse. Necesitas tus datos de acceso a tu banca online para pagar con Trustly."
23
  "New payment method!", "&iexcl;Nuevo m&eacute;todo de pago!"
24
  "Notification id: %s","Identificador de la notificación: %s"
26
  "Payment failed, debit received.","Error en el pago, abono recibido."
27
  "Pending payment.","Pago pendiente."
28
  "Trustly is a payment method that allows you to pay with your online bank account. All you need is your regular online bank credentials. It's fast, easy and secure!", "Trustly es el método de pago seguro que te permite pagar directamente desde tu banca online. Todo lo que necesitas son las contraseñas habituales de tu cuenta. ¡Es fácil, rapido y seguro!"
29
+ "Trustly order has been canceled.", "Para Trustly ha sido cancelada."
30
  "Trustly orderid: %s","Trustly orderid: %s"
 
31
  "Trustly payment module has not been configured.","El módulo de pago de Trustly no se ha configurado."
32
+ "Trustly payment","Pago con Trustly"
33
+ "Trustly","Trustly"
34
+ "Unable to cancel Trustly order.", "No puede cancelar la orden Trustly."
35
  "Unable to set payment method.","No se puede establecer la forma de pago."
36
  "What is Trustly?", "¿Qué es Trustly?"
app/locale/sv_SE/Trustly_Trustly.csv CHANGED
@@ -16,9 +16,9 @@
16
  "Failed to communicate with Trustly.", "Misslyckades att kommunicera med Trustly."
17
  "Failed to display the payment method.", "Kunde inte visa betalningsmetoden."
18
  "Invalid payment.", "Ogiltig betalning"
19
- "Invoiced from Trustly payment", "Fakturerad från Trustly betalning."
20
  "Invoice for Trustly OrderId #%s created", "Faktura för Trustly OrderId #%s skapad"
21
  "Invoice: %s", "Faktura: %s"
 
22
  "It is free and you don’t have to register. You have to have your login details to your online bank to pay with Trustly.", "Det är gratis och du behöver inte registrera dig. Du måste ha dina inloggningsuppgifter till din Internetbank för att betala med Trustly."
23
  "New payment method!", "Ny betalnings metod!"
24
  "Notification id: %s", "Notifieringsid: %s"
@@ -26,11 +26,13 @@
26
  "Payment failed, debit received.", "Betalningen misslyckades, debitering mottagen."
27
  "Pending payment.", "Inkommande betalning."
28
  "Trustly is a payment method that allows you to pay with your online bank account. All you need is your regular online bank credentials. It's fast, easy and secure!", "Trustly är en betalningsmetod som gör det möjligt att betala med din internetbank. Allt du behöver är dina vanliga inloggningsuppgifter. Det är snabbt, enkelt och säkert!"
 
29
  "Trustly orderid: %s", "Trustly OrderId: %s"
30
  "Trustly payment module has not been configured.","Betalningsmodulen för Trustly har inte blivit konfigurerad."
31
  "Trustly payment", "Trustly betalning"
32
  "Trustly", "Trustly"
 
33
  "Unable to set payment method.", "Kan inte aktivera betalningsmetoden"
34
- "What is Trustly?", "Vad är Trustly?"
35
  "Use order currency", "Använd orderns valuta"
36
  "Use the currency the user has selected in the store when placing the order rather then the store base currency.", "Använd valutan som användaren valt att se priserna i istället för butikens bas-valuta när ordern skapas."
 
16
  "Failed to communicate with Trustly.", "Misslyckades att kommunicera med Trustly."
17
  "Failed to display the payment method.", "Kunde inte visa betalningsmetoden."
18
  "Invalid payment.", "Ogiltig betalning"
 
19
  "Invoice for Trustly OrderId #%s created", "Faktura för Trustly OrderId #%s skapad"
20
  "Invoice: %s", "Faktura: %s"
21
+ "Invoiced from Trustly payment", "Fakturerad från Trustly betalning."
22
  "It is free and you don’t have to register. You have to have your login details to your online bank to pay with Trustly.", "Det är gratis och du behöver inte registrera dig. Du måste ha dina inloggningsuppgifter till din Internetbank för att betala med Trustly."
23
  "New payment method!", "Ny betalnings metod!"
24
  "Notification id: %s", "Notifieringsid: %s"
26
  "Payment failed, debit received.", "Betalningen misslyckades, debitering mottagen."
27
  "Pending payment.", "Inkommande betalning."
28
  "Trustly is a payment method that allows you to pay with your online bank account. All you need is your regular online bank credentials. It's fast, easy and secure!", "Trustly är en betalningsmetod som gör det möjligt att betala med din internetbank. Allt du behöver är dina vanliga inloggningsuppgifter. Det är snabbt, enkelt och säkert!"
29
+ "Trustly order has been canceled.", "Trustly betalningen har avbrutits."
30
  "Trustly orderid: %s", "Trustly OrderId: %s"
31
  "Trustly payment module has not been configured.","Betalningsmodulen för Trustly har inte blivit konfigurerad."
32
  "Trustly payment", "Trustly betalning"
33
  "Trustly", "Trustly"
34
+ "Unable to cancel Trustly order.", "Kunde inte avbryta Trustly betalningen."
35
  "Unable to set payment method.", "Kan inte aktivera betalningsmetoden"
 
36
  "Use order currency", "Använd orderns valuta"
37
  "Use the currency the user has selected in the store when placing the order rather then the store base currency.", "Använd valutan som användaren valt att se priserna i istället för butikens bas-valuta när ordern skapas."
38
+ "What is Trustly?", "Vad är Trustly?"
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Trustly</name>
4
- <version>2.0.8</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.gnu.org/copyleft/gpl.html">GPL 3</license>
7
  <channel>community</channel>
@@ -16,18 +16,18 @@
16
  <email>info@trustly.com</email>
17
  </author>
18
  </authors>
19
- <date>2014-12-01</date>
20
- <time>11:19:54</time>
21
  <contents>
22
  <target name="magelocale">
23
  <dir name="da_DK">
24
  <file name="Trustly_Trustly.csv" hash="bdd0d2cbbffee4ab2f268e90de6178a4"/>
25
  </dir>
26
  <dir name="en_US">
27
- <file name="Trustly_Trustly.csv" hash="a6b8b1dae6a076e12068dceeff6d2d6a"/>
28
  </dir>
29
  <dir name="es_ES">
30
- <file name="Trustly_Trustly.csv" hash="37f85a0f00431a0d4095b8e29faaf7fb"/>
31
  </dir>
32
  <dir name="et_EE">
33
  <file name="Trustly_Trustly.csv" hash="5ac7fbc6a05c01ae4d87c3116b828c11"/>
@@ -39,7 +39,7 @@
39
  <file name="Trustly_Trustly.csv" hash="4f05bfa243336c0622bb76f8d3e190e9"/>
40
  </dir>
41
  <dir name="sv_SE">
42
- <file name="Trustly_Trustly.csv" hash="6f3eb2cddbb6d34a4ef0372cbc7d664b"/>
43
  </dir>
44
  </target>
45
  <target name="magecommunity">
@@ -48,27 +48,27 @@
48
  <dir name="Block">
49
  <dir name="System">
50
  <dir name="Config">
51
- <file name="About.php" hash="ef187a0190cd508950103a80b80469ab"/>
52
  </dir>
53
  </dir>
54
- <file name="Form.php" hash="8694b30c33e2e9fa096eaf1b6d2eb221"/>
55
- <file name="Redirect.php" hash="33bf3038c097080b4a723babd09a743f"/>
56
  </dir>
57
  <dir name="Helper">
58
- <file name="Data.php" hash="73dfcf422720db976dc260e009cf3b80"/>
59
  </dir>
60
  <dir name="Model">
61
  <dir name="Mysql4">
62
- <file name="Ordermappings.php" hash="9a20e6607ef45773b1fd3beca10dc47c"/>
63
  </dir>
64
- <file name="Ordermappings.php" hash="b2871d0594151a48e329bc950d09ab76"/>
65
- <file name="Standard.php" hash="50ff94700a51c7ad89be88f1b99bfc76"/>
66
  </dir>
67
  <dir name="controllers">
68
- <file name="PaymentController.php" hash="a3dfc93ea5209f7fa8cb73876ae5b32d"/>
69
  </dir>
70
  <dir name="etc">
71
- <file name="config.xml" hash="d4f5ca9a2f47ea0b58b77d653512ed0d"/>
72
  <file name="system.xml" hash="d92061e410e4e923eb39fa59f2e00927"/>
73
  </dir>
74
  <dir name="lib">
@@ -113,8 +113,6 @@
113
  <file name="Trustly_Trustly.xml" hash="65276cdb908021ff6c08b388c6a23457"/>
114
  </dir>
115
  </target>
116
- <target name="mageskin">
117
- </target>
118
  <target name="magedesign">
119
  <dir name="frontend">
120
  <dir name="base">
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Trustly</name>
4
+ <version>2.0.10</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.gnu.org/copyleft/gpl.html">GPL 3</license>
7
  <channel>community</channel>
16
  <email>info@trustly.com</email>
17
  </author>
18
  </authors>
19
+ <date>2015-02-05</date>
20
+ <time>11:26:30</time>
21
  <contents>
22
  <target name="magelocale">
23
  <dir name="da_DK">
24
  <file name="Trustly_Trustly.csv" hash="bdd0d2cbbffee4ab2f268e90de6178a4"/>
25
  </dir>
26
  <dir name="en_US">
27
+ <file name="Trustly_Trustly.csv" hash="4ecd6f9846463c1c63b38a075dead52a"/>
28
  </dir>
29
  <dir name="es_ES">
30
+ <file name="Trustly_Trustly.csv" hash="151590632c51de093dc27a46a0003581"/>
31
  </dir>
32
  <dir name="et_EE">
33
  <file name="Trustly_Trustly.csv" hash="5ac7fbc6a05c01ae4d87c3116b828c11"/>
39
  <file name="Trustly_Trustly.csv" hash="4f05bfa243336c0622bb76f8d3e190e9"/>
40
  </dir>
41
  <dir name="sv_SE">
42
+ <file name="Trustly_Trustly.csv" hash="14fa4d162aa95aa2614c9eb8122d0546"/>
43
  </dir>
44
  </target>
45
  <target name="magecommunity">
48
  <dir name="Block">
49
  <dir name="System">
50
  <dir name="Config">
51
+ <file name="About.php" hash="8bdfd609cc2c1a542e1013f9ea12242a"/>
52
  </dir>
53
  </dir>
54
+ <file name="Form.php" hash="5c51365bdb83656edd548bd49535b1f5"/>
55
+ <file name="Redirect.php" hash="510806d4ce26ca99ac107837fdd00f56"/>
56
  </dir>
57
  <dir name="Helper">
58
+ <file name="Data.php" hash="cbdcab091cc8f9308f1a61a9d5580f86"/>
59
  </dir>
60
  <dir name="Model">
61
  <dir name="Mysql4">
62
+ <file name="Ordermappings.php" hash="3e15a9a87af7239a42a750c4343ceb54"/>
63
  </dir>
64
+ <file name="Ordermappings.php" hash="8e3426d5454803ab2a212ff5c086dcdf"/>
65
+ <file name="Standard.php" hash="7fc3027a735a544f1bcd0cd65a745d88"/>
66
  </dir>
67
  <dir name="controllers">
68
+ <file name="PaymentController.php" hash="89eca8a5d026166d9faa56f48a5772a1"/>
69
  </dir>
70
  <dir name="etc">
71
+ <file name="config.xml" hash="b5102728ff4264db2e24f975bfe840aa"/>
72
  <file name="system.xml" hash="d92061e410e4e923eb39fa59f2e00927"/>
73
  </dir>
74
  <dir name="lib">
113
  <file name="Trustly_Trustly.xml" hash="65276cdb908021ff6c08b388c6a23457"/>
114
  </dir>
115
  </target>
 
 
116
  <target name="magedesign">
117
  <dir name="frontend">
118
  <dir name="base">