Cardsave_Cardsaveonlinepayments - Version 1.9.0

Version Notes

Built-in code versioning compatible with Magento 1.3 and 1.4.
Compatible with the following versions:
1.3.2.4
1.3.3.0
1.4.1.0
1.4.1.1
Secure URL link fix for SSL certified stores.
Template fix base/default for version 1.4

Download this release

Release Info

Developer Magento Core Team
Extension Cardsave_Cardsaveonlinepayments
Version 1.9.0
Comparing to
See all releases


Code changes from version 1.8.6 to 1.9.0

app/code/local/Cardsave/Cardsaveonlinepayments/Model/Common/PaymentFormHelper.php CHANGED
@@ -507,13 +507,14 @@
507
  return $boMatch;
508
  }
509
 
 
510
  /**
511
  * Transform the string Magento version number into an integer ready for comparison
512
  *
513
  * @param unknown_type $magentoVersion
514
  * @return unknown
515
  */
516
- public static function getVersion($magentoVersion)
517
  {
518
  //$nVersion = Mage::getVersion();
519
  $pattern = '/[^\d]/';
@@ -526,6 +527,6 @@
526
  $magentoVersion = (int)$magentoVersion;
527
 
528
  return $magentoVersion;
529
- }
530
  }
531
  ?>
507
  return $boMatch;
508
  }
509
 
510
+ // TODO : REMOVE
511
  /**
512
  * Transform the string Magento version number into an integer ready for comparison
513
  *
514
  * @param unknown_type $magentoVersion
515
  * @return unknown
516
  */
517
+ /*public static function getVersion($magentoVersion)
518
  {
519
  //$nVersion = Mage::getVersion();
520
  $pattern = '/[^\d]/';
527
  $magentoVersion = (int)$magentoVersion;
528
 
529
  return $magentoVersion;
530
+ }*/
531
  }
532
  ?>
app/code/local/Cardsave/Cardsaveonlinepayments/Model/Direct.php CHANGED
@@ -94,6 +94,7 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
94
  $error = false;
95
  $session = Mage::getSingleton('checkout/session');
96
  $mode = $this->getConfigData('mode');
 
97
 
98
  if($amount <= 0)
99
  {
@@ -161,6 +162,13 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
161
  {
162
  Mage::throwException($error);
163
  }
 
 
 
 
 
 
 
164
 
165
  return $this;
166
  }
@@ -176,6 +184,7 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
176
  {
177
  $error = '';
178
  $session = Mage::getSingleton('checkout/session');
 
179
 
180
  $MerchantID = $this->getConfigData('merchantid');
181
  $Password = $this->getConfigData('password');
@@ -329,10 +338,13 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
329
 
330
  Mage::getSingleton('checkout/session')->setMd($szCrossReference)
331
  ->setAcsurl($szACSURL)
332
- ->setPareq($szPaReq)
333
- ->setRedirectionmethod('_run3DSecureTransaction');
334
 
335
- $order->setIsThreeDSecurePending(true);
 
 
 
 
336
  break;
337
  case 5:
338
  // status code of 5 - means transaction declined
@@ -385,6 +397,13 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
385
  ->setCcApproval('FAIL')
386
  ->setAdditionalData($cdtrCardDetailsTransactionResult->getMessage());
387
  }
 
 
 
 
 
 
 
388
 
389
  return $error;
390
  }
@@ -398,6 +417,7 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
398
  public function _runHostedPaymentTransaction(Varien_Object $payment, $amount)
399
  {
400
  $session = Mage::getSingleton('checkout/session');
 
401
 
402
  $szMerchantID = $this->getConfigData('merchantid');
403
  $szPassword = $this->getConfigData('password');
@@ -550,10 +570,13 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
550
  ->setPaymentformdisplaysresult($boPaymentFormDisplaysResult)
551
  ->setServerresulturlcookievariables($szServerResultURLCookieVariables)
552
  ->setServerresulturlformvariables($szServerResultURLFormVariables)
553
- ->setServerresulturlquerystringvariables($szServerResultURLQueryStringVariables)
554
- ->setRedirectionmethod('_runRedirectedPaymentComplete');
555
-
556
- $payment->getOrder()->setIsHostedPaymentPending(true);
 
 
 
557
  }
558
 
559
  /**
@@ -566,6 +589,7 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
566
  {
567
  $GLOBALS['m_boPayInvoice'] = false;
568
  $payment->setIsTransactionPending(true);
 
569
 
570
  $szMerchantID = $this->getConfigData('merchantid');
571
  $szPassword = $this->getConfigData('password');
@@ -650,10 +674,13 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
650
  ->setStartdatemonth($szStartDateMonth)
651
  ->setStartdateyear($szStartDateYear)
652
  ->setIssuenumber($szIssueNumber)
653
- ->setCv2($szCV2)
654
- ->setRedirectionmethod('_runRedirectedPaymentComplete');
655
-
656
- $payment->getOrder()->setIsHostedPaymentPending(true);
 
 
 
657
  }
658
 
659
  /**
@@ -671,6 +698,7 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
671
  $order = $payment->getOrder();
672
  $szOrderID = $payment->getOrder()->increment_id;
673
  $session = Mage::getSingleton('checkout/session');
 
674
 
675
  $MerchantID = $this->getConfigData('merchantid');
676
  $Password = $this->getConfigData('password');
@@ -763,6 +791,12 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
763
  {
764
  $payment->setStatus(self::STATUS_APPROVED)
765
  ->setAdditionalData($message);
 
 
 
 
 
 
766
  }
767
 
768
  return $this;
@@ -773,6 +807,7 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
773
  $error = false;
774
  $message;
775
  $session = Mage::getSingleton('checkout/session');
 
776
 
777
  if($boIsHostedPaymentAction == true)
778
  {
@@ -815,6 +850,12 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
815
  {
816
  $payment->setStatus(self::STATUS_APPROVED)
817
  ->setAdditionalData($message);
 
 
 
 
 
 
818
  }
819
 
820
  return $this;
@@ -901,4 +942,25 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
901
 
902
  return $szISO3Code;
903
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
904
  }
94
  $error = false;
95
  $session = Mage::getSingleton('checkout/session');
96
  $mode = $this->getConfigData('mode');
97
+ $nVersion = $this->getVersion();
98
 
99
  if($amount <= 0)
100
  {
162
  {
163
  Mage::throwException($error);
164
  }
165
+ else
166
+ {
167
+ if($nVersion == 1324 || $nVersion == 1330)
168
+ {
169
+ $payment->setIsInvoicePaid(true);
170
+ }
171
+ }
172
 
173
  return $this;
174
  }
184
  {
185
  $error = '';
186
  $session = Mage::getSingleton('checkout/session');
187
+ $nVersion = $this->getVersion();
188
 
189
  $MerchantID = $this->getConfigData('merchantid');
190
  $Password = $this->getConfigData('password');
338
 
339
  Mage::getSingleton('checkout/session')->setMd($szCrossReference)
340
  ->setAcsurl($szACSURL)
341
+ ->setPareq($szPaReq);
 
342
 
343
+ if($nVersion >= 1410)
344
+ {
345
+ Mage::getSingleton('checkout/session')->setRedirectionmethod('_run3DSecureTransaction');
346
+ $order->setIsThreeDSecurePending(true);
347
+ }
348
  break;
349
  case 5:
350
  // status code of 5 - means transaction declined
397
  ->setCcApproval('FAIL')
398
  ->setAdditionalData($cdtrCardDetailsTransactionResult->getMessage());
399
  }
400
+ else
401
+ {
402
+ if($nVersion == 1324 || $nVersion == 1330)
403
+ {
404
+ $payment->setIsInvoicePaid(true);
405
+ }
406
+ }
407
 
408
  return $error;
409
  }
417
  public function _runHostedPaymentTransaction(Varien_Object $payment, $amount)
418
  {
419
  $session = Mage::getSingleton('checkout/session');
420
+ $nVersion = $this->getVersion();
421
 
422
  $szMerchantID = $this->getConfigData('merchantid');
423
  $szPassword = $this->getConfigData('password');
570
  ->setPaymentformdisplaysresult($boPaymentFormDisplaysResult)
571
  ->setServerresulturlcookievariables($szServerResultURLCookieVariables)
572
  ->setServerresulturlformvariables($szServerResultURLFormVariables)
573
+ ->setServerresulturlquerystringvariables($szServerResultURLQueryStringVariables);
574
+
575
+ if($nVersion >= 1410)
576
+ {
577
+ $session->setRedirectionmethod('_runRedirectedPaymentComplete');
578
+ $payment->getOrder()->setIsHostedPaymentPending(true);
579
+ }
580
  }
581
 
582
  /**
589
  {
590
  $GLOBALS['m_boPayInvoice'] = false;
591
  $payment->setIsTransactionPending(true);
592
+ $nVersion = $this->getVersion();
593
 
594
  $szMerchantID = $this->getConfigData('merchantid');
595
  $szPassword = $this->getConfigData('password');
674
  ->setStartdatemonth($szStartDateMonth)
675
  ->setStartdateyear($szStartDateYear)
676
  ->setIssuenumber($szIssueNumber)
677
+ ->setCv2($szCV2);
678
+
679
+ if($nVersion >= 1410)
680
+ {
681
+ Mage::getSingleton('checkout/session')->setRedirectionmethod('_runRedirectedPaymentComplete');
682
+ $payment->getOrder()->setIsHostedPaymentPending(true);
683
+ }
684
  }
685
 
686
  /**
698
  $order = $payment->getOrder();
699
  $szOrderID = $payment->getOrder()->increment_id;
700
  $session = Mage::getSingleton('checkout/session');
701
+ $nVersion = $this->getVersion();
702
 
703
  $MerchantID = $this->getConfigData('merchantid');
704
  $Password = $this->getConfigData('password');
791
  {
792
  $payment->setStatus(self::STATUS_APPROVED)
793
  ->setAdditionalData($message);
794
+
795
+ if($nVersion == 1324 || $nVersion == 1330)
796
+ {
797
+ $payment->setIsInvoicePaid(true);
798
+ Mage::getSingleton('core/session')->addSuccess($message);
799
+ }
800
  }
801
 
802
  return $this;
807
  $error = false;
808
  $message;
809
  $session = Mage::getSingleton('checkout/session');
810
+ $nVersion = $this->getVersion();
811
 
812
  if($boIsHostedPaymentAction == true)
813
  {
850
  {
851
  $payment->setStatus(self::STATUS_APPROVED)
852
  ->setAdditionalData($message);
853
+
854
+ if($nVersion == 1324 || $nVersion ==1330)
855
+ {
856
+ $payment->setIsInvoicePaid(true);
857
+ Mage::getSingleton('core/session')->addSuccess($message);
858
+ }
859
  }
860
 
861
  return $this;
942
 
943
  return $szISO3Code;
944
  }
945
+
946
+ /**
947
+ * Transform the string Magento version number into an integer ready for comparison
948
+ *
949
+ * @param unknown_type $magentoVersion
950
+ * @return unknown
951
+ */
952
+ public function getVersion()
953
+ {
954
+ $magentoVersion = Mage::getVersion();
955
+ $pattern = '/[^\d]/';
956
+ $magentoVersion = preg_replace($pattern, '', $magentoVersion);
957
+
958
+ while(strlen($magentoVersion) < 4)
959
+ {
960
+ $magentoVersion .= '0';
961
+ }
962
+ $magentoVersion = (int)$magentoVersion;
963
+
964
+ return $magentoVersion;
965
+ }
966
  }
app/code/local/Cardsave/Cardsaveonlinepayments/controllers/PaymentController.php CHANGED
@@ -42,11 +42,16 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
42
  */
43
  public function redirectAction()
44
  {
45
- // need to re-add the ordered item quantity to stock as per not completed 3DS transaction
46
- if(!Mage::getSingleton('checkout/session')->getPares())
 
47
  {
48
- $order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
49
- $this->_addOrderedItemsToStock($order);
 
 
 
 
50
  }
51
  $this->getResponse()->setBody($this->getLayout()->createBlock('cardsaveonlinepayments/redirect')->toHtml());
52
  }
@@ -57,13 +62,18 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
57
  */
58
  public function threedsecureAction()
59
  {
60
- $mode = Mage::getModel('cardsaveonlinepayments/direct')->getConfigData('mode');
61
 
62
- // need to re-add the ordered item quantity to stock as per not completed 3DS transaction
63
- if($mode != Cardsave_Cardsaveonlinepayments_Model_Source_PaymentMode::PAYMENT_MODE_TRANSPARENT_REDIRECT)
64
  {
65
- $order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
66
- $this->_addOrderedItemsToStock($order);
 
 
 
 
 
 
67
  }
68
 
69
  $this->getResponse()->setBody($this->getLayout()->createBlock('cardsaveonlinepayments/threedsecure')->toHtml());
@@ -81,6 +91,7 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
81
  $checkout = Mage::getSingleton('checkout/type_onepage');
82
  $session = Mage::getSingleton('checkout/session');
83
  $szPaymentProcessorResponse = '';
 
84
 
85
  try
86
  {
@@ -118,18 +129,28 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
118
  $szMessage .= '<br/>'.$szPaymentProcessorResponse;
119
  }
120
 
121
- if($order)
122
- {
123
- $orderState = 'pending_payment';
124
- $orderStatus = 'cardsave_failed_threed_secure';
125
- $order->setCustomerNote(Mage::helper('cardsaveonlinepayments')->__('3D Secure Authentication Failed'));
126
- $order->setState($orderState, $orderStatus, $szPaymentProcessorResponse, false);
127
- $order->save();
128
- }
129
- $this->_clearSessionVariables();
130
-
 
 
 
 
 
 
 
 
 
 
 
131
  // report out an fatal error
132
- Mage::getSingleton('core/session')->addError($szMessage);
133
  $this->_redirect('checkout/onepage/failure');
134
  }
135
  else
@@ -143,13 +164,20 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
143
  $order->sendNewOrderEmail();
144
  }
145
 
146
- $this->_subtractOrderedItemsFromStock($order);
147
- $this->_updateInvoices($order, $szPaymentProcessorResponse);
148
-
149
- if($szPaymentProcessorResponse != '')
150
  {
151
- Mage::getSingleton('core/session')->addSuccess($szPaymentProcessorResponse);
 
 
 
 
 
 
 
 
 
152
  }
 
153
  $this->_redirect('checkout/onepage/success', array('_secure' => true));
154
  }
155
  }
@@ -169,6 +197,7 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
169
  $szPaymentProcessorResponse = '';
170
  $order = Mage::getModel('sales/order');
171
  $order->load(Mage::getSingleton('checkout/session')->getLastOrderId());
 
172
 
173
  try
174
  {
@@ -231,17 +260,27 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
231
  $szNotificationMessage = $szNotificationMessage.'<br/>'.$szPaymentProcessorResponse;
232
  }
233
 
234
- if($order)
235
- {
236
- $orderState = 'pending_payment';
237
- $orderStatus = 'cardsave_failed_hosted_payment';
238
- $order->setCustomerNote(Mage::helper('cardsaveonlinepayments')->__('Hosted Payment Failed'));
239
- $order->setState($orderState, $orderStatus, $szPaymentProcessorResponse, false);
240
- $order->save();
241
- }
 
 
 
 
 
 
 
 
 
 
 
242
 
243
  $this->_clearSessionVariables();
244
- Mage::getSingleton('core/session')->addError($szNotificationMessage);
245
  $this->_redirect('checkout/onepage/failure');
246
  }
247
  else
@@ -255,12 +294,18 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
255
  $order->sendNewOrderEmail();
256
  }
257
 
258
- $this->_subtractOrderedItemsFromStock($order);
259
- $this->_updateInvoices($order, $szPaymentProcessorResponse);
 
 
 
260
 
261
- if($szPaymentProcessorResponse != '')
262
  {
263
- Mage::getSingleton('core/session')->addSuccess($szPaymentProcessorResponse);
 
 
 
264
  }
265
  $this->_redirect('checkout/onepage/success', array('_secure' => true));
266
  }
@@ -277,6 +322,7 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
277
  $checkout = Mage::getSingleton('checkout/type_onepage');
278
  $szOrderID = $this->getRequest()->getPost('OrderID');
279
  $szMessage = $this->getRequest()->getPost('Message');
 
280
 
281
  try
282
  {
@@ -318,8 +364,12 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
318
  if($this->getRequest()->getPost('StatusCode') == '0')
319
  {
320
  Mage::getSingleton('checkout/session')->clear();
321
- $this->_subtractOrderedItemsFromStock($order);
322
- $this->_updateInvoices($order, $szMessage);
 
 
 
 
323
  }
324
 
325
  $this->getResponse()->setBody('StatusCode=0');
@@ -352,6 +402,7 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
352
  $nStartIndex = strpos($szURLVariableString, "?");
353
  $order = Mage::getModel('sales/order');
354
  $order->load(Mage::getSingleton('checkout/session')->getLastOrderId());
 
355
 
356
  if(!is_int($nStartIndex))
357
  {
@@ -443,17 +494,27 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
443
 
444
  if($szErrorMessage)
445
  {
446
- if($order)
 
 
 
 
 
 
 
 
 
 
 
447
  {
448
- $orderState = 'pending_payment';
449
- $orderStatus = 'cardsave_failed_hosted_payment';
450
- $order->setCustomerNote(Mage::helper('cardsaveonlinepayments')->__('Hosted Payment Failed'));
451
- $order->setState($orderState, $orderStatus, $szErrorMessage, false);
452
- $order->save();
453
  }
454
 
455
  $this->_clearSessionVariables();
456
- Mage::getSingleton('core/session')->addError($szErrorMessage);
457
  $this->_redirect('checkout/onepage/failure');
458
  }
459
  else
@@ -467,10 +528,16 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
467
  $order->sendNewOrderEmail();
468
  }
469
 
470
- $this->_subtractOrderedItemsFromStock($order);
471
- $this->_updateInvoices($order, $szMessage);
 
 
 
472
 
473
- Mage::getSingleton('core/session')->addSuccess('Payment Processor Response: '.$szMessage);
 
 
 
474
  $this->_redirect('checkout/onepage/success', array('_secure' => true));
475
  }
476
  }
@@ -484,6 +551,7 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
484
  $model = Mage::getModel('cardsaveonlinepayments/direct');
485
  $order = Mage::getModel('sales/order');
486
  $order->load(Mage::getSingleton('checkout/session')->getLastOrderId());
 
487
 
488
  try
489
  {
@@ -517,17 +585,27 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
517
  $error = Cardsave_Cardsaveonlinepayments_Model_Common_GlobalErrors::ERROR_260;
518
  Mage::logException($exc);
519
 
520
- if($order)
521
- {
522
- $orderState = 'pending_payment';
523
- $orderStatus = 'cardsave_failed_hosted_payment';
524
- $order->setCustomerNote(Mage::helper('cardsaveonlinepayments')->__('Transparent Redirect Payment Failed'));
525
- $order->setState($orderState, $orderStatus, $exc->getMessage(), false);
526
- $order->save();
527
- }
 
 
 
 
 
 
 
 
 
 
 
528
 
529
  $this->_clearSessionVariables();
530
- Mage::getSingleton('core/session')->addError($error);
531
  $this->_redirect('checkout/onepage/failure');
532
  }
533
  }
@@ -608,6 +686,7 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
608
  $szPaymentProcessorResponse = '';
609
  $order = Mage::getModel('sales/order');
610
  $order->load(Mage::getSingleton('checkout/session')->getLastOrderId());
 
611
 
612
  try
613
  {
@@ -665,17 +744,27 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
665
  $szNotificationMessage = $szNotificationMessage.'<br/>'.$szPaymentProcessorResponse;
666
  }
667
 
668
- if($order)
669
- {
670
- $orderState = 'pending_payment';
671
- $orderStatus = 'cardsave_failed_hosted_payment';
672
- $order->setCustomerNote(Mage::helper('cardsaveonlinepayments')->__('Transparent Redirect Payment Failed'));
673
- $order->setState($orderState, $orderStatus, $szPaymentProcessorResponse, false);
674
- $order->save();
675
- }
 
 
 
 
 
 
 
 
 
 
 
676
 
677
  $this->_clearSessionVariables();
678
- Mage::getSingleton('core/session')->addError($szNotificationMessage);
679
  $this->_redirect('checkout/onepage/failure');
680
  }
681
  else
@@ -688,12 +777,18 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
688
  $order->sendNewOrderEmail();
689
  }
690
 
691
- $this->_subtractOrderedItemsFromStock($order);
692
- $this->_updateInvoices($order, $szPaymentProcessorResponse);
 
 
 
693
 
694
- if($szPaymentProcessorResponse != '')
695
  {
696
- Mage::getSingleton('core/session')->addSuccess($szPaymentProcessorResponse);
 
 
 
697
  }
698
  $this->_redirect('checkout/onepage/success', array('_secure' => true));
699
  }
@@ -706,7 +801,7 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
706
  */
707
  private function _subtractOrderedItemsFromStock($order)
708
  {
709
- $nVersion = CSV_PaymentFormHelper::getVersion(Mage::getVersion());
710
  $isCustomStockManagementEnabled = Mage::getModel('cardsaveonlinepayments/direct')->getConfigData('customstockmanagementenabled');
711
 
712
  if($nVersion >= 1410 &&
@@ -738,7 +833,7 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
738
  */
739
  private function _addOrderedItemsToStock($order)
740
  {
741
- $nVersion = CSV_PaymentFormHelper::getVersion(Mage::getVersion());
742
  $isCustomStockManagementEnabled = Mage::getModel('cardsaveonlinepayments/direct')->getConfigData('customstockmanagementenabled');
743
 
744
  if($nVersion >= 1410 &&
42
  */
43
  public function redirectAction()
44
  {
45
+ $nVersion = Mage::getModel('cardsaveonlinepayments/direct')->getVersion();
46
+
47
+ if($nVersion >= 1410)
48
  {
49
+ // need to re-add the ordered item quantity to stock as per not completed 3DS transaction
50
+ if(!Mage::getSingleton('checkout/session')->getPares())
51
+ {
52
+ $order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
53
+ $this->_addOrderedItemsToStock($order);
54
+ }
55
  }
56
  $this->getResponse()->setBody($this->getLayout()->createBlock('cardsaveonlinepayments/redirect')->toHtml());
57
  }
62
  */
63
  public function threedsecureAction()
64
  {
65
+ $nVersion = Mage::getModel('cardsaveonlinepayments/direct')->getVersion();
66
 
67
+ if($nVersion >= 1410)
 
68
  {
69
+ $mode = Mage::getModel('cardsaveonlinepayments/direct')->getConfigData('mode');
70
+
71
+ // need to re-add the ordered item quantity to stock as per not completed 3DS transaction
72
+ if($mode != Cardsave_Cardsaveonlinepayments_Model_Source_PaymentMode::PAYMENT_MODE_TRANSPARENT_REDIRECT)
73
+ {
74
+ $order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
75
+ $this->_addOrderedItemsToStock($order);
76
+ }
77
  }
78
 
79
  $this->getResponse()->setBody($this->getLayout()->createBlock('cardsaveonlinepayments/threedsecure')->toHtml());
91
  $checkout = Mage::getSingleton('checkout/type_onepage');
92
  $session = Mage::getSingleton('checkout/session');
93
  $szPaymentProcessorResponse = '';
94
+ $nVersion = Mage::getModel('cardsaveonlinepayments/direct')->getVersion();
95
 
96
  try
97
  {
129
  $szMessage .= '<br/>'.$szPaymentProcessorResponse;
130
  }
131
 
132
+ if($nVersion >= 1410)
133
+ {
134
+ if($order)
135
+ {
136
+ $orderState = 'pending_payment';
137
+ $orderStatus = 'cardsave_failed_threed_secure';
138
+ $order->setCustomerNote(Mage::helper('cardsaveonlinepayments')->__('3D Secure Authentication Failed'));
139
+ $order->setState($orderState, $orderStatus, $szPaymentProcessorResponse, false);
140
+ $order->save();
141
+ }
142
+ }
143
+ if($nVersion == 1324 || $nVersion == 1330)
144
+ {
145
+ Mage::getSingleton('checkout/session')->addError($szMessage);
146
+ }
147
+ else
148
+ {
149
+ Mage::getSingleton('core/session')->addError($szMessage);
150
+ }
151
+
152
+ $this->_clearSessionVariables();
153
  // report out an fatal error
 
154
  $this->_redirect('checkout/onepage/failure');
155
  }
156
  else
164
  $order->sendNewOrderEmail();
165
  }
166
 
167
+ if($nVersion >= 1410)
 
 
 
168
  {
169
+ $this->_subtractOrderedItemsFromStock($order);
170
+ $this->_updateInvoices($order, $szPaymentProcessorResponse);
171
+ }
172
+
173
+ if($nVersion != 1324 && $nVersion != 1330)
174
+ {
175
+ if($szPaymentProcessorResponse != '')
176
+ {
177
+ Mage::getSingleton('core/session')->addSuccess($szPaymentProcessorResponse);
178
+ }
179
  }
180
+
181
  $this->_redirect('checkout/onepage/success', array('_secure' => true));
182
  }
183
  }
197
  $szPaymentProcessorResponse = '';
198
  $order = Mage::getModel('sales/order');
199
  $order->load(Mage::getSingleton('checkout/session')->getLastOrderId());
200
+ $nVersion = Mage::getModel('cardsaveonlinepayments/direct')->getVersion();
201
 
202
  try
203
  {
260
  $szNotificationMessage = $szNotificationMessage.'<br/>'.$szPaymentProcessorResponse;
261
  }
262
 
263
+ if($nVersion >= 1410)
264
+ {
265
+ if($order)
266
+ {
267
+ $orderState = 'pending_payment';
268
+ $orderStatus = 'cardsave_failed_hosted_payment';
269
+ $order->setCustomerNote(Mage::helper('cardsaveonlinepayments')->__('Hosted Payment Failed'));
270
+ $order->setState($orderState, $orderStatus, $szPaymentProcessorResponse, false);
271
+ $order->save();
272
+ }
273
+ }
274
+ if($nVersion == 1324 || $nVersion == 1330)
275
+ {
276
+ Mage::getSingleton('checkout/session')->addError($szNotificationMessage);
277
+ }
278
+ else
279
+ {
280
+ Mage::getSingleton('core/session')->addError($szNotificationMessage);
281
+ }
282
 
283
  $this->_clearSessionVariables();
 
284
  $this->_redirect('checkout/onepage/failure');
285
  }
286
  else
294
  $order->sendNewOrderEmail();
295
  }
296
 
297
+ if($nVersion >= 1410)
298
+ {
299
+ $this->_subtractOrderedItemsFromStock($order);
300
+ $this->_updateInvoices($order, $szPaymentProcessorResponse);
301
+ }
302
 
303
+ if($nVersion != 1324 && $nVersion != 1330)
304
  {
305
+ if($szPaymentProcessorResponse != '')
306
+ {
307
+ Mage::getSingleton('core/session')->addSuccess($szPaymentProcessorResponse);
308
+ }
309
  }
310
  $this->_redirect('checkout/onepage/success', array('_secure' => true));
311
  }
322
  $checkout = Mage::getSingleton('checkout/type_onepage');
323
  $szOrderID = $this->getRequest()->getPost('OrderID');
324
  $szMessage = $this->getRequest()->getPost('Message');
325
+ $nVersion = Mage::getModel('cardsaveonlinepayments/direct')->getVersion();
326
 
327
  try
328
  {
364
  if($this->getRequest()->getPost('StatusCode') == '0')
365
  {
366
  Mage::getSingleton('checkout/session')->clear();
367
+
368
+ if($nVersion >= 1410)
369
+ {
370
+ $this->_subtractOrderedItemsFromStock($order);
371
+ $this->_updateInvoices($order, $szMessage);
372
+ }
373
  }
374
 
375
  $this->getResponse()->setBody('StatusCode=0');
402
  $nStartIndex = strpos($szURLVariableString, "?");
403
  $order = Mage::getModel('sales/order');
404
  $order->load(Mage::getSingleton('checkout/session')->getLastOrderId());
405
+ $nVersion = Mage::getModel('cardsaveonlinepayments/direct')->getVersion();
406
 
407
  if(!is_int($nStartIndex))
408
  {
494
 
495
  if($szErrorMessage)
496
  {
497
+ if($nVersion >= 1410)
498
+ {
499
+ if($order)
500
+ {
501
+ $orderState = 'pending_payment';
502
+ $orderStatus = 'cardsave_failed_hosted_payment';
503
+ $order->setCustomerNote(Mage::helper('cardsaveonlinepayments')->__('Hosted Payment Failed'));
504
+ $order->setState($orderState, $orderStatus, $szErrorMessage, false);
505
+ $order->save();
506
+ }
507
+ }
508
+ if($nVersion == 1324 || $nVersion == 1330)
509
  {
510
+ Mage::getSingleton('checkout/session')->addError($szErrorMessage);
511
+ }
512
+ else
513
+ {
514
+ Mage::getSingleton('core/session')->addError($szErrorMessage);
515
  }
516
 
517
  $this->_clearSessionVariables();
 
518
  $this->_redirect('checkout/onepage/failure');
519
  }
520
  else
528
  $order->sendNewOrderEmail();
529
  }
530
 
531
+ if($nVersion >= 1410)
532
+ {
533
+ $this->_subtractOrderedItemsFromStock($order);
534
+ $this->_updateInvoices($order, $szMessage);
535
+ }
536
 
537
+ if($nVersion != 1324 && $nVersion != 1330)
538
+ {
539
+ Mage::getSingleton('core/session')->addSuccess('Payment Processor Response: '.$szMessage);
540
+ }
541
  $this->_redirect('checkout/onepage/success', array('_secure' => true));
542
  }
543
  }
551
  $model = Mage::getModel('cardsaveonlinepayments/direct');
552
  $order = Mage::getModel('sales/order');
553
  $order->load(Mage::getSingleton('checkout/session')->getLastOrderId());
554
+ $nVersion = Mage::getModel('cardsaveonlinepayments/direct')->getVersion();
555
 
556
  try
557
  {
585
  $error = Cardsave_Cardsaveonlinepayments_Model_Common_GlobalErrors::ERROR_260;
586
  Mage::logException($exc);
587
 
588
+ if($nVersion >= 1410)
589
+ {
590
+ if($order)
591
+ {
592
+ $orderState = 'pending_payment';
593
+ $orderStatus = 'cardsave_failed_hosted_payment';
594
+ $order->setCustomerNote(Mage::helper('cardsaveonlinepayments')->__('Transparent Redirect Payment Failed'));
595
+ $order->setState($orderState, $orderStatus, $exc->getMessage(), false);
596
+ $order->save();
597
+ }
598
+ }
599
+ if($nVersion == 1324 || $nVersion == 1330)
600
+ {
601
+ Mage::getSingleton('checkout/session')->addError($error);
602
+ }
603
+ else
604
+ {
605
+ Mage::getSingleton('core/session')->addError($error);
606
+ }
607
 
608
  $this->_clearSessionVariables();
 
609
  $this->_redirect('checkout/onepage/failure');
610
  }
611
  }
686
  $szPaymentProcessorResponse = '';
687
  $order = Mage::getModel('sales/order');
688
  $order->load(Mage::getSingleton('checkout/session')->getLastOrderId());
689
+ $nVersion = Mage::getModel('cardsaveonlinepayments/direct')->getVersion();
690
 
691
  try
692
  {
744
  $szNotificationMessage = $szNotificationMessage.'<br/>'.$szPaymentProcessorResponse;
745
  }
746
 
747
+ if($nVersion >= 1410)
748
+ {
749
+ if($order)
750
+ {
751
+ $orderState = 'pending_payment';
752
+ $orderStatus = 'cardsave_failed_hosted_payment';
753
+ $order->setCustomerNote(Mage::helper('cardsaveonlinepayments')->__('Transparent Redirect Payment Failed'));
754
+ $order->setState($orderState, $orderStatus, $szPaymentProcessorResponse, false);
755
+ $order->save();
756
+ }
757
+ }
758
+ if($nVersion == 1324 || $nVersion == 1330)
759
+ {
760
+ Mage::getSingleton('checkout/session')->addError($szNotificationMessage);
761
+ }
762
+ else
763
+ {
764
+ Mage::getSingleton('core/session')->addError($szNotificationMessage);
765
+ }
766
 
767
  $this->_clearSessionVariables();
 
768
  $this->_redirect('checkout/onepage/failure');
769
  }
770
  else
777
  $order->sendNewOrderEmail();
778
  }
779
 
780
+ if($nVersion >= 1410)
781
+ {
782
+ $this->_subtractOrderedItemsFromStock($order);
783
+ $this->_updateInvoices($order, $szPaymentProcessorResponse);
784
+ }
785
 
786
+ if($nVersion != 1324 && $nVersion != 1330)
787
  {
788
+ if($szPaymentProcessorResponse != '')
789
+ {
790
+ Mage::getSingleton('core/session')->addSuccess($szPaymentProcessorResponse);
791
+ }
792
  }
793
  $this->_redirect('checkout/onepage/success', array('_secure' => true));
794
  }
801
  */
802
  private function _subtractOrderedItemsFromStock($order)
803
  {
804
+ $nVersion = Mage::getModel('cardsaveonlinepayments/direct')->getVersion();
805
  $isCustomStockManagementEnabled = Mage::getModel('cardsaveonlinepayments/direct')->getConfigData('customstockmanagementenabled');
806
 
807
  if($nVersion >= 1410 &&
833
  */
834
  private function _addOrderedItemsToStock($order)
835
  {
836
+ $nVersion = Mage::getModel('cardsaveonlinepayments/direct')->getVersion();
837
  $isCustomStockManagementEnabled = Mage::getModel('cardsaveonlinepayments/direct')->getConfigData('customstockmanagementenabled');
838
 
839
  if($nVersion >= 1410 &&
app/code/local/Cardsave/Checkout/Model/Type/Onepage.php CHANGED
@@ -2,7 +2,8 @@
2
 
3
  class Cardsave_Checkout_Model_Type_Onepage extends Mage_Checkout_Model_Type_Onepage
4
  {
5
- public function getVersion($magentoVersion)
 
6
  {
7
  $pattern = '/[^\d]/';
8
  $magentoVersion = preg_replace($pattern, '', $magentoVersion);
@@ -23,7 +24,7 @@ class Cardsave_Checkout_Model_Type_Onepage extends Mage_Checkout_Model_Type_Onep
23
  */
24
  public function saveOrder()
25
  {
26
- $nVersion = $this->getVersion(Mage::getVersion());
27
 
28
  if($nVersion >= 1410)
29
  {
@@ -121,7 +122,7 @@ class Cardsave_Checkout_Model_Type_Onepage extends Mage_Checkout_Model_Type_Onep
121
  // TODO: send recurring profile emails
122
  }
123
  }
124
- else
125
  {
126
  // logic for version below 1.4.0.1 and below
127
  $this->validateOrder();
@@ -373,6 +374,259 @@ class Cardsave_Checkout_Model_Type_Onepage extends Mage_Checkout_Model_Type_Onep
373
  //$this->getQuote()->setIsActive(false);
374
  //$this->getQuote()->save();
375
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
376
 
377
  return $this;
378
  }
@@ -386,7 +640,7 @@ class Cardsave_Checkout_Model_Type_Onepage extends Mage_Checkout_Model_Type_Onep
386
  */
387
  public function saveOrderAfter3dSecure($pares, $md)
388
  {
389
- $nVersion = $this->getVersion(Mage::getVersion());
390
 
391
  if($nVersion >= 1410)
392
  {
@@ -421,7 +675,7 @@ class Cardsave_Checkout_Model_Type_Onepage extends Mage_Checkout_Model_Type_Onep
421
  ->setAcsurl(null)
422
  ->setCardsaveonlinepaymentsOrderId(null);
423
  }
424
- else
425
  {
426
  $this->validateOrder();
427
  $billing = $this->getQuote()->getBillingAddress();
@@ -576,7 +830,7 @@ class Cardsave_Checkout_Model_Type_Onepage extends Mage_Checkout_Model_Type_Onep
576
  */
577
  public function saveOrderAfterRedirectedPaymentAction($boIsHostedPaymentAction, $szStatusCode, $szMessage, $szPreviousStatusCode, $szPreviousMessage, $szOrderID)
578
  {
579
- $nVersion = $this->getVersion(Mage::getVersion());
580
 
581
  if($nVersion >= 1410)
582
  {
@@ -618,7 +872,7 @@ class Cardsave_Checkout_Model_Type_Onepage extends Mage_Checkout_Model_Type_Onep
618
  ->setOrderid(null)
619
  ->setCardsaveonlinepaymentsOrderId(null);
620
  }
621
- else
622
  {
623
  $this->validateOrder();
624
  $billing = $this->getQuote()->getBillingAddress();
2
 
3
  class Cardsave_Checkout_Model_Type_Onepage extends Mage_Checkout_Model_Type_Onepage
4
  {
5
+ // TODO : REMOVE - old representation
6
+ /*public function getVersion($magentoVersion)
7
  {
8
  $pattern = '/[^\d]/';
9
  $magentoVersion = preg_replace($pattern, '', $magentoVersion);
24
  */
25
  public function saveOrder()
26
  {
27
+ $nVersion = Mage::getModel('cardsaveonlinepayments/direct')->getVersion();
28
 
29
  if($nVersion >= 1410)
30
  {
122
  // TODO: send recurring profile emails
123
  }
124
  }
125
+ else if($nVersion == 1400 || $nVersion == 1401)
126
  {
127
  // logic for version below 1.4.0.1 and below
128
  $this->validateOrder();
374
  //$this->getQuote()->setIsActive(false);
375
  //$this->getQuote()->save();
376
  }
377
+ else if($nVersion == 1324 || $nVersion == 1330)
378
+ {
379
+ $this->validateOrder();
380
+ $billing = $this->getQuote()->getBillingAddress();
381
+
382
+ if (!$this->getQuote()->isVirtual())
383
+ {
384
+ $shipping = $this->getQuote()->getShippingAddress();
385
+ }
386
+
387
+ switch ($this->getQuote()->getCheckoutMethod())
388
+ {
389
+ case Mage_Sales_Model_Quote::CHECKOUT_METHOD_GUEST:
390
+ if (!$this->getQuote()->isAllowedGuestCheckout())
391
+ {
392
+ Mage::throwException(Mage::helper('checkout')->__('Sorry, guest checkout is not enabled. Please try again or contact store owner.'));
393
+ }
394
+ $this->getQuote()->setCustomerId(null)
395
+ ->setCustomerEmail($billing->getEmail())
396
+ ->setCustomerIsGuest(true)
397
+ ->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
398
+ break;
399
+
400
+ case Mage_Sales_Model_Quote::CHECKOUT_METHOD_REGISTER:
401
+ $customer = Mage::getModel('customer/customer');
402
+
403
+ $customerBilling = $billing->exportCustomerAddress();
404
+ $customer->addAddress($customerBilling);
405
+
406
+ if (!$this->getQuote()->isVirtual() &&
407
+ !$shipping->getSameAsBilling())
408
+ {
409
+ $customerShipping = $shipping->exportCustomerAddress();
410
+ $customer->addAddress($customerShipping);
411
+ }
412
+
413
+ if ($this->getQuote()->getCustomerDob() &&
414
+ !$billing->getCustomerDob())
415
+ {
416
+ $billing->setCustomerDob($this->getQuote()->getCustomerDob());
417
+ }
418
+
419
+ if ($this->getQuote()->getCustomerTaxvat() && !$billing->getCustomerTaxvat())
420
+ {
421
+ $billing->setCustomerTaxvat($this->getQuote()->getCustomerTaxvat());
422
+ }
423
+
424
+ Mage::helper('core')->copyFieldset('checkout_onepage_billing', 'to_customer', $billing, $customer);
425
+
426
+ $customer->setPassword($customer->decryptPassword($this->getQuote()->getPasswordHash()));
427
+ $customer->setPasswordHash($customer->hashPassword($customer->getPassword()));
428
+
429
+ $this->getQuote()->setCustomer($customer);
430
+ Mage::log(time());
431
+ break;
432
+
433
+ default:
434
+ $customer = Mage::getSingleton('customer/session')->getCustomer();
435
+
436
+ if (!$billing->getCustomerId() ||
437
+ $billing->getSaveInAddressBook())
438
+ {
439
+ $customerBilling = $billing->exportCustomerAddress();
440
+ $customer->addAddress($customerBilling);
441
+ }
442
+ if (!$this->getQuote()->isVirtual() &&
443
+ ((!$shipping->getCustomerId() && !$shipping->getSameAsBilling()) ||
444
+ (!$shipping->getSameAsBilling() && $shipping->getSaveInAddressBook())))
445
+ {
446
+ $customerShipping = $shipping->exportCustomerAddress();
447
+ $customer->addAddress($customerShipping);
448
+ }
449
+ $customer->setSavedFromQuote(true);
450
+ $customer->save();
451
+
452
+ $changed = false;
453
+ if (isset($customerBilling) &&
454
+ !$customer->getDefaultBilling())
455
+ {
456
+ $customer->setDefaultBilling($customerBilling->getId());
457
+ $changed = true;
458
+ }
459
+ if (!$this->getQuote()->isVirtual() &&
460
+ isset($customerBilling) &&
461
+ !$customer->getDefaultShipping() &&
462
+ $shipping->getSameAsBilling())
463
+ {
464
+ $customer->setDefaultShipping($customerBilling->getId());
465
+ $changed = true;
466
+ }
467
+ elseif (!$this->getQuote()->isVirtual() &&
468
+ isset($customerShipping) &&
469
+ !$customer->getDefaultShipping())
470
+ {
471
+ $customer->setDefaultShipping($customerShipping->getId());
472
+ $changed = true;
473
+ }
474
+
475
+ if ($changed)
476
+ {
477
+ $customer->save();
478
+ }
479
+ }
480
+
481
+ $this->getQuote()->reserveOrderId();
482
+ $convertQuote = Mage::getModel('sales/convert_quote');
483
+ // @var $convertQuote Mage_Sales_Model_Convert_Quote
484
+ if ($this->getQuote()->isVirtual())
485
+ {
486
+ $order = $convertQuote->addressToOrder($billing);
487
+ }
488
+ else
489
+ {
490
+ $order = $convertQuote->addressToOrder($shipping);
491
+ }
492
+ // @var $order Mage_Sales_Model_Order
493
+ $order->setBillingAddress($convertQuote->addressToOrderAddress($billing));
494
+
495
+ if (!$this->getQuote()->isVirtual())
496
+ {
497
+ $order->setShippingAddress($convertQuote->addressToOrderAddress($shipping));
498
+ }
499
+
500
+ $order->setPayment($convertQuote->paymentToOrderPayment($this->getQuote()->getPayment()));
501
+
502
+ foreach ($this->getQuote()->getAllItems() as $item)
503
+ {
504
+ $orderItem = $convertQuote->itemToOrderItem($item);
505
+ if ($item->getParentItem())
506
+ {
507
+ $orderItem->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId()));
508
+ }
509
+ $order->addItem($orderItem);
510
+ }
511
+
512
+ // We can use configuration data for declare new order status
513
+ Mage::dispatchEvent('checkout_type_onepage_save_order', array('order'=>$order, 'quote'=>$this->getQuote()));
514
+ // check again, if customer exists
515
+ if ($this->getQuote()->getCheckoutMethod() == Mage_Sales_Model_Quote::CHECKOUT_METHOD_REGISTER)
516
+ {
517
+ if ($this->_customerEmailExists($customer->getEmail(), Mage::app()->getWebsite()->getId()))
518
+ {
519
+ Mage::throwException(Mage::helper('checkout')->__('There is already a customer registered using this email address'));
520
+ }
521
+ }
522
+
523
+ // clear 3dSecure session variables
524
+ Mage::getSingleton('checkout/session')->setThreedsecurerequired(null);
525
+ Mage::getSingleton('checkout/session')->setMd(null);
526
+ Mage::getSingleton('checkout/session')->setPares(null);
527
+ Mage::getSingleton('checkout/session')->setAcsurl(null);
528
+
529
+ $order->place();
530
+
531
+ if ($this->getQuote()->getCheckoutMethod()==Mage_Sales_Model_Quote::CHECKOUT_METHOD_REGISTER)
532
+ {
533
+ $customer->save();
534
+ $customerBillingId = $customerBilling->getId();
535
+ if (!$this->getQuote()->isVirtual())
536
+ {
537
+ $customerShippingId = isset($customerShipping) ? $customerShipping->getId() : $customerBillingId;
538
+ $customer->setDefaultShipping($customerShippingId);
539
+ }
540
+ $customer->setDefaultBilling($customerBillingId);
541
+ $customer->save();
542
+
543
+ $this->getQuote()->setCustomerId($customer->getId());
544
+
545
+ $order->setCustomerId($customer->getId());
546
+ Mage::helper('core')->copyFieldset('customer_account', 'to_order', $customer, $order);
547
+
548
+ $billing->setCustomerId($customer->getId())->setCustomerAddressId($customerBillingId);
549
+ if (!$this->getQuote()->isVirtual())
550
+ {
551
+ $shipping->setCustomerId($customer->getId())->setCustomerAddressId($customerShippingId);
552
+ }
553
+
554
+ if ($customer->isConfirmationRequired())
555
+ {
556
+ $customer->sendNewAccountEmail('confirmation');
557
+ }
558
+ else
559
+ {
560
+ $customer->sendNewAccountEmail();
561
+ }
562
+ }
563
+
564
+ /**
565
+ * a flag to set that there will be redirect to third party after confirmation
566
+ * eg: paypal standard ipn
567
+ */
568
+ $redirectUrl = $this->getQuote()->getPayment()->getOrderPlaceRedirectUrl();
569
+ if(!$redirectUrl)
570
+ {
571
+ $order->setEmailSent(true);
572
+ }
573
+
574
+ if(!$redirectUrl ||
575
+ $this->getQuote()->getPayment()->getMethodInstance()->getCode() != 'cardsaveonlinepayments')
576
+ {
577
+ $order->save();
578
+ }
579
+
580
+ Mage::dispatchEvent('checkout_type_onepage_save_order_after', array('order'=>$order, 'quote'=>$this->getQuote()));
581
+
582
+
583
+ /**
584
+ * need to have somelogic to set order as new status to make sure order is not finished yet
585
+ * quote will be still active when we send the customer to paypal
586
+ */
587
+
588
+ $orderId = $order->getIncrementId();
589
+ $this->getCheckout()->setLastQuoteId($this->getQuote()->getId());
590
+ $this->getCheckout()->setLastOrderId($order->getId());
591
+ $this->getCheckout()->setLastRealOrderId($order->getIncrementId());
592
+ $this->getCheckout()->setRedirectUrl($redirectUrl);
593
+
594
+ /**
595
+ * we only want to send to customer about new order when there is no redirect to third party
596
+ */
597
+ if(!$redirectUrl)
598
+ {
599
+ $order->sendNewOrderEmail();
600
+ }
601
+
602
+ if ($this->getQuote()->getCheckoutMethod(true) == Mage_Sales_Model_Quote::CHECKOUT_METHOD_REGISTER &&
603
+ !Mage::getSingleton('customer/session')->isLoggedIn())
604
+ {
605
+ /**
606
+ * we need to save quote here to have it saved with Customer Id.
607
+ * so when loginById() executes checkout/session method loadCustomerQuote
608
+ * it would not create new quotes and merge it with old one.
609
+ */
610
+ $this->getQuote()->save();
611
+ if ($customer->isConfirmationRequired())
612
+ {
613
+ Mage::getSingleton('checkout/session')->addSuccess(Mage::helper('customer')->__('Account confirmation is required. Please, check your e-mail for confirmation link. To resend confirmation email please <a href="%s">click here</a>.',
614
+ Mage::helper('customer')->getEmailConfirmationUrl($customer->getEmail())
615
+ ));
616
+ }
617
+ else
618
+ {
619
+ Mage::getSingleton('customer/session')->loginById($customer->getId());
620
+ }
621
+ }
622
+
623
+ //Setting this one more time like control flag that we haves saved order
624
+ //Must be checkout on success page to show it or not.
625
+ $this->getCheckout()->setLastSuccessQuoteId($this->getQuote()->getId());
626
+
627
+ $this->getQuote()->setIsActive(false);
628
+ $this->getQuote()->save();
629
+ }
630
 
631
  return $this;
632
  }
640
  */
641
  public function saveOrderAfter3dSecure($pares, $md)
642
  {
643
+ $nVersion = Mage::getModel('cardsaveonlinepayments/direct')->getVersion();
644
 
645
  if($nVersion >= 1410)
646
  {
675
  ->setAcsurl(null)
676
  ->setCardsaveonlinepaymentsOrderId(null);
677
  }
678
+ else if($nVersion == 1400 || $nVersion == 1401 || $nVersion == 1324 || $nVersion == 1330)
679
  {
680
  $this->validateOrder();
681
  $billing = $this->getQuote()->getBillingAddress();
830
  */
831
  public function saveOrderAfterRedirectedPaymentAction($boIsHostedPaymentAction, $szStatusCode, $szMessage, $szPreviousStatusCode, $szPreviousMessage, $szOrderID)
832
  {
833
+ $nVersion = Mage::getModel('cardsaveonlinepayments/direct')->getVersion();
834
 
835
  if($nVersion >= 1410)
836
  {
872
  ->setOrderid(null)
873
  ->setCardsaveonlinepaymentsOrderId(null);
874
  }
875
+ else if($nVersion == 1400 || $nVersion == 1401 || $nVersion == 1324 || $nVersion == 1330)
876
  {
877
  $this->validateOrder();
878
  $billing = $this->getQuote()->getBillingAddress();
app/code/local/Cardsave/Sales/Model/Order/Invoice.php CHANGED
@@ -20,22 +20,45 @@ class Cardsave_Sales_Model_Order_Invoice extends Mage_Sales_Model_Order_Invoice
20
 
21
  public function pay()
22
  {
23
- if ($this->_wasPayCalled)
24
- {
25
- return $this;
26
- }
27
-
28
- if(!$this->getOrder()->getIsThreeDSecurePending() &&
29
- !$this->getOrder()->getIsHostedPaymentPending())
30
- {
31
- $this->_wasPayCalled = true;
32
-
33
- $invoiceState = self::STATE_PAID;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  if ($this->getOrder()->getPayment()->hasForcedState())
35
  {
36
  $invoiceState = $this->getOrder()->getPayment()->getForcedState();
37
  }
38
-
39
  $this->setState($invoiceState);
40
 
41
  $this->getOrder()->getPayment()->pay($this);
@@ -46,7 +69,7 @@ class Cardsave_Sales_Model_Order_Invoice extends Mage_Sales_Model_Order_Invoice
46
  $this->getOrder()->getBaseTotalPaid()+$this->getBaseGrandTotal()
47
  );
48
  Mage::dispatchEvent('sales_order_invoice_pay', array($this->_eventObject=>$this));
49
- }
50
 
51
  return $this;
52
  }
20
 
21
  public function pay()
22
  {
23
+ $nVersion = Mage::getModel('cardsaveonlinepayments/direct')->getVersion();
24
+
25
+ if($nVersion >= 1400)
26
+ {
27
+ if ($this->_wasPayCalled)
28
+ {
29
+ return $this;
30
+ }
31
+
32
+ if(!$this->getOrder()->getIsThreeDSecurePending() &&
33
+ !$this->getOrder()->getIsHostedPaymentPending())
34
+ {
35
+ $this->_wasPayCalled = true;
36
+
37
+ $invoiceState = self::STATE_PAID;
38
+ if ($this->getOrder()->getPayment()->hasForcedState())
39
+ {
40
+ $invoiceState = $this->getOrder()->getPayment()->getForcedState();
41
+ }
42
+
43
+ $this->setState($invoiceState);
44
+
45
+ $this->getOrder()->getPayment()->pay($this);
46
+ $this->getOrder()->setTotalPaid(
47
+ $this->getOrder()->getTotalPaid()+$this->getGrandTotal()
48
+ );
49
+ $this->getOrder()->setBaseTotalPaid(
50
+ $this->getOrder()->getBaseTotalPaid()+$this->getBaseGrandTotal()
51
+ );
52
+ Mage::dispatchEvent('sales_order_invoice_pay', array($this->_eventObject=>$this));
53
+ }
54
+ }
55
+ else if($nVersion == 1324 || $nVersion == 1330)
56
+ {
57
+ $invoiceState = self::STATE_PAID;
58
  if ($this->getOrder()->getPayment()->hasForcedState())
59
  {
60
  $invoiceState = $this->getOrder()->getPayment()->getForcedState();
61
  }
 
62
  $this->setState($invoiceState);
63
 
64
  $this->getOrder()->getPayment()->pay($this);
69
  $this->getOrder()->getBaseTotalPaid()+$this->getBaseGrandTotal()
70
  );
71
  Mage::dispatchEvent('sales_order_invoice_pay', array($this->_eventObject=>$this));
72
+ }
73
 
74
  return $this;
75
  }
app/code/local/Cardsave/Sales/Model/Order/Payment.php CHANGED
@@ -2,6 +2,170 @@
2
 
3
  class Cardsave_Sales_Model_Order_Payment extends Mage_Sales_Model_Order_Payment
4
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  /**
6
  * Authorize or authorize and capture payment on gateway, if applicable
7
  * This method is supposed to be called only when order is placed
@@ -10,113 +174,1313 @@ class Cardsave_Sales_Model_Order_Payment extends Mage_Sales_Model_Order_Payment
10
  */
11
  public function place()
12
  {
13
- Mage::dispatchEvent('sales_order_payment_place_start', array('payment' => $this));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  $order = $this->getOrder();
15
 
16
- $this->setAmountOrdered($order->getTotalDue());
17
- $this->setBaseAmountOrdered($order->getBaseTotalDue());
18
- $this->setShippingAmount($order->getShippingAmount());
19
- $this->setBaseShippingAmount($order->getBaseShippingAmount());
20
-
21
- $methodInstance = $this->getMethodInstance();
22
- $methodInstance->setStore($order->getStoreId());
23
-
24
- $orderState = Mage_Sales_Model_Order::STATE_NEW;
25
- $orderStatus= false;
26
-
27
- $stateObject = new Varien_Object();
28
-
29
- /**
30
- * Do order payment validation on payment method level
31
- */
32
- $methodInstance->validate();
33
- $action = $methodInstance->getConfigPaymentAction();
34
- if ($action) {
35
- if ($methodInstance->isInitializeNeeded()) {
36
- /**
37
- * For method initialization we have to use original config value for payment action
38
- */
39
- $methodInstance->initialize($methodInstance->getConfigData('payment_action'), $stateObject);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  } else {
41
- $orderState = Mage_Sales_Model_Order::STATE_PROCESSING;
42
- switch ($action) {
43
- case Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE:
44
- $this->_authorize(true, $order->getBaseTotalDue()); // base amount will be set inside
45
- $this->setAmountAuthorized($order->getTotalDue());
46
- break;
47
- case Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE:
48
- $this->setAmountAuthorized($order->getTotalDue());
49
- $this->setBaseAmountAuthorized($order->getBaseTotalDue());
50
- $this->capture(null);
51
- break;
52
- default:
53
- break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  }
55
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  }
 
57
 
58
- $this->_createBillingAgreement();
59
-
60
- $orderIsNotified = null;
61
- if ($stateObject->getState() && $stateObject->getStatus())
62
- {
63
- $orderState = $stateObject->getState();
64
- $orderStatus = $stateObject->getStatus();
65
- $orderIsNotified = $stateObject->getIsNotified();
66
- }
67
- else if($order->getIsThreeDSecurePending())
68
- {
69
- $orderState = 'pending_payment';
70
- $orderStatus = 'cardsave_pending_threed_secure';
71
- $message = '3D Secure authentication need to be completed';
72
- $orderIsNotified = false;
73
- }
74
- else if($order->getIsHostedPaymentPending())
75
- {
76
- $order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, true)->save();
77
- $orderState = 'pending_payment';
78
- $orderStatus = 'cardsave_pending_hosted_payment';
79
- $message = 'Hosted Payment need to be completed';
80
- $orderIsNotified = false;
81
- }
82
- else
83
- {
84
- $orderStatus = $methodInstance->getConfigData('order_status');
85
- if (!$orderStatus || $order->getIsVirtual())
86
- {
87
- $orderStatus = $order->getConfig()->getStateDefaultStatus($orderState);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  }
89
  }
90
-
91
- $isCustomerNotified = (null !== $orderIsNotified) ? $orderIsNotified : $order->getCustomerNoteNotify();
92
- //$message = $order->getCustomerNote();
93
- if(!$order->getIsThreeDSecurePending() &&
94
- !$order->getIsHostedPaymentPending())
95
- {
96
- $message = $order->getCustomerNote();
97
- }
98
-
99
- // add message if order was put into review during authorization or capture
100
- if ($order->getState() == Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW)
101
- {
102
- if ($message)
103
- {
104
- $order->addStatusToHistory($order->getStatus(), $message, $isCustomerNotified);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  }
 
106
  }
107
- // add message to history if order state already declared
108
- elseif ($order->getState() && ($orderStatus !== $order->getStatus() || $message))
109
- {
110
- $order->setState($orderState, $orderStatus, $message, $isCustomerNotified);
111
  }
112
- // set order state
113
- elseif (($order->getState() != $orderState) || ($order->getStatus() != $orderStatus) || $message)
114
- {
115
- $order->setState($orderState, $orderStatus, $message, $isCustomerNotified);
 
 
 
116
  }
 
 
117
 
118
- Mage::dispatchEvent('sales_order_payment_place_end', array('payment' => $this));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
 
120
  return $this;
121
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  }
2
 
3
  class Cardsave_Sales_Model_Order_Payment extends Mage_Sales_Model_Order_Payment
4
  {
5
+ /**
6
+ * Capture payment
7
+ *
8
+ * @return Mage_Sales_Model_Order_Payment
9
+ */
10
+ public function capture($invoice)
11
+ {
12
+ $nVersion = Mage::getModel('cardsaveonlinepayments/direct')->getVersion();
13
+
14
+ if($nVersion == 1411 || $nVersion == 1410)
15
+ {
16
+ if (is_null($invoice))
17
+ {
18
+ $invoice = $this->_invoice();
19
+ $this->setCreatedInvoice($invoice);
20
+ return $this; // @see Mage_Sales_Model_Order_Invoice::capture()
21
+ }
22
+ $amountToCapture = $this->_formatAmount($invoice->getBaseGrandTotal());
23
+ $order = $this->getOrder();
24
+
25
+ // prepare parent transaction and its amount
26
+ $paidWorkaround = 0;
27
+ if (!$invoice->wasPayCalled())
28
+ {
29
+ $paidWorkaround = (float)$amountToCapture;
30
+ }
31
+ $this->_isCaptureFinal($paidWorkaround);
32
+
33
+ $this->_generateTransactionId(Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE, $this->getAuthorizationTransaction());
34
+
35
+ Mage::dispatchEvent('sales_order_payment_capture', array('payment' => $this, 'invoice' => $invoice));
36
+
37
+ /**
38
+ * Fetch an update about existing transaction. It can determine whether the transaction can be paid
39
+ * Capture attempt will happen only when invoice is not yet paid and the transaction can be paid
40
+ */
41
+ if ($invoice->getTransactionId())
42
+ {
43
+ $this->getMethodInstance()->setStore($order->getStoreId())->fetchTransactionInfo($this, $invoice->getTransactionId());
44
+ }
45
+ $status = true;
46
+ if (!$invoice->getIsPaid() && !$this->getIsTransactionPending())
47
+ {
48
+ // attempt to capture: this can trigger "is_transaction_pending"
49
+ $this->getMethodInstance()->setStore($order->getStoreId())->capture($this, $amountToCapture);
50
+
51
+ $transaction = $this->_addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE, $invoice, true);
52
+
53
+ if ($this->getIsTransactionPending())
54
+ {
55
+ $message = Mage::helper('sales')->__('Capturing amount of %s is pending approval on gateway.', $this->_formatPrice($amountToCapture));
56
+ $state = Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW;
57
+ if ($this->getIsFraudDetected())
58
+ {
59
+ $status = 'fraud';
60
+ }
61
+ $invoice->setIsPaid(false);
62
+ }
63
+ else
64
+ { // normal online capture: invoice is marked as "paid"
65
+ $message = Mage::helper('sales')->__('Captured amount of %s online.', $this->_formatPrice($amountToCapture));
66
+ $state = Mage_Sales_Model_Order::STATE_PROCESSING;
67
+ $invoice->setIsPaid(true);
68
+ $this->_updateTotals(array('base_amount_paid_online' => $amountToCapture));
69
+ }
70
+ if ($order->isNominal())
71
+ {
72
+ $message = $this->_prependMessage(Mage::helper('sales')->__('Nominal order registered.'));
73
+ }
74
+ else
75
+ {
76
+ $message = $this->_prependMessage($message);
77
+ $message = $this->_appendTransactionToMessage($transaction, $message);
78
+ }
79
+ $order->setState($state, $status, $message);
80
+ $this->getMethodInstance()->processInvoice($invoice, $this); // should be deprecated
81
+ return $this;
82
+ }
83
+ Mage::throwException(Mage::helper('sales')->__('The transaction "%s" cannot be captured yet.', $invoice->getTransactionId()));
84
+ }
85
+ if($nVersion == 1400 || $nVersion == 1401)
86
+ {
87
+ if (is_null($invoice))
88
+ {
89
+ $invoice = $this->_invoice();
90
+ $this->setCreatedInvoice($invoice);
91
+ return $this; // @see Mage_Sales_Model_Order_Invoice::capture()
92
+ }
93
+ $amountToCapture = $this->_formatAmount($invoice->getBaseGrandTotal());
94
+
95
+ $paidWorkaround = 0;
96
+ if (!$invoice->wasPayCalled())
97
+ {
98
+ $paidWorkaround = (float)$amountToCapture;
99
+ }
100
+ $this->_isCaptureFinal($paidWorkaround);
101
+ $baseTransaction = false;
102
+ if ($invoice->getTransactionId())
103
+ {
104
+ $baseTransaction = $this->_lookupTransaction($invoice->getTransactionId());
105
+ }
106
+ else
107
+ {
108
+ $baseTransaction = $this->getAuthorizationTransaction();
109
+ }
110
+ $this->_generateTransactionId(Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE, $baseTransaction);
111
+
112
+ Mage::dispatchEvent('sales_order_payment_capture', array('payment' => $this, 'invoice' => $invoice));
113
+
114
+ $this->getMethodInstance()
115
+ ->setStore($this->getOrder()->getStoreId())
116
+ ->capture($this, $amountToCapture);
117
+
118
+ // update transactions, set order state (order will close itself if required)
119
+ $transaction = $this->_addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE, $invoice, true);
120
+ /**
121
+ * Check if payment transaction is under pending state.
122
+ * Gateway can accept peyment transaction but mark it as pending.
123
+ * We need hold such kind of orders
124
+ */
125
+ if ($this->getIsTransactionPending())
126
+ {
127
+ $message = Mage::helper('sales')->__('Amount of %s pending approval on gateway.', $this->_formatPrice($amountToCapture));
128
+ $message = $this->_prependMessage($message);
129
+ $message = $this->_appendTransactionToMessage($transaction, $message);
130
+ $status = $this->getTransactionPendingStatus() ? $this->getTransactionPendingStatus() : true;
131
+ $this->getOrder()->setState(Mage_Sales_Model_Order::STATE_HOLDED, $status, $message);
132
+ $invoice->setIsPaid(false);
133
+ }
134
+ else
135
+ {
136
+ $this->_updateTotals(array('base_amount_paid_online' => $amountToCapture));
137
+ $message = Mage::helper('sales')->__('Captured amount of %s online.', $this->_formatPrice($amountToCapture));
138
+ $message = $this->_prependMessage($message);
139
+ $message = $this->_appendTransactionToMessage($transaction, $message);
140
+ $this->getOrder()->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, $message);
141
+ $invoice->setIsPaid(true);
142
+ }
143
+
144
+ $this->getMethodInstance()->processInvoice($invoice, $this); // should be deprecated
145
+ return $this;
146
+ }
147
+ if($nVersion == 1324 || $nVersion == 1330)
148
+ {
149
+ if (is_null($invoice))
150
+ {
151
+ $invoice = $this->_invoice();
152
+ }
153
+
154
+ Mage::dispatchEvent('sales_order_payment_capture', array('payment' => $this, 'invoice' => $invoice));
155
+
156
+ $this->getMethodInstance()
157
+ ->setStore($this->getOrder()->getStoreId())
158
+ ->capture($this, sprintf('%.2f', $invoice->getBaseGrandTotal()));
159
+ if($this->getIsInvoicePaid())
160
+ {
161
+ $invoice->setIsPaid(true);
162
+ }
163
+ $this->getMethodInstance()->processInvoice($invoice, $this);
164
+
165
+ return $this;
166
+ }
167
+ }
168
+
169
  /**
170
  * Authorize or authorize and capture payment on gateway, if applicable
171
  * This method is supposed to be called only when order is placed
174
  */
175
  public function place()
176
  {
177
+ $nVersion = Mage::getModel('cardsaveonlinepayments/direct')->getVersion();
178
+
179
+ if($nVersion == 1411 || $nVersion == 1410 || $nVersion == 1401 || $nVersion == 1400)
180
+ {
181
+ Mage::dispatchEvent('sales_order_payment_place_start', array('payment' => $this));
182
+ $order = $this->getOrder();
183
+
184
+ $this->setAmountOrdered($order->getTotalDue());
185
+ $this->setBaseAmountOrdered($order->getBaseTotalDue());
186
+ $this->setShippingAmount($order->getShippingAmount());
187
+ $this->setBaseShippingAmount($order->getBaseShippingAmount());
188
+
189
+ $methodInstance = $this->getMethodInstance();
190
+ $methodInstance->setStore($order->getStoreId());
191
+
192
+ $orderState = Mage_Sales_Model_Order::STATE_NEW;
193
+ $orderStatus= false;
194
+
195
+ $stateObject = new Varien_Object();
196
+
197
+ /**
198
+ * Do order payment validation on payment method level
199
+ */
200
+ $methodInstance->validate();
201
+ $action = $methodInstance->getConfigPaymentAction();
202
+ if ($action)
203
+ {
204
+ if ($methodInstance->isInitializeNeeded())
205
+ {
206
+ /**
207
+ * For method initialization we have to use original config value for payment action
208
+ */
209
+ $methodInstance->initialize($methodInstance->getConfigData('payment_action'), $stateObject);
210
+ }
211
+ else
212
+ {
213
+ $orderState = Mage_Sales_Model_Order::STATE_PROCESSING;
214
+ switch ($action)
215
+ {
216
+ case Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE:
217
+ $this->_authorize(true, $order->getBaseTotalDue()); // base amount will be set inside
218
+ $this->setAmountAuthorized($order->getTotalDue());
219
+ break;
220
+ case Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE:
221
+ $this->setAmountAuthorized($order->getTotalDue());
222
+ $this->setBaseAmountAuthorized($order->getBaseTotalDue());
223
+ $this->capture(null);
224
+ break;
225
+ default:
226
+ break;
227
+ }
228
+ }
229
+ }
230
+
231
+ if($nVersion == 1411 || $nVersion == 1410)
232
+ {
233
+ $this->_createBillingAgreement();
234
+ $orderStateHelper = Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW;
235
+ }
236
+ else
237
+ {
238
+ $orderStateHelper = Mage_Sales_Model_Order::STATE_HOLDED;
239
+ }
240
+
241
+ $orderIsNotified = null;
242
+ if ($stateObject->getState() && $stateObject->getStatus())
243
+ {
244
+ $orderState = $stateObject->getState();
245
+ $orderStatus = $stateObject->getStatus();
246
+ $orderIsNotified = $stateObject->getIsNotified();
247
+ }
248
+ else if($order->getIsThreeDSecurePending())
249
+ {
250
+ $orderState = 'pending_payment';
251
+ $orderStatus = 'cardsave_pending_threed_secure';
252
+ $message = '3D Secure authentication need to be completed';
253
+ $orderIsNotified = false;
254
+ }
255
+ else if($order->getIsHostedPaymentPending())
256
+ {
257
+ $order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, true)->save();
258
+ $orderState = 'pending_payment';
259
+ $orderStatus = 'cardsave_pending_hosted_payment';
260
+ $message = 'Hosted Payment need to be completed';
261
+ $orderIsNotified = false;
262
+ }
263
+ else
264
+ {
265
+ $orderStatus = $methodInstance->getConfigData('order_status');
266
+ if (!$orderStatus || $order->getIsVirtual())
267
+ {
268
+ $orderStatus = $order->getConfig()->getStateDefaultStatus($orderState);
269
+ }
270
+ }
271
+
272
+ $isCustomerNotified = (null !== $orderIsNotified) ? $orderIsNotified : $order->getCustomerNoteNotify();
273
+ //$message = $order->getCustomerNote();
274
+ if(!$order->getIsThreeDSecurePending() &&
275
+ !$order->getIsHostedPaymentPending())
276
+ {
277
+ $message = $order->getCustomerNote();
278
+ }
279
+
280
+ // add message if order was put into review during authorization or capture
281
+ //if ($order->getState() == Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW)$orderState
282
+ if ($order->getState() == $orderStateHelper)
283
+ {
284
+ if ($message)
285
+ {
286
+ $order->addStatusToHistory($order->getStatus(), $message, $isCustomerNotified);
287
+ }
288
+
289
+ if($nVersion == 1400 || $nVersion == 1401)
290
+ {
291
+ $order->setHoldBeforeState($orderState);
292
+ $order->setHoldBeforeStatus($orderStatus);
293
+ }
294
+ }
295
+ // add message to history if order state already declared
296
+ elseif ($order->getState() && ($orderStatus !== $order->getStatus() || $message))
297
+ {
298
+ $order->setState($orderState, $orderStatus, $message, $isCustomerNotified);
299
+ }
300
+ // set order state
301
+ elseif (($order->getState() != $orderState) || ($order->getStatus() != $orderStatus) || $message)
302
+ {
303
+ $order->setState($orderState, $orderStatus, $message, $isCustomerNotified);
304
+ }
305
+
306
+ Mage::dispatchEvent('sales_order_payment_place_end', array('payment' => $this));
307
+
308
+ return $this;
309
+ }
310
+ if($nVersion == 1324 || $nVersion == 1330)
311
+ {
312
+ Mage::dispatchEvent('sales_order_payment_place_start', array('payment' => $this));
313
+
314
+ $this->setAmountOrdered($this->getOrder()->getTotalDue());
315
+ $this->setBaseAmountOrdered($this->getOrder()->getBaseTotalDue());
316
+
317
+ $this->setShippingAmount($this->getOrder()->getShippingAmount());
318
+ $this->setBaseShippingAmount($this->getOrder()->getBaseShippingAmount());
319
+
320
+ $methodInstance = $this->getMethodInstance()->setStore($this->getOrder()->getStoreId());
321
+
322
+ $orderState = Mage_Sales_Model_Order::STATE_NEW;
323
+ $orderStatus= false;
324
+
325
+ $stateObject = new Varien_Object();
326
+
327
+ /**
328
+ * validating payment method again
329
+ */
330
+ $methodInstance->validate();
331
+ if ($action = $methodInstance->getConfigData('payment_action')) {
332
+ /**
333
+ * Run action declared for payment method in configuration
334
+ */
335
+
336
+ if ($methodInstance->isInitializeNeeded()) {
337
+ $methodInstance->initialize($action, $stateObject);
338
+ } else {
339
+ switch ($action) {
340
+ case Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE:
341
+ case Mage_Paypal_Model_Api_Abstract::PAYMENT_TYPE_AUTH:
342
+ $methodInstance->authorize($this, $this->getOrder()->getBaseTotalDue());
343
+
344
+ $this->setAmountAuthorized($this->getOrder()->getTotalDue());
345
+ $this->setBaseAmountAuthorized($this->getOrder()->getBaseTotalDue());
346
+
347
+ $orderState = Mage_Sales_Model_Order::STATE_PROCESSING;
348
+ break;
349
+ case Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE:
350
+ case Mage_Paypal_Model_Api_Abstract::PAYMENT_TYPE_SALE:
351
+ $invoice = $this->_invoice();
352
+
353
+ $this->setAmountAuthorized($this->getOrder()->getTotalDue());
354
+ $this->setBaseAmountAuthorized($this->getOrder()->getBaseTotalDue());
355
+
356
+ $orderState = $this->getOrder()->getIsVirtual()
357
+ ? Mage_Sales_Model_Order::STATE_COMPLETE
358
+ : Mage_Sales_Model_Order::STATE_PROCESSING;
359
+ break;
360
+ default:
361
+ break;
362
+ }
363
+ }
364
+ }
365
+
366
+ $orderIsNotified = null;
367
+ if ($stateObject->getState() && $stateObject->getStatus()) {
368
+ $orderState = $stateObject->getState();
369
+ $orderStatus = $stateObject->getStatus();
370
+ $orderIsNotified = $stateObject->getIsNotified();
371
+ } else {
372
+ /*
373
+ * this flag will set if the order went to as authorization under fraud service for payflowpro
374
+ */
375
+ if ($this->getFraudFlag()) {
376
+ $orderStatus = $methodInstance->getConfigData('fraud_order_status');
377
+ $orderState = Mage_Sales_Model_Order::STATE_HOLDED;
378
+ } else {
379
+ /**
380
+ * Change order status if it specified
381
+ */
382
+ $orderStatus = $methodInstance->getConfigData('order_status');
383
+ }
384
+
385
+ if (!$orderStatus || $this->getOrder()->getIsVirtual()) {
386
+ $orderStatus = $this->getOrder()->getConfig()->getStateDefaultStatus($orderState);
387
+ }
388
+ }
389
+
390
+ $this->getOrder()->setState($orderState);
391
+ $this->getOrder()->addStatusToHistory(
392
+ $orderStatus,
393
+ $this->getOrder()->getCustomerNote(),
394
+ (null !== $orderIsNotified ? $orderIsNotified : $this->getOrder()->getCustomerNoteNotify())
395
+ );
396
+
397
+ Mage::dispatchEvent('sales_order_payment_place_end', array('payment' => $this));
398
+
399
+ return $this;
400
+ }
401
+ }
402
+
403
+ /**
404
+ * Actions for payment when it triggered review state
405
+ *
406
+ * @var string
407
+ */
408
+ const REVIEW_ACTION_ACCEPT = 'accept';
409
+ const REVIEW_ACTION_DENY = 'deny';
410
+ const REVIEW_ACTION_UPDATE = 'update';
411
+
412
+ /**
413
+ * Order model object
414
+ *
415
+ * @var Mage_Sales_Model_Order
416
+ */
417
+ protected $_order;
418
+
419
+ /**
420
+ * Billing agreement instance that may be created during payment processing
421
+ *
422
+ * @var Mage_Sales_Model_Billing_Agreement
423
+ */
424
+ protected $_billingAgreement = null;
425
+
426
+ /**
427
+ * Whether can void
428
+ * @var string
429
+ */
430
+ protected $_canVoidLookup = null;
431
+
432
+ /**
433
+ * Transactions registry to spare resource calls
434
+ * array(txn_id => sales/order_payment_transaction)
435
+ * @var array
436
+ */
437
+ protected $_transactionsLookup = array();
438
+
439
+ protected $_eventPrefix = 'sales_order_payment';
440
+ protected $_eventObject = 'payment';
441
+
442
+ /**
443
+ * Transaction addditional information container
444
+ *
445
+ * @var array
446
+ */
447
+ protected $_transactionAdditionalInfo = array();
448
+
449
+ /**
450
+ * Initialize resource model
451
+ */
452
+ protected function _construct()
453
+ {
454
+ $this->_init('sales/order_payment');
455
+ }
456
+
457
+ /**
458
+ * Declare order model object
459
+ *
460
+ * @param Mage_Sales_Model_Order $order
461
+ * @return Mage_Sales_Model_Order_Payment
462
+ */
463
+ public function setOrder(Mage_Sales_Model_Order $order)
464
+ {
465
+ $this->_order = $order;
466
+ return $this;
467
+ }
468
+
469
+ /**
470
+ * Retrieve order model object
471
+ *
472
+ * @return Mage_Sales_Model_Order
473
+ */
474
+ public function getOrder()
475
+ {
476
+ return $this->_order;
477
+ }
478
+
479
+ /**
480
+ * Check order payment capture action availability
481
+ *
482
+ * @return bool
483
+ */
484
+ public function canCapture()
485
+ {
486
+ if (!$this->getMethodInstance()->canCapture()) {
487
+ return false;
488
+ }
489
+ // Check Authoriztion transaction state
490
+ $authTransaction = $this->getAuthorizationTransaction();
491
+ if ($authTransaction && $authTransaction->getIsClosed()) {
492
+ return false;
493
+ }
494
+ return true;
495
+ }
496
+
497
+ public function canRefund()
498
+ {
499
+ return $this->getMethodInstance()->canRefund();
500
+ }
501
+
502
+ public function canRefundPartialPerInvoice()
503
+ {
504
+ return $this->getMethodInstance()->canRefundPartialPerInvoice();
505
+ }
506
+
507
+ public function canCapturePartial()
508
+ {
509
+ return $this->getMethodInstance()->canCapturePartial();
510
+ }
511
+
512
+ /**
513
+ * Process a capture notification from a payment gateway for specified amount
514
+ * Creates an invoice automatically if the amount covers the order base grand total completely
515
+ * Updates transactions hierarchy, if required
516
+ * Prevents transaction double processing
517
+ * Updates payment totals, updates order status and adds proper comments
518
+ *
519
+ * TODO: eliminate logic duplication with capture()
520
+ *
521
+ * @param float $amount
522
+ * @return Mage_Sales_Model_Order_Payment
523
+ */
524
+ public function registerCaptureNotification($amount)
525
+ {
526
+ $this->_generateTransactionId(Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE,
527
+ $this->getAuthorizationTransaction()
528
+ );
529
+
530
+ $order = $this->getOrder();
531
+ $amount = (float)$amount;
532
+ $invoice = $this->_getInvoiceForTransactionId($this->getTransactionId());
533
+
534
+ // register new capture
535
+ if (!$invoice) {
536
+ if ($this->_isCaptureFinal($amount)) {
537
+ $invoice = $order->prepareInvoice()->register();
538
+ $order->addRelatedObject($invoice);
539
+ $this->setCreatedInvoice($invoice);
540
+ } else {
541
+ $this->_updateTotals(array('base_amount_paid_online' => $amount));
542
+ }
543
+ }
544
+
545
+ $status = true;
546
+ if ($this->getIsTransactionPending()) {
547
+ $message = Mage::helper('sales')->__('Capturing amount of %s is pending approval on gateway.', $this->_formatPrice($amount));
548
+ $state = Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW;
549
+ if ($this->getIsFraudDetected()) {
550
+ $status = 'fraud';
551
+ }
552
+ } else {
553
+ $message = Mage::helper('sales')->__('Registered notification about captured amount of %s.', $this->_formatPrice($amount));
554
+ $state = Mage_Sales_Model_Order::STATE_PROCESSING;
555
+ // register capture for an existing invoice
556
+ if ($invoice && Mage_Sales_Model_Order_Invoice::STATE_OPEN == $invoice->getState()) {
557
+ $invoice->pay();
558
+ $this->_updateTotals(array('base_amount_paid_online' => $amount));
559
+ $order->addRelatedObject($invoice);
560
+ }
561
+ }
562
+
563
+ $transaction = $this->_addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE, $invoice, true);
564
+ $message = $this->_prependMessage($message);
565
+ $message = $this->_appendTransactionToMessage($transaction, $message);
566
+ $order->setState($state, $status, $message);
567
+ return $this;
568
+ }
569
+
570
+ /**
571
+ * Process authorization notification
572
+ *
573
+ * @see self::_authorize()
574
+ * @param float $amount
575
+ * @return Mage_Sales_Model_Order_Payment
576
+ */
577
+ public function registerAuthorizationNotification($amount)
578
+ {
579
+ return ($this->_isTransactionExists()) ? $this : $this->_authorize(false, $amount);
580
+ }
581
+
582
+ /**
583
+ * Register payment fact: update self totals from the invoice
584
+ *
585
+ * @param Mage_Sales_Model_Order_Invoice $invoice
586
+ * @return Mage_Sales_Model_Order_Payment
587
+ */
588
+ public function pay($invoice)
589
+ {
590
+ $this->_updateTotals(array(
591
+ 'amount_paid' => $invoice->getGrandTotal(),
592
+ 'base_amount_paid' => $invoice->getBaseGrandTotal(),
593
+ 'shipping_captured' => $invoice->getShippingAmount(),
594
+ 'base_shipping_captured' => $invoice->getBaseShippingAmount(),
595
+ ));
596
+ Mage::dispatchEvent('sales_order_payment_pay', array('payment' => $this, 'invoice' => $invoice));
597
+ return $this;
598
+ }
599
+
600
+ /**
601
+ * Cancel specified invoice: update self totals from it
602
+ *
603
+ * @param Mage_Sales_Model_Order_Invoice $invoice
604
+ * @return Mage_Sales_Model_Order_Payment
605
+ */
606
+ public function cancelInvoice($invoice)
607
+ {
608
+ $this->_updateTotals(array(
609
+ 'amount_paid' => -1 * $invoice->getGrandTotal(),
610
+ 'base_amount_paid' => -1 * $invoice->getBaseGrandTotal(),
611
+ 'shipping_captured' => -1 * $invoice->getShippingAmount(),
612
+ 'base_shipping_captured' => -1 * $invoice->getBaseShippingAmount(),
613
+ ));
614
+ Mage::dispatchEvent('sales_order_payment_cancel_invoice', array('payment' => $this, 'invoice' => $invoice));
615
+ return $this;
616
+ }
617
+
618
+ /**
619
+ * Create new invoice with maximum qty for invoice for each item
620
+ * register this invoice and capture
621
+ *
622
+ * @return Mage_Sales_Model_Order_Invoice
623
+ */
624
+ protected function _invoice()
625
+ {
626
+ $invoice = $this->getOrder()->prepareInvoice();
627
+
628
+ $invoice->register();
629
+ if ($this->getMethodInstance()->canCapture()) {
630
+ $invoice->capture();
631
+ }
632
+
633
+ $this->getOrder()->addRelatedObject($invoice);
634
+ return $invoice;
635
+ }
636
+
637
+ /**
638
+ * Check order payment void availability
639
+ *
640
+ * @return bool
641
+ */
642
+ public function canVoid(Varien_Object $document)
643
+ {
644
+ if (null === $this->_canVoidLookup) {
645
+ $this->_canVoidLookup = (bool)$this->getMethodInstance()->canVoid($document);
646
+ if ($this->_canVoidLookup) {
647
+ $authTransaction = $this->getAuthorizationTransaction();
648
+ $this->_canVoidLookup = (bool)$authTransaction && !(int)$authTransaction->getIsClosed();
649
+ }
650
+ }
651
+ return $this->_canVoidLookup;
652
+ }
653
+
654
+ /**
655
+ * Void payment online
656
+ *
657
+ * @see self::_void()
658
+ * @param Varien_Object $document
659
+ * @return Mage_Sales_Model_Order_Payment
660
+ */
661
+ public function void(Varien_Object $document)
662
+ {
663
+ $this->_void(true);
664
+ Mage::dispatchEvent('sales_order_payment_void', array('payment' => $this, 'invoice' => $document));
665
+ return $this;
666
+ }
667
+
668
+ /**
669
+ * Process void notification
670
+ *
671
+ * @see self::_void()
672
+ * @param float $amount
673
+ * @return Mage_Sales_Model_Payment
674
+ */
675
+ public function registerVoidNotification($amount = null)
676
+ {
677
+ if (!$this->hasMessage()) {
678
+ $this->setMessage(Mage::helper('sales')->__('Registered a Void notification.'));
679
+ }
680
+ return $this->_void(false, $amount);
681
+ }
682
+
683
+ /**
684
+ * Refund payment online or offline, depending on whether there is invoice set in the creditmemo instance
685
+ * Updates transactions hierarchy, if required
686
+ * Updates payment totals, updates order status and adds proper comments
687
+ *
688
+ * @param Mage_Sales_Model_Order_Creditmemo $creditmemo
689
+ * @return Mage_Sales_Model_Order_Payment
690
+ */
691
+ public function refund($creditmemo)
692
+ {
693
+ $baseAmountToRefund = $this->_formatAmount($creditmemo->getBaseGrandTotal());
694
+ $order = $this->getOrder();
695
+
696
+ $this->_generateTransactionId(Mage_Sales_Model_Order_Payment_Transaction::TYPE_REFUND);
697
+
698
+ // call refund from gateway if required
699
+ $isOnline = false;
700
+ $gateway = $this->getMethodInstance();
701
+ $invoice = null;
702
+ if ($gateway->canRefund() && $creditmemo->getDoTransaction()) {
703
+ $this->setCreditmemo($creditmemo);
704
+ $invoice = $creditmemo->getInvoice();
705
+ if ($invoice) {
706
+ $isOnline = true;
707
+ $captureTxn = $this->_lookupTransaction($invoice->getTransactionId());
708
+ if ($captureTxn) {
709
+ $this->setParentTransactionId($captureTxn->getTxnId());
710
+ }
711
+ $this->setShouldCloseParentTransaction(true); // TODO: implement multiple refunds per capture
712
+ try {
713
+ $gateway->setStore($this->getOrder()->getStoreId())
714
+ ->processBeforeRefund($invoice, $this)
715
+ ->refund($this, $baseAmountToRefund)
716
+ ->processCreditmemo($creditmemo, $this)
717
+ ;
718
+ } catch (Mage_Core_Exception $e) {
719
+ if (!$captureTxn) {
720
+ $e->setMessage(' ' . Mage::helper('sales')->__('If the invoice was created offline, try creating an offline creditmemo.'), true);
721
+ }
722
+ throw $e;
723
+ }
724
+ }
725
+ }
726
+
727
+ // update self totals from creditmemo
728
+ $this->_updateTotals(array(
729
+ 'amount_refunded' => $creditmemo->getGrandTotal(),
730
+ 'base_amount_refunded' => $baseAmountToRefund,
731
+ 'base_amount_refunded_online' => $isOnline ? $baseAmountToRefund : null,
732
+ 'shipping_refunded' => $creditmemo->getShippingAmount(),
733
+ 'base_shipping_refunded' => $creditmemo->getBaseShippingAmount(),
734
+ ));
735
+
736
+ // update transactions and order state
737
+ $transaction = $this->_addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_REFUND, $creditmemo, $isOnline);
738
+ if ($invoice) {
739
+ $message = Mage::helper('sales')->__('Refunded amount of %s online.', $this->_formatPrice($baseAmountToRefund));
740
+ } else {
741
+ $message = $this->hasMessage() ? $this->getMessage()
742
+ : Mage::helper('sales')->__('Refunded amount of %s offline.', $this->_formatPrice($baseAmountToRefund));
743
+ }
744
+ $message = $message = $this->_prependMessage($message);
745
+ $message = $this->_appendTransactionToMessage($transaction, $message);
746
+ $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, $message);
747
+
748
+ Mage::dispatchEvent('sales_order_payment_refund', array('payment' => $this, 'creditmemo' => $creditmemo));
749
+ return $this;
750
+ }
751
+
752
+ /**
753
+ * Process payment refund notification
754
+ * Updates transactions hierarchy, if required
755
+ * Prevents transaction double processing
756
+ * Updates payment totals, updates order status and adds proper comments
757
+ * TODO: potentially a full capture can be refunded. In this case if there was only one invoice for that transaction
758
+ * then we should create a creditmemo from invoice and also refund it offline
759
+ * TODO: implement logic of chargebacks reimbursements (via negative amount)
760
+ *
761
+ * @param float $amount
762
+ * @return Mage_Sales_Model_Order_Payment
763
+ */
764
+ public function registerRefundNotification($amount)
765
+ {
766
+ $this->_generateTransactionId(Mage_Sales_Model_Order_Payment_Transaction::TYPE_REFUND,
767
+ $this->_lookupTransaction($this->getParentTransactionId())
768
+ );
769
+ if ($this->_isTransactionExists()) {
770
+ return $this;
771
+ }
772
+ $order = $this->getOrder();
773
+
774
+ // create an offline creditmemo (from order), if the entire grand total of order is covered by this refund
775
+ $creditmemo = null;
776
+ if ($amount == $order->getBaseGrandTotal()) {
777
+ /*
778
+ $creditmemo = $order->prepareCreditmemo()->register()->refund();
779
+ $this->_updateTotals(array(
780
+ 'amount_refunded' => $creditmemo->getGrandTotal(),
781
+ 'shipping_refunded' => $creditmemo->getShippingRefunded(),
782
+ 'base_shipping_refunded' => $creditmemo->getBaseShippingRefunded()
783
+ ));
784
+ $order->addRelatedObject($creditmemo);
785
+ $this->setCreatedCreditmemo($creditmemo);
786
+ */
787
+ }
788
+ $this->_updateTotals(array('base_amount_refunded_online' => $amount));
789
+
790
+ // update transactions and order state
791
+ $transaction = $this->_addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_REFUND, $creditmemo);
792
+ $message = $this->_prependMessage(
793
+ Mage::helper('sales')->__('Registered notification about refunded amount of %s.', $this->_formatPrice($amount))
794
+ );
795
+ $message = $this->_appendTransactionToMessage($transaction, $message);
796
+ $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, $message);
797
+ return $this;
798
+ }
799
+
800
+ /**
801
+ * Cancel a creditmemo: substract its totals from the payment
802
+ *
803
+ * @param Mage_Sales_Model_Order_Creditmemo $creditmemo
804
+ * @return Mage_Sales_Model_Order_Payment
805
+ */
806
+ public function cancelCreditmemo($creditmemo)
807
+ {
808
+ $this->_updateTotals(array(
809
+ 'amount_refunded' => -1 * $creditmemo->getGrandTotal(),
810
+ 'base_amount_refunded' => -1 * $creditmemo->getBaseGrandTotal(),
811
+ 'shipping_refunded' => -1 * $creditmemo->getShippingAmount(),
812
+ 'base_shipping_refunded' => -1 * $creditmemo->getBaseShippingAmount()
813
+ ));
814
+ Mage::dispatchEvent('sales_order_payment_cancel_creditmemo',
815
+ array('payment' => $this, 'creditmemo' => $creditmemo)
816
+ );
817
+ return $this;
818
+ }
819
+
820
+ /**
821
+ * Order cancellation hook for payment method instance
822
+ * Adds void transaction if needed
823
+ * @return Mage_Sales_Model_Order_Payment
824
+ */
825
+ public function cancel()
826
+ {
827
+ $isOnline = true;
828
+ if (!$this->canVoid(new Varien_Object())) {
829
+ $isOnline = false;
830
+ }
831
+
832
+ if (!$this->hasMessage()) {
833
+ $this->setMessage($isOnline ? Mage::helper('sales')->__('Canceled order online.')
834
+ : Mage::helper('sales')->__('Canceled order offline.')
835
+ );
836
+ }
837
+
838
+ if ($isOnline) {
839
+ $this->_void($isOnline, null, 'cancel');
840
+ }
841
+
842
+ Mage::dispatchEvent('sales_order_payment_cancel', array('payment' => $this));
843
+
844
+ return $this;
845
+ }
846
+
847
+ /**
848
+ * Check order payment review availability
849
+ *
850
+ * @return bool
851
+ */
852
+ public function canReviewPayment()
853
+ {
854
+ return (bool)$this->getMethodInstance()->canReviewPayment($this);
855
+ }
856
+
857
+ public function canFetchTransactionInfo()
858
+ {
859
+ return (bool)$this->getMethodInstance()->canFetchTransactionInfo();
860
+ }
861
+
862
+ /**
863
+ * Accept online a payment that is in review state
864
+ *
865
+ * @return Mage_Sales_Model_Order_Payment
866
+ */
867
+ public function accept()
868
+ {
869
+ $this->registerPaymentReviewAction(self::REVIEW_ACTION_ACCEPT, true);
870
+ return $this;
871
+ }
872
+
873
+ /**
874
+ * Accept order with payment method instance
875
+ *
876
+ * @return Mage_Sales_Model_Order_Payment
877
+ */
878
+ public function deny()
879
+ {
880
+ $this->registerPaymentReviewAction(self::REVIEW_ACTION_DENY, true);
881
+ return $this;
882
+ }
883
+
884
+ /**
885
+ * Perform the payment review action: either initiated by merchant or by a notification
886
+ *
887
+ * Sets order to processing state and optionally approves invoice or cancels the order
888
+ *
889
+ * @param string $action
890
+ * @param bool $isOnline
891
+ * @return Mage_Sales_Model_Order_Payment
892
+ */
893
+ public function registerPaymentReviewAction($action, $isOnline)
894
+ {
895
  $order = $this->getOrder();
896
 
897
+ $transactionId = $isOnline ? $this->getLastTransId() : $this->getTransactionId();
898
+ if (!$this->_lookupTransaction($transactionId)) {
899
+ Mage::throwException(Mage::helper('sales')->__('No valid transaction found for this payment review.'));
900
+ }
901
+ $invoice = $this->_getInvoiceForTransactionId($transactionId);
902
+
903
+ // invoke the payment method to determine what to do with the transaction
904
+ $result = null; $message = null;
905
+ switch ($action) {
906
+ case self::REVIEW_ACTION_ACCEPT:
907
+ if ($isOnline) {
908
+ if ($this->getMethodInstance()->setStore($order->getStoreId())->acceptPayment($this)) {
909
+ $result = true;
910
+ $message = Mage::helper('sales')->__('Approved the payment online.');
911
+ } else {
912
+ $result = -1;
913
+ $message = Mage::helper('sales')->__('There is no need to approve this payment.');
914
+ }
915
+ } else {
916
+ $result = (bool)$this->getNotificationResult() ? true : -1;
917
+ $message = Mage::helper('sales')->__('Registered notification about approved payment.');
918
+ }
919
+ break;
920
+ case self::REVIEW_ACTION_DENY:
921
+ if ($isOnline) {
922
+ if ($this->getMethodInstance()->setStore($order->getStoreId())->denyPayment($this)) {
923
+ $result = false;
924
+ $message = Mage::helper('sales')->__('Denied the payment online.');
925
+ } else {
926
+ $result = -1;
927
+ $message = Mage::helper('sales')->__('There is no need to deny this payment.');
928
+ }
929
+ } else {
930
+ $result = (bool)$this->getNotificationResult() ? false : -1;
931
+ $message = Mage::helper('sales')->__('Registered notification about denied payment.');
932
+ }
933
+ break;
934
+ case self::REVIEW_ACTION_UPDATE:
935
+ if ($isOnline) {
936
+ $this->getMethodInstance()->setStore($order->getStoreId())->fetchTransactionInfo($this, $transactionId);
937
+ } else {
938
+ // notification mechanism is responsible to update the payment object first
939
+ }
940
+ if ($this->getIsTransactionApproved()) {
941
+ $result = true;
942
+ $message = Mage::helper('sales')->__('Registered update about approved payment.');
943
+ } elseif ($this->getIsTransactionDenied()) {
944
+ $result = false;
945
+ $message = Mage::helper('sales')->__('Registered update about approved payment.');
946
+ } else {
947
+ $result = -1;
948
+ $message = Mage::helper('sales')->__('There is no update for the payment.');
949
+ }
950
+ break;
951
+ default:
952
+ throw new Exception('Not implemented.');
953
+ }
954
+ $message = $this->_prependMessage($message);
955
+ $message = $this->_appendTransactionToMessage($transactionId, $message);
956
+
957
+ // process payment in case of positive or negative result, or add a comment
958
+ if (-1 === $result) { // switch won't work with such $result!
959
+ $order->addStatusHistoryComment($message);
960
+ } elseif (true === $result) {
961
+ if ($invoice) {
962
+ $invoice->pay();
963
+ $this->_updateTotals(array('base_amount_paid_online' => $invoice->getBaseGrandTotal()));
964
+ $order->addRelatedObject($invoice);
965
+ }
966
+ $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, $message);
967
+ } elseif (false === $result) {
968
+ if ($invoice) {
969
+ $invoice->cancel();
970
+ $order->addRelatedObject($invoice);
971
+ }
972
+ $order->registerCancellation($message, false);
973
+ }
974
+ return $this;
975
+ }
976
+
977
+ /**
978
+ * Authorize payment either online or offline (process auth notification)
979
+ * Updates transactions hierarchy, if required
980
+ * Prevents transaction double processing
981
+ * Updates payment totals, updates order status and adds proper comments
982
+ *
983
+ * @param bool $isOnline
984
+ * @param float $amount
985
+ * @return Mage_Sales_Model_Order_Payment
986
+ */
987
+ protected function _authorize($isOnline, $amount)
988
+ {
989
+ // update totals
990
+ $amount = $this->_formatAmount($amount, true);
991
+ $this->setBaseAmountAuthorized($amount);
992
+
993
+ // do authorization
994
+ $order = $this->getOrder();
995
+ $state = Mage_Sales_Model_Order::STATE_PROCESSING;
996
+ $status = true;
997
+ if ($isOnline) {
998
+
999
+ // invoke authorization on gateway
1000
+ $this->getMethodInstance()->setStore($order->getStoreId())->authorize($this, $amount);
1001
+
1002
+ // similar logic of "payment review" order as in capturing
1003
+ if ($this->getIsTransactionPending()) {
1004
+ $message = Mage::helper('sales')->__('Authorizing amount of %s is pending approval on gateway.', $this->_formatPrice($amount));
1005
+ $state = Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW;
1006
+ if ($this->getIsFraudDetected()) {
1007
+ $status = 'fraud';
1008
+ }
1009
  } else {
1010
+ $message = Mage::helper('sales')->__('Authorized amount of %s.', $this->_formatPrice($amount));
1011
+ }
1012
+ } else {
1013
+ $message = Mage::helper('sales')->__('Registered notification about authorized amount of %s.', $this->_formatPrice($amount));
1014
+ }
1015
+
1016
+ // update transactions, order state and add comments
1017
+ $transaction = $this->_addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH);
1018
+ if ($order->isNominal()) {
1019
+ $message = $this->_prependMessage(Mage::helper('sales')->__('Nominal order registered.'));
1020
+ } else {
1021
+ $message = $this->_prependMessage($message);
1022
+ $message = $this->_appendTransactionToMessage($transaction, $message);
1023
+ }
1024
+ $order->setState($state, $status, $message);
1025
+
1026
+ return $this;
1027
+ }
1028
+
1029
+ /**
1030
+ * Public access to _authorize method
1031
+ * @param bool $isOnline
1032
+ * @param float $amount
1033
+ */
1034
+ public function authorize($isOnline, $amount)
1035
+ {
1036
+ return $this->_authorize($isOnline, $amount);
1037
+ }
1038
+
1039
+ /**
1040
+ * Void payment either online or offline (process void notification)
1041
+ * NOTE: that in some cases authorization can be voided after a capture. In such case it makes sense to use
1042
+ * the amount void amount, for informational purposes.
1043
+ * Updates payment totals, updates order status and adds proper comments
1044
+ *
1045
+ * @param bool $isOnline
1046
+ * @param float $amount
1047
+ * @param string $gatewayCallback
1048
+ * @return Mage_Sales_Model_Order_Payment
1049
+ */
1050
+ protected function _void($isOnline, $amount = null, $gatewayCallback = 'void')
1051
+ {
1052
+ $order = $this->getOrder();
1053
+ $authTransaction = $this->getAuthorizationTransaction();
1054
+ $this->_generateTransactionId(Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID, $authTransaction);
1055
+ $this->setShouldCloseParentTransaction(true);
1056
+
1057
+ // attempt to void
1058
+ if ($isOnline) {
1059
+ $this->getMethodInstance()->setStore($order->getStoreId())->$gatewayCallback($this);
1060
+ }
1061
+ if ($this->_isTransactionExists()) {
1062
+ return $this;
1063
+ }
1064
+
1065
+ // if the authorization was untouched, we may assume voided amount = order grand total
1066
+ // but only if the payment auth amount equals to order grand total
1067
+ if ($authTransaction && ($order->getBaseGrandTotal() == $this->getBaseAmountAuthorized())
1068
+ && (0 == $this->getBaseAmountCanceled())) {
1069
+ if ($authTransaction->canVoidAuthorizationCompletely()) {
1070
+ $amount = (float)$order->getBaseGrandTotal();
1071
+ }
1072
+ }
1073
+
1074
+ if ($amount) {
1075
+ $amount = $this->_formatAmount($amount);
1076
+ }
1077
+
1078
+ // update transactions, order state and add comments
1079
+ $transaction = $this->_addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID);
1080
+ $message = $this->hasMessage() ? $this->getMessage() : Mage::helper('sales')->__('Voided authorization.');
1081
+ $message = $this->_prependMessage($message);
1082
+ if ($amount) {
1083
+ $message .= ' ' . Mage::helper('sales')->__('Amount: %s.', $this->_formatPrice($amount));
1084
+ }
1085
+ $message = $this->_appendTransactionToMessage($transaction, $message);
1086
+ $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, $message);
1087
+ return $this;
1088
+ }
1089
+
1090
+ // /**
1091
+ // * TODO: implement this
1092
+ // * @param Mage_Sales_Model_Order_Invoice $invoice
1093
+ // * @return Mage_Sales_Model_Order_Payment
1094
+ // */
1095
+ // public function cancelCapture($invoice = null)
1096
+ // {
1097
+ // }
1098
+
1099
+ /**
1100
+ * Create transaction, prepare its insertion into hierarchy and add its information to payment and comments
1101
+ *
1102
+ * To add transactions and related information, the following information should be set to payment before processing:
1103
+ * - transaction_id
1104
+ * - is_transaction_closed (optional) - whether transaction should be closed or open (closed by default)
1105
+ * - parent_transaction_id (optional)
1106
+ * - should_close_parent_transaction (optional) - whether to close parent transaction (closed by default)
1107
+ *
1108
+ * If the sales document is specified, it will be linked to the transaction as related for future usage.
1109
+ * Currently transaction ID is set into the sales object
1110
+ * This method writes the added transaction ID into last_trans_id field of the payment object
1111
+ *
1112
+ * To make sure transaction object won't cause trouble before saving, use $failsafe = true
1113
+ *
1114
+ * @param string $type
1115
+ * @param Mage_Sales_Model_Abstract $salesDocument
1116
+ * @param bool $failsafe
1117
+ * @return null|Mage_Sales_Model_Order_Payment_Transaction
1118
+ */
1119
+ protected function _addTransaction($type, $salesDocument = null, $failsafe = false)
1120
+ {
1121
+ // look for set transaction ids
1122
+ $transactionId = $this->getTransactionId();
1123
+ if (null !== $transactionId) {
1124
+ // set transaction parameters
1125
+ $transaction = false;
1126
+ if ($this->getOrder()->getId()) {
1127
+ $transaction = $this->_lookupTransaction($transactionId);
1128
+ }
1129
+ if (!$transaction) {
1130
+ $transaction = Mage::getModel('sales/order_payment_transaction')->setTxnId($transactionId);
1131
+ }
1132
+ $transaction
1133
+ ->setOrderPaymentObject($this)
1134
+ ->setTxnType($type)
1135
+ ->isFailsafe($failsafe);
1136
+
1137
+ if ($this->hasIsTransactionClosed()) {
1138
+ $transaction->setIsClosed((int)$this->getIsTransactionClosed());
1139
+ }
1140
+
1141
+ //set transaction addition information
1142
+ if ($this->_transactionAdditionalInfo) {
1143
+ foreach ($this->_transactionAdditionalInfo as $key => $value) {
1144
+ $transaction->setAdditionalInformation($key, $value);
1145
  }
1146
  }
1147
+
1148
+ // link with sales entities
1149
+ $this->setLastTransId($transactionId);
1150
+ $this->setCreatedTransaction($transaction);
1151
+ $this->getOrder()->addRelatedObject($transaction);
1152
+ if ($salesDocument && $salesDocument instanceof Mage_Sales_Model_Abstract) {
1153
+ $salesDocument->setTransactionId($transactionId);
1154
+ // TODO: linking transaction with the sales document
1155
+ }
1156
+
1157
+ // link with parent transaction
1158
+ $parentTransactionId = $this->getParentTransactionId();
1159
+
1160
+ if ($parentTransactionId) {
1161
+ $transaction->setParentTxnId($parentTransactionId);
1162
+ if ($this->getShouldCloseParentTransaction()) {
1163
+ $parentTransaction = $this->_lookupTransaction($parentTransactionId);
1164
+ if ($parentTransaction) {
1165
+ $parentTransaction->isFailsafe($failsafe)->close(false);
1166
+ $this->getOrder()->addRelatedObject($parentTransaction);
1167
+ }
1168
+ }
1169
+ }
1170
+ return $transaction;
1171
  }
1172
+ }
1173
 
1174
+ /**
1175
+ * Public acces to _addTransaction method
1176
+ *
1177
+ * @param string $type
1178
+ * @param Mage_Sales_Model_Abstract $salesDocument
1179
+ * @param bool $failsafe
1180
+ * @return null|Mage_Sales_Model_Order_Payment_Transaction
1181
+ */
1182
+ public function addTransaction($type, $salesDocument = null, $failsafe = false)
1183
+ {
1184
+ return $this->_addTransaction($type, $salesDocument, $failsafe);
1185
+ }
1186
+
1187
+ /**
1188
+ * Import details data of specified transaction
1189
+ *
1190
+ * @param Mage_Sales_Model_Order_Payment_Transaction $transactionTo
1191
+ * @return Mage_Sales_Model_Order_Payment
1192
+ */
1193
+ public function importTransactionInfo(Mage_Sales_Model_Order_Payment_Transaction $transactionTo)
1194
+ {
1195
+ $data = $this->getMethodInstance()
1196
+ ->setStore($this->getOrder()->getStoreId())
1197
+ ->fetchTransactionInfo($this, $transactionTo->getTxnId());
1198
+ if ($data) {
1199
+ $transactionTo->setAdditionalInformation(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, $data);
1200
+ }
1201
+ return $this;
1202
+ }
1203
+
1204
+ /**
1205
+ * Get the billing agreement, if any
1206
+ *
1207
+ * @return Mage_Sales_Model_Billing_Agreement|null
1208
+ */
1209
+ public function getBillingAgreement()
1210
+ {
1211
+ return $this->_billingAgreement;
1212
+ }
1213
+
1214
+ /**
1215
+ * Totals updater utility method
1216
+ * Updates self totals by keys in data array('key' => $delta)
1217
+ *
1218
+ * @param array $data
1219
+ */
1220
+ protected function _updateTotals($data)
1221
+ {
1222
+ foreach ($data as $key => $amount) {
1223
+ if (null !== $amount) {
1224
+ $was = $this->getDataUsingMethod($key);
1225
+ $this->setDataUsingMethod($key, $was + $amount);
1226
  }
1227
  }
1228
+ }
1229
+
1230
+ /**
1231
+ * Prevent double processing of the same transaction by a payment notification
1232
+ * Uses either specified txn_id or the transaction id that was set before
1233
+ *
1234
+ * @deprecated after 1.4.0.1
1235
+ * @param string $txnId
1236
+ * @throws Mage_Core_Exception
1237
+ */
1238
+ protected function _avoidDoubleTransactionProcessing($txnId = null)
1239
+ {
1240
+ if ($this->_isTransactionExists($txnId)) {
1241
+ Mage::throwException(
1242
+ Mage::helper('sales')->__('Transaction "%s" was already processed.', $txnId)
1243
+ );
1244
+ }
1245
+ }
1246
+
1247
+ /**
1248
+ * Check transaction existence by specified transaction id
1249
+ *
1250
+ * @param string $txnId
1251
+ * @return boolean
1252
+ */
1253
+ protected function _isTransactionExists($txnId = null)
1254
+ {
1255
+ if (null === $txnId) {
1256
+ $txnId = $this->getTransactionId();
1257
+ }
1258
+ return $txnId && $this->_lookupTransaction($txnId);
1259
+ }
1260
+
1261
+ /**
1262
+ * Append transaction ID (if any) message to the specified message
1263
+ *
1264
+ * @param Mage_Sales_Model_Order_Payment_Transaction|null $transaction
1265
+ * @param string $message
1266
+ * @return string
1267
+ */
1268
+ protected function _appendTransactionToMessage($transaction, $message)
1269
+ {
1270
+ if ($transaction) {
1271
+ $txnId = is_object($transaction) ? $transaction->getTxnId() : $transaction;
1272
+ $message .= ' ' . Mage::helper('sales')->__('Transaction ID: "%s".', $txnId);
1273
+ }
1274
+ return $message;
1275
+ }
1276
+
1277
+ /**
1278
+ * Prepend a "prepared_message" that may be set to the payment instance before, to the specified message
1279
+ * Prepends value to the specified string or to the comment of specified order status history item instance
1280
+ *
1281
+ * @param string|Mage_Sales_Model_Order_Status_History $messagePrependTo
1282
+ * @return string|Mage_Sales_Model_Order_Status_History
1283
+ */
1284
+ protected function _prependMessage($messagePrependTo)
1285
+ {
1286
+ $preparedMessage = $this->getPreparedMessage();
1287
+ if ($preparedMessage) {
1288
+ if (is_string($preparedMessage)) {
1289
+ return $preparedMessage . ' ' . $messagePrependTo;
1290
+ }
1291
+ elseif (is_object($preparedMessage) && ($preparedMessage instanceof Mage_Sales_Model_Order_Status_History)) {
1292
+ $comment = $preparedMessage->getComment() . ' ' . $messagePrependTo;
1293
+ $preparedMessage->setComment($comment);
1294
+ return $comment;
1295
+ }
1296
+ }
1297
+ return $messagePrependTo;
1298
+ }
1299
+
1300
+ /**
1301
+ * Round up and cast specified amount to float or string
1302
+ *
1303
+ * @param string|float $amount
1304
+ * @param bool $asFloat
1305
+ * @return string|float
1306
+ */
1307
+ protected function _formatAmount($amount, $asFloat = false)
1308
+ {
1309
+ $amount = sprintf('%.2F', $amount); // "f" depends on locale, "F" doesn't
1310
+ return $asFloat ? (float)$amount : $amount;
1311
+ }
1312
+
1313
+ /**
1314
+ * Format price with currency sign
1315
+ * @param float $amount
1316
+ * @return string
1317
+ */
1318
+ protected function _formatPrice($amount)
1319
+ {
1320
+ return $this->getOrder()->getBaseCurrency()->formatTxt($amount);
1321
+ }
1322
+
1323
+ /**
1324
+ * Find one transaction by ID or type
1325
+ * @param string $txnId
1326
+ * @param string $txnType
1327
+ * @return Mage_Sales_Model_Order_Payment_Transaction|false
1328
+ */
1329
+ protected function _lookupTransaction($txnId, $txnType = false)
1330
+ {
1331
+ if (!$txnId) {
1332
+ if ($txnType && $this->getId()) {
1333
+ $collection = Mage::getModel('sales/order_payment_transaction')->getCollection()
1334
+ ->setOrderFilter($this->getOrder())
1335
+ ->addPaymentIdFilter($this->getId())
1336
+ ->addTxnTypeFilter($txnType);
1337
+ foreach ($collection as $txn) {
1338
+ $txn->setOrderPaymentObject($this);
1339
+ $this->_transactionsLookup[$txn->getTxnId()] = $txn;
1340
+ return $txn;
1341
+ }
1342
  }
1343
+ return false;
1344
  }
1345
+ if (isset($this->_transactionsLookup[$txnId])) {
1346
+ return $this->_transactionsLookup[$txnId];
 
 
1347
  }
1348
+ $txn = Mage::getModel('sales/order_payment_transaction')
1349
+ ->setOrderPaymentObject($this)
1350
+ ->loadByTxnId($txnId);
1351
+ if ($txn->getId()) {
1352
+ $this->_transactionsLookup[$txnId] = $txn;
1353
+ } else {
1354
+ $this->_transactionsLookup[$txnId] = false;
1355
  }
1356
+ return $this->_transactionsLookup[$txnId];
1357
+ }
1358
 
1359
+ /**
1360
+ * Lookup an authorization transaction using parent transaction id, if set
1361
+ * @return Mage_Sales_Model_Order_Payment_Transaction|false
1362
+ */
1363
+ public function getAuthorizationTransaction()
1364
+ {
1365
+ if ($this->getParentTransactionId()) {
1366
+ $txn = $this->_lookupTransaction($this->getParentTransactionId());
1367
+ } else {
1368
+ $txn = false;
1369
+ }
1370
+
1371
+ if (!$txn) {
1372
+ $txn = $this->_lookupTransaction(false, Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH);
1373
+ }
1374
+ return $txn;
1375
+ }
1376
+
1377
+ /**
1378
+ * Lookup the transaction by id
1379
+ * @param string $transactionId
1380
+ * @return Mage_Sales_Model_Order_Payment_Transaction|false
1381
+ */
1382
+ public function getTransaction($transactionId)
1383
+ {
1384
+ return $this->_lookupTransaction($transactionId);
1385
+ }
1386
+
1387
+ /**
1388
+ * Update transaction ids for further processing
1389
+ * If no transactions were set before invoking, may generate an "offline" transaction id
1390
+ *
1391
+ * @param string $type
1392
+ * @param Mage_Sales_Model_Order_Payment_Transaction $transactionBasedOn
1393
+ */
1394
+ protected function _generateTransactionId($type, $transactionBasedOn = false)
1395
+ {
1396
+ if (!$this->getParentTransactionId() && !$this->getTransactionId() && $transactionBasedOn) {
1397
+ $this->setParentTransactionId($transactionBasedOn->getTxnId());
1398
+ }
1399
+ // generate transaction id for an offline action or payment method that didn't set it
1400
+ if (($parentTxnId = $this->getParentTransactionId()) && !$this->getTransactionId()) {
1401
+ $this->setTransactionId("{$parentTxnId}-{$type}");
1402
+ }
1403
+ }
1404
+
1405
+ /**
1406
+ * Decide whether authorization transaction may close (if the amount to capture will cover entire order)
1407
+ * @param float $amountToCapture
1408
+ * @return bool
1409
+ */
1410
+ protected function _isCaptureFinal($amountToCapture)
1411
+ {
1412
+ $orderGrandTotal = sprintf('%.4F', $this->getOrder()->getBaseGrandTotal());
1413
+ if ($orderGrandTotal == sprintf('%.4F', ($this->getBaseAmountPaidOnline() + $amountToCapture))) {
1414
+ if (false !== $this->getShouldCloseParentTransaction()) {
1415
+ $this->setShouldCloseParentTransaction(true);
1416
+ }
1417
+ return true;
1418
+ }
1419
+ return false;
1420
+ }
1421
+
1422
+ /**
1423
+ * Before object save manipulations
1424
+ *
1425
+ * @return Mage_Sales_Model_Order_Payment
1426
+ */
1427
+ protected function _beforeSave()
1428
+ {
1429
+ parent::_beforeSave();
1430
+
1431
+ if (!$this->getParentId() && $this->getOrder()) {
1432
+ $this->setParentId($this->getOrder()->getId());
1433
+ }
1434
 
1435
  return $this;
1436
  }
1437
+
1438
+ /**
1439
+ * Generate billing agreement object if there is billing agreement data
1440
+ * Adds it to order as related object
1441
+ */
1442
+ protected function _createBillingAgreement()
1443
+ {
1444
+ if ($this->getBillingAgreementData()) {
1445
+ $order = $this->getOrder();
1446
+ $agreement = Mage::getModel('sales/billing_agreement')->importOrderPayment($this);
1447
+ if ($agreement->isValid()) {
1448
+ $message = Mage::helper('sales')->__('Created billing agreement #%s.', $agreement->getReferenceId());
1449
+ $order->addRelatedObject($agreement);
1450
+ $this->_billingAgreement = $agreement;
1451
+ } else {
1452
+ $message = Mage::helper('sales')->__('Failed to create billing agreement for this order.');
1453
+ }
1454
+ $comment = $order->addStatusHistoryComment($message);
1455
+ $order->addRelatedObject($comment);
1456
+ }
1457
+ }
1458
+
1459
+ /**
1460
+ * Additionnal transaction info setter
1461
+ *
1462
+ * @param sting $key
1463
+ * @param string $value
1464
+ */
1465
+ public function setTransactionAdditionalInfo($key, $value)
1466
+ {
1467
+ $this->_transactionAdditionalInfo[$key] = $value;
1468
+ }
1469
+
1470
+ /**
1471
+ * Return invoice model for transaction
1472
+ *
1473
+ * @param string $transactionId
1474
+ * @return Mage_Sales_Model_Order_Invoice
1475
+ */
1476
+ protected function _getInvoiceForTransactionId($transactionId)
1477
+ {
1478
+ foreach ($this->getOrder()->getInvoiceCollection() as $invoice) {
1479
+ if ($invoice->getTransactionId() == $transactionId) {
1480
+ $invoice->load($invoice->getId()); // to make sure all data will properly load (maybe not required)
1481
+ return $invoice;
1482
+ }
1483
+ }
1484
+ return false;
1485
+ }
1486
  }
app/code/local/Cardsave/Sales/Model/Service/Quote.php CHANGED
@@ -4,84 +4,88 @@ class Cardsave_Sales_Model_Service_Quote extends Mage_Sales_Model_Service_Quote
4
  {
5
  public function submitOrder()
6
  {
7
- if ($this->_quote->getPayment()->getMethodInstance()->getCode() != 'cardsaveonlinepayments')
8
- {
9
- return parent::submitOrder();
10
- }
11
-
12
- $this->_deleteNominalItems();
13
- $this->_validate();
14
- $quote = $this->_quote;
15
- $isVirtual = $quote->isVirtual();
16
-
17
- $transaction = Mage::getModel('core/resource_transaction');
18
- if ($quote->getCustomerId())
19
- {
20
- $transaction->addObject($quote->getCustomer());
21
- }
22
- $transaction->addObject($quote);
23
-
24
- $quote->reserveOrderId();
25
- if ($isVirtual)
26
- {
27
- $order = $this->_convertor->addressToOrder($quote->getBillingAddress());
28
- }
29
- else
30
- {
31
- $order = $this->_convertor->addressToOrder($quote->getShippingAddress());
32
- }
33
- $order->setBillingAddress($this->_convertor->addressToOrderAddress($quote->getBillingAddress()));
34
-
35
- if (!$isVirtual)
36
- {
37
- $order->setShippingAddress($this->_convertor->addressToOrderAddress($quote->getShippingAddress()));
38
- }
39
- $order->setPayment($this->_convertor->paymentToOrderPayment($quote->getPayment()));
40
-
41
- foreach ($this->_orderData as $key => $value)
42
- {
43
- $order->setData($key, $value);
44
- }
45
-
46
- foreach ($quote->getAllItems() as $item)
47
- {
48
- $orderItem = $this->_convertor->itemToOrderItem($item);
49
- if ($item->getParentItem())
50
- {
51
- $orderItem->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId()));
52
- }
53
- $order->addItem($orderItem);
54
- }
55
- $quote->setIsActive(false);
56
-
57
- $transaction->addObject($order);
58
- $transaction->addCommitCallback(array($order, 'place'));
59
- $transaction->addCommitCallback(array($order, 'save'));
60
-
61
- /**
62
- * We can use configuration data for declare new order status
63
- */
64
- Mage::dispatchEvent('checkout_type_onepage_save_order', array('order'=>$order, 'quote'=>$quote));
65
- Mage::dispatchEvent('sales_model_service_quote_submit_before', array('order'=>$order, 'quote'=>$quote));
66
- try
67
- {
68
- $transaction->save();
69
- Mage::dispatchEvent('sales_model_service_quote_submit_success', array('order'=>$order, 'quote'=>$quote));
70
-
71
- // need to store the orderID in the session for the callback from an external page
72
- Mage::getSingleton('checkout/session')->setCardsaveonlinepaymentsOrderId($order->getId());
73
-
74
- }
75
- catch (Exception $e)
76
- {
77
- Mage::logException($e);
78
- Mage::dispatchEvent('sales_model_service_quote_submit_failure', array('order'=>$order, 'quote'=>$quote));
79
- throw $e;
80
- }
81
- Mage::dispatchEvent('sales_model_service_quote_submit_after', array('order'=>$order, 'quote'=>$quote));
82
- $this->_order = $order;
83
-
84
- return $order;
 
 
 
 
 
85
  }
86
-
87
  }
4
  {
5
  public function submitOrder()
6
  {
7
+ $nVersion = Mage::getModel('cardsaveonlinepayments/direct')->getVersion();
8
+
9
+ if($nVersion >= 1410)
10
+ {
11
+ if ($this->_quote->getPayment()->getMethodInstance()->getCode() != 'cardsaveonlinepayments')
12
+ {
13
+ return parent::submitOrder();
14
+ }
15
+
16
+ $this->_deleteNominalItems();
17
+ $this->_validate();
18
+ $quote = $this->_quote;
19
+ $isVirtual = $quote->isVirtual();
20
+
21
+ $transaction = Mage::getModel('core/resource_transaction');
22
+ if ($quote->getCustomerId())
23
+ {
24
+ $transaction->addObject($quote->getCustomer());
25
+ }
26
+ $transaction->addObject($quote);
27
+
28
+ $quote->reserveOrderId();
29
+ if ($isVirtual)
30
+ {
31
+ $order = $this->_convertor->addressToOrder($quote->getBillingAddress());
32
+ }
33
+ else
34
+ {
35
+ $order = $this->_convertor->addressToOrder($quote->getShippingAddress());
36
+ }
37
+ $order->setBillingAddress($this->_convertor->addressToOrderAddress($quote->getBillingAddress()));
38
+
39
+ if (!$isVirtual)
40
+ {
41
+ $order->setShippingAddress($this->_convertor->addressToOrderAddress($quote->getShippingAddress()));
42
+ }
43
+ $order->setPayment($this->_convertor->paymentToOrderPayment($quote->getPayment()));
44
+
45
+ foreach ($this->_orderData as $key => $value)
46
+ {
47
+ $order->setData($key, $value);
48
+ }
49
+
50
+ foreach ($quote->getAllItems() as $item)
51
+ {
52
+ $orderItem = $this->_convertor->itemToOrderItem($item);
53
+ if ($item->getParentItem())
54
+ {
55
+ $orderItem->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId()));
56
+ }
57
+ $order->addItem($orderItem);
58
+ }
59
+ $quote->setIsActive(false);
60
+
61
+ $transaction->addObject($order);
62
+ $transaction->addCommitCallback(array($order, 'place'));
63
+ $transaction->addCommitCallback(array($order, 'save'));
64
+
65
+ /**
66
+ * We can use configuration data for declare new order status
67
+ */
68
+ Mage::dispatchEvent('checkout_type_onepage_save_order', array('order'=>$order, 'quote'=>$quote));
69
+ Mage::dispatchEvent('sales_model_service_quote_submit_before', array('order'=>$order, 'quote'=>$quote));
70
+ try
71
+ {
72
+ $transaction->save();
73
+ Mage::dispatchEvent('sales_model_service_quote_submit_success', array('order'=>$order, 'quote'=>$quote));
74
+
75
+ // need to store the orderID in the session for the callback from an external page
76
+ Mage::getSingleton('checkout/session')->setCardsaveonlinepaymentsOrderId($order->getId());
77
+
78
+ }
79
+ catch (Exception $e)
80
+ {
81
+ Mage::logException($e);
82
+ Mage::dispatchEvent('sales_model_service_quote_submit_failure', array('order'=>$order, 'quote'=>$quote));
83
+ throw $e;
84
+ }
85
+ Mage::dispatchEvent('sales_model_service_quote_submit_after', array('order'=>$order, 'quote'=>$quote));
86
+ $this->_order = $order;
87
+
88
+ return $order;
89
+ }
90
  }
 
91
  }
app/design/adminhtml/base/default/template/cardsaveonlinepayments/form.phtml ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $direct = Mage::getModel('cardsaveonlinepayments/direct'); ?>
2
+ <?php if ($direct->getConfigData('mode') == Cardsave_Cardsaveonlinepayments_Model_Source_PaymentMode::PAYMENT_MODE_HOSTED_PAYMENT_FORM) {?>
3
+ <fieldset class="form-list">
4
+ <?php $_code=$this->getMethodCode() ?>
5
+ <ul id="payment_form_<?php echo $_code ?>" style="display:none">
6
+ <li>
7
+ <?php echo $this->__('You will be redirected to a secure page where you can complete your payment.') ?>
8
+ </li>
9
+ </ul>
10
+ </fieldset>
11
+ <?php } else {?>
12
+ <fieldset class="form-list">
13
+ <?php $_code = $this->getMethodCode(); ?>
14
+ <ul id="payment_form_<?php echo $_code; ?>" style="display:none">
15
+ <li>
16
+ <div class="input-box">
17
+ <label for="<?php echo $_code; ?>_cc_owner"><?php echo $this->__('Name On Card') ?> <span class="required">*</span></label><br/>
18
+ <input type="text" title="<?php echo $this->__('Name On Card') ?>" class="required-entry input-text" id="<?php echo $_code; ?>_cc_owner" name="payment[cc_owner]" value="<?php echo $this->htmlEscape($this->getInfoData('cc_owner')) ?>"/>
19
+ </div>
20
+ </li>
21
+ <li>
22
+ <div class="input-box">
23
+ <label for="<?php echo $_code; ?>_cc_number"><?php echo $this->__('Card Number') ?> <span class="required">*</span></label><br/>
24
+ <input type="text" id="<?php echo $_code; ?>_cc_number" name="payment[cc_number]" title="<?php echo $this->__('Card Number') ?>" class="required-entry input-text" value=""/>
25
+ </div>
26
+ </li>
27
+ <li>
28
+ <div class="input-box">
29
+ <label for="<?php echo $_code; ?>_expiration"><?php echo $this->__('Expiration Date') ?> <span class="required">*</span></label><br/>
30
+ <div class="v-fix">
31
+ <select id="<?php echo $_code; ?>_expiration" style="width:140px;" name="payment[cc_exp_month]" class="required-entry">
32
+ <?php $_ccExpMonth = $this->getInfoData('cc_exp_month') ?>
33
+ <?php foreach ($this->getCcMonths() as $k=>$v): ?>
34
+ <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccExpMonth): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
35
+ <?php endforeach ?>
36
+ </select>
37
+ </div>
38
+
39
+ <div class="v-fix" style="padding-left:5px;">
40
+ <?php $_ccExpYear = $this->getInfoData('cc_exp_year') ?>
41
+ <select id="<?php echo $_code; ?>_expiration_yr" style="width:103px;" name="payment[cc_exp_year]" class="required-entry">
42
+ <?php foreach ($this->getCcYears() as $k=>$v): ?>
43
+ <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccExpYear): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
44
+ <?php endforeach ?>
45
+ </select>
46
+ </div>
47
+ </div>
48
+ </li>
49
+ <li>
50
+ <div class="input-box">
51
+ <label for="<?php echo $_code; ?>_cc_ss_start_month"><?php echo $this->__('Start Date') ?></label><br />
52
+ <div class="v-fix">
53
+ <select id="<?php echo $_code; ?>_cc_ss_start_month" style="width:140px;" name="payment[cc_ss_start_month]" class="validate-cc-start">
54
+ <?php $_ccStartMonth = $this->getInfoData('cc_ss_start_month') ?>
55
+ <?php foreach ($this->getCcStartMonths() as $k=>$v): ?>
56
+ <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccStartMonth): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
57
+ <?php endforeach ?>
58
+ </select>
59
+ </div>
60
+ <div class="v-fix" style="padding-left:5px;">
61
+ <?php $_ccStartYear = $this->getInfoData('cc_ss_start_year') ?>
62
+ <select id="<?php echo $_code ?>_cc_ss_start_year" style="width:103px;" name="payment[cc_ss_start_year]">
63
+ <?php foreach ($this->getCcStartYears() as $k=>$v): ?>
64
+ <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccStartYear): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
65
+ <?php endforeach ?>
66
+ </select>
67
+ </div>
68
+ </div>
69
+ </li>
70
+ <li>
71
+ <div class="input-box">
72
+ <label for="<?php echo $_code; ?>_cc_ss_issue"><?php echo $this->__('Issue Number') ?></label><br />
73
+ <div class="v-fix"><input type="text" title="<?php echo $this->__('Issue Number') ?>" class="input-text" id="<?php echo $_code ?>_cc_ss_issue" name="payment[cc_ss_issue]" style="width:3em;" value="" /></div>
74
+ </div>
75
+ </li>
76
+ <li>
77
+ <div class="input-box">
78
+ <label for="<?php echo $_code; ?>_cc_cid"><?php echo $this->__('CV2') ?> <span class="required">*</span></label><br/>
79
+ <div class="v-fix"><input type="text" title="<?php echo $this->__('CV2') ?>" class="required-entry input-text" id="<?php echo $_code; ?>_cc_cid" name="payment[cc_cid]" style="width:3em;" value=""/></div>
80
+ &nbsp;
81
+ <a href="#" class="cvv-what-is-this"><?php echo $this->__('What is this?') ?></a>
82
+ </div>
83
+ </li>
84
+ </ul>
85
+ </fieldset>
86
+ <?php }?>
app/design/adminhtml/base/default/template/cardsaveonlinepayments/info.phtml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $direct = Mage::getModel('cardsaveonlinepayments/direct'); ?>
2
+ <?php if ($direct->getConfigData('mode') != Cardsave_Cardsaveonlinepayments_Model_Source_PaymentMode::PAYMENT_MODE_DIRECT_API) {?>
3
+ <?php if ($direct->getConfigData('mode') == Cardsave_Cardsaveonlinepayments_Model_Source_PaymentMode::PAYMENT_MODE_HOSTED_PAYMENT_FORM) {?>
4
+ <?php echo $this->__('You will be redirected to a secure payment page'); ?>
5
+ <?php } else {?>
6
+ <?php echo $this->__('No card information is available'); ?>
7
+ <?php }?>
8
+ <?php } else {?>
9
+ <?php if($_info = $this->getInfo()): ?>
10
+ <?php echo $this->__('Name on the Card: %s', $this->htmlEscape($this->getInfo()->getCcOwner())) ?>
11
+ <br/>
12
+ <?php echo $this->__('Card Number: %s', $this->htmlEscape($this->getCcNumber())) ?>
13
+ <br/>
14
+ <?php echo $this->__('Expiration Date: %s/%s', $this->htmlEscape($this->getInfo()->getCcExpMonth()), $this->htmlEscape($this->getInfo()->getCcExpYear())) ?>
15
+ <br />
16
+ <?php else: ?>
17
+ <?php endif; ?>
18
+ <?php }?>
app/design/frontend/base/default/template/cardsaveonlinepayments/form.phtml ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $direct = Mage::getModel('cardsaveonlinepayments/direct'); ?>
2
+ <?php if ($direct->getConfigData('mode') == Cardsave_Cardsaveonlinepayments_Model_Source_PaymentMode::PAYMENT_MODE_HOSTED_PAYMENT_FORM) {?>
3
+ <fieldset class="form-list">
4
+ <?php $_code=$this->getMethodCode() ?>
5
+ <ul id="payment_form_<?php echo $_code ?>" style="display:none">
6
+ <li>
7
+ <img alt="<?php echo $this->__('CardSave Online Payment Logo'); ?>" src="<?php echo $this->getSkinUrl('images/cardsave_online.jpg'); ?>">
8
+ </li>
9
+ <li>
10
+ <?php echo $this->__('You will be redirected to a secure page where you can complete your payment.') ?>
11
+ </li>
12
+ </ul>
13
+ </fieldset>
14
+ <?php } else {?>
15
+ <fieldset class="form-list">
16
+ <?php $_code = $this->getMethodCode(); ?>
17
+ <ul id="payment_form_<?php echo $_code; ?>" style="display:none">
18
+ <li>
19
+ <img alt="<?php echo $this->__('CardSave Online Payment Logo'); ?>" src="<?php echo $this->getSkinUrl('images/cardsave_online.jpg'); ?>">
20
+ </li>
21
+ <li>
22
+ <div class="input-box">
23
+ <label for="<?php echo $_code; ?>_cc_owner"><?php echo $this->__('Name On Card') ?> <span class="required">*</span></label><br/>
24
+ <input type="text" title="<?php echo $this->__('Name On Card') ?>" class="required-entry input-text" id="<?php echo $_code; ?>_cc_owner" name="payment[cc_owner]" value="<?php echo $this->htmlEscape($this->getInfoData('cc_owner')) ?>"/>
25
+ </div>
26
+ </li>
27
+ <li>
28
+ <div class="input-box">
29
+ <label for="<?php echo $_code; ?>_cc_number"><?php echo $this->__('Card Number') ?> <span class="required">*</span></label><br/>
30
+ <input type="text" id="<?php echo $_code; ?>_cc_number" name="payment[cc_number]" title="<?php echo $this->__('Card Number') ?>" class="required-entry input-text" value=""/>
31
+ </div>
32
+ </li>
33
+ <li>
34
+ <div class="input-box">
35
+ <label for="<?php echo $_code; ?>_expiration"><?php echo $this->__('Expiry Date') ?> <span class="required">*</span></label><br/>
36
+ <div class="v-fix">
37
+ <select id="<?php echo $_code; ?>_expiration" style="width:140px;" name="payment[cc_exp_month]" class="required-entry">
38
+ <?php $_ccExpMonth = $this->getInfoData('cc_exp_month') ?>
39
+ <?php foreach ($this->getCcMonths() as $k=>$v): ?>
40
+ <option value="<?php echo $k?$k:'' ?>" <?php if($k==$_ccExpMonth): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
41
+ <?php endforeach ?>
42
+ </select>
43
+ </div>
44
+
45
+ <div class="v-fix" style="padding-left:5px;">
46
+ <?php $_ccExpYear = $this->getInfoData('cc_exp_year') ?>
47
+ <select id="<?php echo $_code; ?>_expiration_yr" style="width:103px;" name="payment[cc_exp_year]" class="required-entry">
48
+ <?php foreach ($this->getCcYears() as $k=>$v): ?>
49
+ <option value="<?php echo $k?$k:'' ?>" <?php if($k==$_ccExpYear): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
50
+ <?php endforeach ?>
51
+ </select>
52
+ </div>
53
+ </div>
54
+ </li>
55
+ <li>
56
+ <div class="input-box">
57
+ <label for="<?php echo $_code; ?>_cc_ss_start_month"><?php echo $this->__('Start Date') ?></label><br />
58
+ <div class="v-fix">
59
+ <select id="<?php echo $_code; ?>_cc_ss_start_month" style="width:140px;" name="payment[cc_ss_start_month]" class="validate-cc-start">
60
+ <?php $_ccStartMonth = $this->getInfoData('cc_ss_start_month') ?>
61
+ <?php foreach ($this->getCcStartMonths() as $k=>$v): ?>
62
+ <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccStartMonth): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
63
+ <?php endforeach ?>
64
+ </select>
65
+ </div>
66
+ <div class="v-fix" style="padding-left:5px;">
67
+ <?php $_ccStartYear = $this->getInfoData('cc_ss_start_year') ?>
68
+ <select id="<?php echo $_code ?>_cc_ss_start_year" style="width:103px;" name="payment[cc_ss_start_year]">
69
+ <?php foreach ($this->getCcStartYears() as $k=>$v): ?>
70
+ <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccStartYear): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
71
+ <?php endforeach ?>
72
+ </select>
73
+ </div>
74
+ </div>
75
+ </li>
76
+ <li>
77
+ <div class="input-box">
78
+ <label for="<?php echo $_code; ?>_cc_ss_issue"><?php echo $this->__('Issue Number') ?></label><br />
79
+ <div class="v-fix"><input type="text" title="<?php echo $this->__('Issue Number') ?>" class="input-text" id="<?php echo $_code ?>_cc_ss_issue" name="payment[cc_ss_issue]" style="width:3em;" value="" /></div>
80
+ </div>
81
+ </li>
82
+ <li>
83
+ <div class="input-box">
84
+ <label for="<?php echo $_code; ?>_cc_cid"><?php echo $this->__('CV2') ?> <span class="required">*</span></label><br/>
85
+ <div class="v-fix"><input type="text" title="<?php echo $this->__('CV2') ?>" class="required-entry input-text" id="<?php echo $_code; ?>_cc_cid" name="payment[cc_cid]" style="width:3em;" value=""/></div>
86
+ &nbsp;
87
+ <a href="#" class="cvv-what-is-this"><?php echo $this->__('What is this?') ?></a>
88
+ </div>
89
+ </li>
90
+ </ul>
91
+ </fieldset>
92
+ <?php }?>
app/design/frontend/base/default/template/cardsaveonlinepayments/info.phtml ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $direct = Mage::getModel('cardsaveonlinepayments/direct'); ?>
2
+ <?php if ($direct->getConfigData('mode') != Cardsave_Cardsaveonlinepayments_Model_Source_PaymentMode::PAYMENT_MODE_DIRECT_API) {?>
3
+ <?php if ($direct->getConfigData('mode') == Cardsave_Cardsaveonlinepayments_Model_Source_PaymentMode::PAYMENT_MODE_HOSTED_PAYMENT_FORM) {?>
4
+ <?php echo $this->__('You will be redirected to a secure payment page'); ?>
5
+ <?php } else {?>
6
+ <?php echo $this->__('No card information is available'); ?>
7
+ <?php }?>
8
+ <?php } else {?>
9
+ <?php if($_info = $this->getInfo()): ?>
10
+ <?php echo $this->__('Name on the Card: %s', $this->htmlEscape($this->getInfo()->getCcOwner())) ?>
11
+ <br/>
12
+ <?php echo $this->__('Card Number: xxxx-%s', $this->htmlEscape($this->getInfo()->getCcLast4())) ?>
13
+ <br/>
14
+ <?php echo $this->__('Expiration Date: %s/%s', $this->htmlEscape($this->getInfo()->getCcExpMonth()), $this->htmlEscape($this->getInfo()->getCcExpYear())) ?>
15
+ <?php else: ?>
16
+ <?php endif; ?>
17
+ <?php }?>
package.xml CHANGED
@@ -1,21 +1,25 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Cardsave_Cardsaveonlinepayments</name>
4
- <version>1.8.6</version>
5
  <stability>stable</stability>
6
  <license>OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
- <summary>Cardsave payment extension compatible with Magento v 1.4.0 and 1.4.1</summary>
10
- <description>Fully supports 3D secure transactions. Also supports all of the integration methods provided by Cardsave. Compatible with the following Magento versions:
11
- 1.4.0.0
 
 
 
12
  1.4.1.0
13
- 1.4.1.1</description>
14
- <notes>Secure URL fix for 3D Secure payments</notes>
 
15
  <authors><author><name>cardsave.support</name><user>auto-converted</user><email>integrationsupport@cardsaveonlinepayments.com</email></author></authors>
16
- <date>2011-01-18</date>
17
- <time>12:21:54</time>
18
- <contents><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="cardsaveonlinepayments"><file name="form.phtml" hash="2b0b8a72c9f4a6d2ab9f0ea020c8f2ed"/><file name="info.phtml" hash="935e10cad0632d558b2db1913cb80a2a"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="template"><dir name="cardsaveonlinepayments"><file name="form.phtml" hash="206c8703ef4d160dfc6c739c128ab47b"/><file name="info.phtml" hash="7256464904bbad66a821dea898d657a6"/></dir></dir></dir></dir></dir></target><target name="magelocal"><dir name="Cardsave"><dir name="Cardsaveonlinepayments"><dir name="Block"><file name="Error.php" hash="660d3cbde48910ef271df9e05130a6d7"/><file name="Form.php" hash="ea5b3817c9607a94f4685d53d0b18569"/><file name="Info.php" hash="57a4bfec1a1c769de063be2b922f4a97"/><file name="Redirect.php" hash="b5a1f7af807dc9a41ec5b9db5c74e87e"/><file name="Threedsecure.php" hash="9d75776f34c5acaf6ea265f35f302c69"/></dir><dir name="controllers"><file name="PaymentController.php" hash="a6fb22263b53965234514d1825915428"/></dir><dir name="etc"><file name="config.xml" hash="14507a95509d6366272555a05ba110c9"/><file name="system.xml" hash="4d0eab1c1a11d3e2078802499ad49f1e"/></dir><dir name="Helper"><file name="Data.php" hash="e024ec0479d1e8e7efcf4751b05194d6"/></dir><dir name="Model"><dir name="Common"><dir name="ThePaymentGateway"><file name="PaymentSystem.php" hash="e4d4df170c21b7e3571b3ba1205ca979"/><file name="SOAP.php" hash="a0e5474dce51dc90ba4d37b5de3cdd84"/><file name="TPG_Common.php" hash="d86997c977cfd55b8ab577a514ab149c"/></dir><file name="GlobalErrors.php" hash="04d277d4a763efa508bf36d29c7dc8c4"/><file name="ISOCountries.php" hash="78dc558da68ca9a6ef44898a3980ecf2"/><file name="ISOCurrencies.php" hash="a32bc47b2d9896c293ecdcbf847144f9"/><file name="PaymentFormHelper.php" hash="75d4ea669fae3eb62df24c45f83a5a60"/></dir><dir name="Source"><file name="HashMethod.php" hash="997928579b69d21ae9eebec698c715c6"/><file name="OrderStatus.php" hash="4c44f8ba1652f20d934aa200ed4c8d00"/><file name="PaymentAction.php" hash="fa94be37c18bbb2f6301bdad1db3698d"/><file name="PaymentMode.php" hash="ea8af602bd09d54a123af64bc4b680d0"/><file name="ResultDeliveryMethod.php" hash="afb838319df715e604173d6aa143feab"/></dir><file name="Direct.php" hash="ba78fc3be3cd8a5442cd1932baee1aac"/><file name="Request.php" hash="370f028086d13ae1df470e93a67dea66"/></dir></dir><dir name="Checkout"><dir name="Block"><dir name="Onepage"><dir name="Payment"><file name="Methods.php" hash="695d628564f6e1e0c85e3821699e6b45"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="9dbd58b6b32491d65e5c7d5850aa3420"/></dir><dir name="Model"><dir name="Type"><file name="Onepage.php" hash="e3d27996d67ced85884ab3dbd9dd1199"/></dir></dir></dir><dir name="Sales"><dir name="etc"><file name="config.xml" hash="7b59887dda2117c9843b582a4721ade2"/></dir><dir name="Model"><dir name="Order"><file name="Invoice.php" hash="9d826794c5b0652d2e6e5d3e315a5cc6"/><file name="Payment.php" hash="0b725d11e47c08917e67ba0bd1feaa26"/></dir><dir name="Service"><file name="Quote.php" hash="2cca459cf3338bf53501fe836b8b9f96"/></dir><file name="Order.php" hash="9ffa9e06b0d5d8d2d810ab50017e81fa"/></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="default"><dir name="default"><dir name="images"><file name="cardsave_online.jpg" hash="abb239c81edb9ae8df8cf891e914e2aa"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Cardsave_All.xml" hash="e1d59fd8c4d4b5d87607f43fecf47e59"/></dir></target></contents>
19
  <compatible/>
20
  <dependencies/>
21
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Cardsave_Cardsaveonlinepayments</name>
4
+ <version>1.9.0</version>
5
  <stability>stable</stability>
6
  <license>OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
+ <summary>CardSave payment extension compatible with Magento version 1.3.2.4, 1.3.3.0, 1.4.1.0, 1.4.1.1</summary>
10
+ <description>Fully supports 3D secure transactions. Also supports all of the integration methods provided by Cardsave.</description>
11
+ <notes>Built-in code versioning compatible with Magento 1.3 and 1.4.
12
+ Compatible with the following versions:
13
+ 1.3.2.4
14
+ 1.3.3.0
15
  1.4.1.0
16
+ 1.4.1.1
17
+ Secure URL link fix for SSL certified stores.
18
+ Template fix base/default for version 1.4</notes>
19
  <authors><author><name>cardsave.support</name><user>auto-converted</user><email>integrationsupport@cardsaveonlinepayments.com</email></author></authors>
20
+ <date>2011-01-26</date>
21
+ <time>17:30:17</time>
22
+ <contents><target name="magedesign"><dir name="adminhtml"><dir name="base"><dir name="default"><dir name="template"><dir name="cardsaveonlinepayments"><file name="form.phtml" hash="2b0b8a72c9f4a6d2ab9f0ea020c8f2ed"/><file name="info.phtml" hash="935e10cad0632d558b2db1913cb80a2a"/></dir></dir></dir></dir><dir name="default"><dir name="default"><dir name="template"><dir name="cardsaveonlinepayments"><file name="form.phtml" hash="2b0b8a72c9f4a6d2ab9f0ea020c8f2ed"/><file name="info.phtml" hash="935e10cad0632d558b2db1913cb80a2a"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="cardsaveonlinepayments"><file name="form.phtml" hash="206c8703ef4d160dfc6c739c128ab47b"/><file name="info.phtml" hash="7256464904bbad66a821dea898d657a6"/></dir></dir></dir></dir><dir name="default"><dir name="default"><dir name="template"><dir name="cardsaveonlinepayments"><file name="form.phtml" hash="206c8703ef4d160dfc6c739c128ab47b"/><file name="info.phtml" hash="7256464904bbad66a821dea898d657a6"/></dir></dir></dir></dir></dir></target><target name="magelocal"><dir name="Cardsave"><dir name="Cardsaveonlinepayments"><dir name="Block"><file name="Error.php" hash="660d3cbde48910ef271df9e05130a6d7"/><file name="Form.php" hash="ea5b3817c9607a94f4685d53d0b18569"/><file name="Info.php" hash="57a4bfec1a1c769de063be2b922f4a97"/><file name="Redirect.php" hash="b5a1f7af807dc9a41ec5b9db5c74e87e"/><file name="Threedsecure.php" hash="9d75776f34c5acaf6ea265f35f302c69"/></dir><dir name="controllers"><file name="PaymentController.php" hash="ea696459baa33fc027bea217e99ced08"/></dir><dir name="etc"><file name="config.xml" hash="14507a95509d6366272555a05ba110c9"/><file name="system.xml" hash="4d0eab1c1a11d3e2078802499ad49f1e"/></dir><dir name="Helper"><file name="Data.php" hash="e024ec0479d1e8e7efcf4751b05194d6"/></dir><dir name="Model"><dir name="Common"><dir name="ThePaymentGateway"><file name="PaymentSystem.php" hash="e4d4df170c21b7e3571b3ba1205ca979"/><file name="SOAP.php" hash="a0e5474dce51dc90ba4d37b5de3cdd84"/><file name="TPG_Common.php" hash="d86997c977cfd55b8ab577a514ab149c"/></dir><file name="GlobalErrors.php" hash="04d277d4a763efa508bf36d29c7dc8c4"/><file name="ISOCountries.php" hash="78dc558da68ca9a6ef44898a3980ecf2"/><file name="ISOCurrencies.php" hash="a32bc47b2d9896c293ecdcbf847144f9"/><file name="PaymentFormHelper.php" hash="41e22f61e8b71b8e8b6ca78b90da44e5"/></dir><dir name="Source"><file name="HashMethod.php" hash="997928579b69d21ae9eebec698c715c6"/><file name="OrderStatus.php" hash="4c44f8ba1652f20d934aa200ed4c8d00"/><file name="PaymentAction.php" hash="fa94be37c18bbb2f6301bdad1db3698d"/><file name="PaymentMode.php" hash="ea8af602bd09d54a123af64bc4b680d0"/><file name="ResultDeliveryMethod.php" hash="afb838319df715e604173d6aa143feab"/></dir><file name="Direct.php" hash="5b13a75e6f163241eda84f35326d5e18"/><file name="Request.php" hash="370f028086d13ae1df470e93a67dea66"/></dir></dir><dir name="Checkout"><dir name="Block"><dir name="Onepage"><dir name="Payment"><file name="Methods.php" hash="695d628564f6e1e0c85e3821699e6b45"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="9dbd58b6b32491d65e5c7d5850aa3420"/></dir><dir name="Model"><dir name="Type"><file name="Onepage.php" hash="63e21d5d5a681e30067c8a20390bb141"/></dir></dir></dir><dir name="Sales"><dir name="etc"><file name="config.xml" hash="7b59887dda2117c9843b582a4721ade2"/></dir><dir name="Model"><dir name="Order"><file name="Invoice.php" hash="9be99f3fbe1c4fe98fb110d3daa8afe6"/><file name="Payment.php" hash="f95be17629c775b2e10795ec55bb85d2"/></dir><dir name="Service"><file name="Quote.php" hash="61670788275b93098bc8da9f27344e4b"/></dir><file name="Order.php" hash="9ffa9e06b0d5d8d2d810ab50017e81fa"/></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="images"><file name="cardsave_online.jpg" hash="abb239c81edb9ae8df8cf891e914e2aa"/></dir></dir></dir><dir name="default"><dir name="default"><dir name="images"><file name="cardsave_online.jpg" hash="abb239c81edb9ae8df8cf891e914e2aa"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Cardsave_All.xml" hash="e1d59fd8c4d4b5d87607f43fecf47e59"/></dir></target></contents>
23
  <compatible/>
24
  <dependencies/>
25
  </package>
skin/frontend/base/default/images/cardsave_online.jpg ADDED
Binary file