@@ -8,7 +8,6 @@ class Devopensource_Redsys_IndexController extends Mage_Core_Controller_Front_Ac
88 public function redirectAction ()
99 {
1010 $ this ->helper = Mage::helper ('devopensource_redsys ' );
11-
1211 $ orderId = Mage::getSingleton ('checkout/session ' )->getLastRealOrderId ();
1312 $ _order = Mage::getModel ('sales/order ' )->loadByIncrementId ($ orderId );
1413
@@ -25,6 +24,8 @@ public function redirectAction()
2524
2625 $ this ->helper ->stateInTpv ($ _order );
2726
27+ Mage::dispatchEvent ('redsys_redirect ' , array ('order ' => $ _order ));
28+
2829 $ transaction_amount = number_format ($ _order ->getTotalDue (), 2 , '' , '' );
2930 $ amount = (float )$ transaction_amount ;
3031
@@ -120,6 +121,8 @@ public function callbackAction()
120121 $ order ->sendNewOrderEmail ();
121122 $ this ->helper ->createInvoice ($ order );
122123 $ this ->helper ->createTransaction ($ order ,$ decodeData );
124+
125+ Mage::dispatchEvent ('redsys_payment_accepted ' , array ('order ' => $ order ));
123126 } catch (Exception $ e ) {
124127 $ order ->addStatusHistoryComment ($ this ->__ ("TPV Error: %s " ,$ e ->getMessage ()), false );
125128 $ order ->save ();
@@ -147,6 +150,8 @@ public function callbackAction()
147150
148151 public function cancelAction ()
149152 {
153+ $ this ->helper = Mage::helper ('devopensource_redsys ' );
154+
150155 if (!empty ($ _GET ) && Mage::getStoreConfig ('payment/redsys/display_error_clients ' ,Mage::app ()->getStore ()))
151156 {
152157 $ this ->helper = Mage::helper ('devopensource_redsys ' );
@@ -164,22 +169,35 @@ public function cancelAction()
164169 $ responsecode = intval ($ response );
165170 $ error = $ this ->helper ->comentarioReponse ($ responsecode );
166171 }
172+
167173 }
168174
169175 if (!isset ($ error )){
170176 $ error = $ this ->__ ('Denied transaction from Redsys. ' );
171177 }
172178
173- $ this ->helper = Mage::helper ('devopensource_redsys ' );
174179 $ session = Mage::getSingleton ('checkout/session ' );
180+ $ _orderIncId = $ session ->getData ('last_real_order_id ' );
181+ $ _order = Mage::getModel ('sales/order ' )->loadByIncrementId ($ _orderIncId );
182+
183+ if (Mage::getStoreConfig ('payment/redsys/notify_by_email ' , Mage::app ()->getStore ())){
184+ $ this ->helper ->notifyEmailCustomer ($ this ->__ ('Cancelled payment order %s from the payment gateway TPV. ' , '# ' .$ _orderIncId ), $ _order ->getCustomerEmail ());
185+ }
186+
187+ $ this ->helper ->notifyEmailAdmin ($ this ->__ ('Cancelled payment order %s from the payment gateway TPV. ' , '# ' .$ _orderIncId ), $ _order ->getCustomerEmail ());
188+
189+ Mage::dispatchEvent ('redsys_payment_cancel ' , array ('session ' => $ session ));
190+
175191 $ this ->helper ->recoveryCart ();
176192 $ session ->addError ($ error );
193+
177194 $ this ->_redirect ('checkout/cart ' );
178195 }
179196
180197 public function successAction ()
181198 {
182199 $ session = Mage::getSingleton ('checkout/session ' );
200+ Mage::dispatchEvent ('redsys_payment_success ' , array ('session ' => $ session ));
183201 $ session ->addsuccess ($ this ->__ ('Authorized transaction ' ));
184202 $ this ->_redirect ('checkout/onepage/success ' );
185203 }
0 commit comments