Cardsave_Cardsaveonlinepayments - Version 1.12.0

Version Notes

Option to select transaction type: PREAUTH or SALE.
CrossReference feature added with new transaction types: VOID, REFUND and COLLECTION.
Fixed stock management bug on Hosted Payment Form payment when clicking on BACK button before payment is processed.

Download this release

Release Info

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


Code changes from version 1.11.1 to 1.12.0

app/code/local/Cardsave/Cardsaveonlinepayments/Block/Adminhtml/Sales/Order/Payment.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Cardsave_Cardsaveonlinepayments_Block_Adminhtml_Sales_Order_Payment extends Mage_Adminhtml_Block_Sales_Order_Payment
3
+ {
4
+ public function setPayment($payment)
5
+ {
6
+ parent::setPayment($payment);
7
+ $paymentInfoBlock = Mage::helper('payment')->getInfoBlock($payment);
8
+
9
+ if ($payment->getMethod() == 'cardsaveonlinepayments')
10
+ {
11
+
12
+ $paymentInfoBlock->setTemplate('payment/info/cc_cardsaveonlinepayments.phtml');
13
+ }
14
+
15
+ $this->setChild('info', $paymentInfoBlock);
16
+ $this->setData('payment', $payment);
17
+ return $this;
18
+ }
19
+
20
+ protected function _toHtml()
21
+ {
22
+ return $this->getChildHtml('info');
23
+ }
24
+
25
+ }
app/code/local/Cardsave/Cardsaveonlinepayments/Model/Common/ThePaymentGateway/PaymentSystem.php CHANGED
@@ -1519,7 +1519,7 @@
1519
 
1520
  $todTransactionOutputData = null;
1521
  $goGatewayOutput = null;
1522
-
1523
  $sSOAPClient = new CSV_SOAP('CrossReferenceTransaction', CSV_GatewayTransaction::getSOAPNamespace());
1524
  // transaction details
1525
  if ($this->m_tdTransactionDetails != null)
1519
 
1520
  $todTransactionOutputData = null;
1521
  $goGatewayOutput = null;
1522
+
1523
  $sSOAPClient = new CSV_SOAP('CrossReferenceTransaction', CSV_GatewayTransaction::getSOAPNamespace());
1524
  // transaction details
1525
  if ($this->m_tdTransactionDetails != null)
app/code/local/Cardsave/Cardsaveonlinepayments/Model/Direct.php CHANGED
@@ -19,9 +19,9 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
19
  protected $_isGateway = true;
20
  protected $_canAuthorize = true;
21
  protected $_canCapture = true;
22
- protected $_canCapturePartial = true;
23
- protected $_canRefund = false;
24
- protected $_canVoid = false;
25
  protected $_canUseInternal = true;
26
  protected $_canUseCheckout = true;
27
  protected $_canUseForMultishipping = true;
@@ -77,8 +77,33 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
77
  public function authorize(Varien_Object $payment, $amount)
78
  {
79
  $error = false;
 
 
 
 
80
 
81
- Mage::throwException('This payment module only allow capture payments.');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
 
83
  return $this;
84
  }
@@ -129,33 +154,41 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
129
  return $this;
130
  }
131
 
132
- // fresh payment request
133
- $session->setThreedsecurerequired(null)
134
- ->setRedirectedpayment(null)
135
- ->setIshostedpayment(null)
136
- ->setHostedPayment(null)
137
- ->setMd(null)
138
- ->setPareq(null)
139
- ->setAcsurl(null)
140
- ->setPaymentprocessorresponse(null);
141
-
142
- $payment->setAmount($amount);
143
-
144
- switch ($mode)
145
- {
146
- case Cardsave_Cardsaveonlinepayments_Model_Source_PaymentMode::PAYMENT_MODE_DIRECT_API:
147
- $error = $this->_runTransaction($payment, $amount);
148
- break;
149
- case Cardsave_Cardsaveonlinepayments_Model_Source_PaymentMode::PAYMENT_MODE_HOSTED_PAYMENT_FORM:
150
- $error = $this->_runHostedPaymentTransaction($payment, $amount);
151
- break;
152
- case Cardsave_Cardsaveonlinepayments_Model_Source_PaymentMode::PAYMENT_MODE_TRANSPARENT_REDIRECT:
153
- $error = $this->_runTransparentRedirectTransaction($payment, $amount);
154
- break;
155
- default:
156
- Mage::throwException('Invalid payment type: '.$this->getConfigData('mode'));
157
- break;
158
- }
 
 
 
 
 
 
 
 
159
  }
160
 
161
  if($error)
@@ -191,7 +224,6 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
191
  $SecretKey = $this->getConfigData('secretkey');
192
  // assign payment form field values to variables
193
  $order = $payment->getOrder();
194
- // escape the special characters as the PHP integration doesn't do it (ie: & ampersand)
195
  $szOrderID = $payment->getOrder()->increment_id;
196
  $szOrderDescription = '';
197
  $szCardName = $payment->getCcOwner();
@@ -214,7 +246,8 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
214
  $szEmailAddress = $billingAddress->getCustomerEmail();
215
  $szPhoneNumber = $billingAddress->getTelephone();
216
  $nDecimalAmount;
217
-
 
218
  $PaymentProcessorFullDomain = $this->_getPaymentProcessorFullDomain();
219
  $iclISOCurrencyList = CSV_ISOCurrencies::getISOCurrencyList();
220
  $iclISOCountryList = CSV_ISOCountries::getISOCountryList();
@@ -224,12 +257,26 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
224
  $rgeplRequestGatewayEntryPointList->add("https://gw2.".$PaymentProcessorFullDomain, 200, 2);
225
  $rgeplRequestGatewayEntryPointList->add("https://gw3.".$PaymentProcessorFullDomain, 300, 2);
226
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
  $cdtCardDetailsTransaction = new CSV_CardDetailsTransaction($rgeplRequestGatewayEntryPointList);
228
 
229
  $cdtCardDetailsTransaction->getMerchantAuthentication()->setMerchantID($MerchantID);
230
  $cdtCardDetailsTransaction->getMerchantAuthentication()->setPassword($Password);
231
 
232
- $cdtCardDetailsTransaction->getTransactionDetails()->getMessageDetails()->setTransactionType("SALE");
233
 
234
  if ($szCurrencyShort != '' &&
235
  $iclISOCurrencyList->getISOCurrency($szCurrencyShort, $icISOCurrency))
@@ -238,9 +285,8 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
238
  $cdtCardDetailsTransaction->getTransactionDetails()->getCurrencyCode()->setValue($icISOCurrency->getISOCode());
239
  }
240
 
241
- $power = pow(10, $icISOCurrency->getExponent());
242
- $nDecimalAmount = $amount * $power;
243
- //$nAmount = new CSV_NullableInt($nDecimalAmount);
244
  $cdtCardDetailsTransaction->getTransactionDetails()->getAmount()->setValue($nDecimalAmount);
245
 
246
  $cdtCardDetailsTransaction->getTransactionDetails()->setOrderID($szOrderID);
@@ -316,18 +362,31 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
316
  {
317
  $szLogMessage = "Transaction could not be completed for OrderID: ".$szOrderID.". Result details: ";
318
  $szNotificationMessage = 'Payment Processor Response: '.$cdtrCardDetailsTransactionResult->getMessage();
319
- $szCrossReference = $todTransactionOutputData->getCrossReference();
 
 
 
 
320
 
321
  switch ($cdtrCardDetailsTransactionResult->getStatusCode())
322
  {
323
  case 0:
324
  // status code of 0 - means transaction successful
325
- $szLogMessage = "Transaction successfully completed for OrderID: ".$szOrderID.". Result object details: ";
 
 
 
 
 
 
 
 
 
326
  Mage::getSingleton('core/session')->addSuccess($szNotificationMessage);
327
  break;
328
  case 3:
329
  // status code of 3 - means 3D Secure authentication required
330
- $szLogMessage = "3D Secure Authentication required for OrderID: ".$szOrderID.". Result object details: ";
331
  $szNotificationMessage = '';
332
 
333
  $szPaReq = $todTransactionOutputData->getThreeDSecureOutputData()->getPaREQ();
@@ -350,7 +409,7 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
350
  case 20:
351
  // status code of 20 - means duplicate transaction
352
  $szPreviousTransactionMessage = $cdtrCardDetailsTransactionResult->getPreviousTransactionResult()->getMessage();
353
- $szLogMessage = "Duplicate transaction for OrderID: ".$szOrderID.". A duplicate transaction means that a transaction with these details has already been processed by the payment provider. The details of the original transaction: ".$szPreviousTransactionMessage.". Result object details: ";
354
  $szNotificationMessage = $szNotificationMessage.". A duplicate transaction means that a transaction with these details has already been processed by the payment provider. The details of the original transaction - Previous Transaction Response: ".$szPreviousTransactionMessage;
355
 
356
  if ($cdtrCardDetailsTransactionResult->getPreviousTransactionResult()->getStatusCode()->getValue() != 0)
@@ -376,7 +435,7 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
376
  }
377
  $szLogMessage = $szLogMessage." ";
378
  }
379
- $szLogMessage = $szLogMessage.' Result object details: ';
380
  break;
381
  default:
382
  // unhandled status code
@@ -400,13 +459,7 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
400
  $payment->setIsInvoicePaid(true);
401
  }
402
  }
403
-
404
- if($szCrossReference)
405
- {
406
- $szAdditionalData = "CrossReference=".$szCrossReference;
407
- $payment->setAdditionalData($szAdditionalData);
408
- }
409
-
410
  return $error;
411
  }
412
 
@@ -483,8 +536,7 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
483
  $nCurrencyCode = $icISOCurrency->getISOCode();
484
  }
485
 
486
- $power = pow(10, $icISOCurrency->getExponent());
487
- $nAmount = $amount * $power;
488
 
489
  $szISO2CountryCode = $billingAddress->getCountry();
490
  $szCountryShort = $this->_getISO3Code($szISO2CountryCode);
@@ -494,10 +546,24 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
494
  }
495
 
496
  $szOrderID = $payment->getOrder()->increment_id;
497
- $szTransactionType = 'SALE';
498
  //date time with 2008-12-01 14:12:00 +01:00 format
499
  $szTransactionDateTime = date('Y-m-d H:i:s P');
500
  $szOrderDescription = '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
501
 
502
  $szCustomerName = $billingAddress->getfirstname();
503
  if($billingAddress->getfirstname())
@@ -579,6 +645,10 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
579
  $session->setRedirectionmethod('_runRedirectedPaymentComplete');
580
  $payment->getOrder()->setIsHostedPaymentPending(true);
581
  }
 
 
 
 
582
  }
583
 
584
  /**
@@ -612,15 +682,28 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
612
  $nCurrencyCode = $icISOCurrency->getISOCode();
613
  }
614
 
615
- $power = pow(10, $icISOCurrency->getExponent());
616
- $nAmount = $amount * $power;
617
 
618
  $szOrderID = $payment->getOrder()->increment_id;
619
- $szTransactionType = 'SALE';
620
  //date time with 2008-12-01 14:12:00 +01:00 format
621
  $szTransactionDateTime = date('Y-m-d H:i:s P');
622
  $szOrderDescription = '';
623
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
624
  $szAddress1 = $billingAddress->getStreet1();
625
  $szAddress2 = $billingAddress->getStreet2();
626
  $szAddress3 = $billingAddress->getStreet3();
@@ -683,6 +766,10 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
683
  Mage::getSingleton('checkout/session')->setRedirectionmethod('_runRedirectedPaymentComplete');
684
  $payment->getOrder()->setIsHostedPaymentPending(true);
685
  }
 
 
 
 
686
  }
687
 
688
  /**
@@ -732,13 +819,20 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
732
  else
733
  {
734
  $message = "Payment Processor Response: ".$tdsarThreeDSecureAuthenticationResult->getMessage();
735
- $szLogMessage = "3D Secure transaction could not be completed for OrderID: ".$szOrderID.". Result object details: ";
 
736
 
737
  switch ($tdsarThreeDSecureAuthenticationResult->getStatusCode())
738
  {
739
  case 0:
740
  // status code of 0 - means transaction successful
741
- $szLogMessage = "3D Secure transaction successfully completed for OrderID: ".$szOrderID.". Result object details: ";
 
 
 
 
 
 
742
  break;
743
  case 5:
744
  // status code of 5 - means transaction declined
@@ -747,7 +841,7 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
747
  case 20:
748
  // status code of 20 - means duplicate transaction
749
  $szPreviousTransactionMessage = $tdsarThreeDSecureAuthenticationResult->getPreviousTransactionResult()->getMessage();
750
- $szLogMessage = "Duplicate transaction for OrderID: ".$szOrderID.". A duplicate transaction means that a transaction with these details has already been processed by the payment provider. The details of the original transaction: ".$szPreviousTransactionMessage.". Result object details: ";
751
 
752
  if ($tdsarThreeDSecureAuthenticationResult->getPreviousTransactionResult()->getStatusCode()->getValue() == 0)
753
  {
@@ -797,6 +891,8 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
797
  {
798
  $payment->setStatus(self::STATUS_APPROVED);
799
 
 
 
800
  if($nVersion == 1324 || $nVersion == 1330)
801
  {
802
  $payment->setIsInvoicePaid(true);
@@ -824,11 +920,14 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
824
  }
825
 
826
  $message = "Payment Processor Response: ".$szMessage;
827
-
828
  switch ($szStatusCode)
829
  {
830
  case "0":
831
  Mage::log($szWording."transaction successfully completed. ".$message);
 
 
 
832
  break;
833
  case "20":
834
  Mage::log("Duplicate ".$szWording."transaction. ".$message);
@@ -847,11 +946,9 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
847
  }
848
 
849
  $session->setPaymentprocessorresponse($message);
850
- if($szCrossReference)
851
- {
852
- $szAdditionalData = "CrossReference=".$szCrossReference;
853
- $payment->setAdditionalData($szAdditionalData);
854
- }
855
 
856
  if($error == true)
857
  {
@@ -881,17 +978,39 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
881
  {
882
  $result = false;
883
  $session = Mage::getSingleton('checkout/session');
 
 
884
 
885
  if($session->getMd() &&
886
  $session->getAcsurl() &&
887
  $session->getPareq())
888
  {
889
  // Direct (API) for 3D Secure payments
 
 
 
 
 
 
 
 
 
 
890
  $result = Mage::getUrl('cardsaveonlinepayments/payment/threedsecure', array('_secure' => true));
891
  }
892
  if($session->getHashdigest())
893
  {
894
  // Hosted Payment Form and Transparent Redirect payments
 
 
 
 
 
 
 
 
 
 
895
  $result = Mage::getUrl('cardsaveonlinepayments/payment/redirect', array('_secure' => true));
896
  }
897
 
@@ -974,4 +1093,467 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
974
 
975
  return $magentoVersion;
976
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
977
  }
19
  protected $_isGateway = true;
20
  protected $_canAuthorize = true;
21
  protected $_canCapture = true;
22
+ protected $_canCapturePartial = false;
23
+ protected $_canRefund = true;
24
+ protected $_canVoid = true;
25
  protected $_canUseInternal = true;
26
  protected $_canUseCheckout = true;
27
  protected $_canUseForMultishipping = true;
77
  public function authorize(Varien_Object $payment, $amount)
78
  {
79
  $error = false;
80
+ $mode = $this->getConfigData('mode');
81
+ $nVersion = $this->getVersion();
82
+
83
+ //Mage::throwException('This payment module only allow capture payments.');
84
 
85
+ // TODO : need to finish for non Direct API methods
86
+ switch ($mode)
87
+ {
88
+ case Cardsave_Cardsaveonlinepayments_Model_Source_PaymentMode::PAYMENT_MODE_DIRECT_API:
89
+ $error = $this->_runTransaction($payment, $amount);
90
+ break;
91
+ case Cardsave_Cardsaveonlinepayments_Model_Source_PaymentMode::PAYMENT_MODE_HOSTED_PAYMENT_FORM:
92
+ $error = $this->_runHostedPaymentTransaction($payment, $amount);
93
+ break;
94
+ case Cardsave_Cardsaveonlinepayments_Model_Source_PaymentMode::PAYMENT_MODE_TRANSPARENT_REDIRECT:
95
+ $error = $this->_runTransparentRedirectTransaction($payment, $amount);
96
+ //Mage::throwException('TR not supported');
97
+ break;
98
+ default:
99
+ Mage::throwException('Invalid payment type: '.$this->getConfigData('mode'));
100
+ break;
101
+ }
102
+
103
+ if($error)
104
+ {
105
+ Mage::throwException($error);
106
+ }
107
 
108
  return $this;
109
  }
154
  return $this;
155
  }
156
 
157
+ if($session->getIsCollectionCrossReferenceTransaction())
158
+ {
159
+ // do a CrossReference transaction
160
+ $error = $this->_runCrossReferenceTransaction($payment, "COLLECTION", $amount);
161
+ }
162
+ else
163
+ {
164
+ // fresh payment request
165
+ $session->setThreedsecurerequired(null)
166
+ ->setRedirectedpayment(null)
167
+ ->setIshostedpayment(null)
168
+ ->setHostedPayment(null)
169
+ ->setMd(null)
170
+ ->setPareq(null)
171
+ ->setAcsurl(null)
172
+ ->setPaymentprocessorresponse(null);
173
+
174
+ $payment->setAmount($amount);
175
+
176
+ switch ($mode)
177
+ {
178
+ case Cardsave_Cardsaveonlinepayments_Model_Source_PaymentMode::PAYMENT_MODE_DIRECT_API:
179
+ $error = $this->_runTransaction($payment, $amount);
180
+ break;
181
+ case Cardsave_Cardsaveonlinepayments_Model_Source_PaymentMode::PAYMENT_MODE_HOSTED_PAYMENT_FORM:
182
+ $error = $this->_runHostedPaymentTransaction($payment, $amount);
183
+ break;
184
+ case Cardsave_Cardsaveonlinepayments_Model_Source_PaymentMode::PAYMENT_MODE_TRANSPARENT_REDIRECT:
185
+ $error = $this->_runTransparentRedirectTransaction($payment, $amount);
186
+ break;
187
+ default:
188
+ Mage::throwException('Invalid payment type: '.$this->getConfigData('mode'));
189
+ break;
190
+ }
191
+ }
192
  }
193
 
194
  if($error)
224
  $SecretKey = $this->getConfigData('secretkey');
225
  // assign payment form field values to variables
226
  $order = $payment->getOrder();
 
227
  $szOrderID = $payment->getOrder()->increment_id;
228
  $szOrderDescription = '';
229
  $szCardName = $payment->getCcOwner();
246
  $szEmailAddress = $billingAddress->getCustomerEmail();
247
  $szPhoneNumber = $billingAddress->getTelephone();
248
  $nDecimalAmount;
249
+ $szTransactionType;
250
+
251
  $PaymentProcessorFullDomain = $this->_getPaymentProcessorFullDomain();
252
  $iclISOCurrencyList = CSV_ISOCurrencies::getISOCurrencyList();
253
  $iclISOCountryList = CSV_ISOCountries::getISOCountryList();
257
  $rgeplRequestGatewayEntryPointList->add("https://gw2.".$PaymentProcessorFullDomain, 200, 2);
258
  $rgeplRequestGatewayEntryPointList->add("https://gw3.".$PaymentProcessorFullDomain, 300, 2);
259
 
260
+ $paymentAction = $this->getConfigData('payment_action');
261
+ if($paymentAction == Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE_CAPTURE)
262
+ {
263
+ $szTransactionType = "SALE";
264
+ }
265
+ else if($paymentAction == Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE)
266
+ {
267
+ $szTransactionType = "PREAUTH";
268
+ }
269
+ else
270
+ {
271
+ Mage::throwException('Unknown payment action: '.$paymentAction);
272
+ }
273
+
274
  $cdtCardDetailsTransaction = new CSV_CardDetailsTransaction($rgeplRequestGatewayEntryPointList);
275
 
276
  $cdtCardDetailsTransaction->getMerchantAuthentication()->setMerchantID($MerchantID);
277
  $cdtCardDetailsTransaction->getMerchantAuthentication()->setPassword($Password);
278
 
279
+ $cdtCardDetailsTransaction->getTransactionDetails()->getMessageDetails()->setTransactionType($szTransactionType);
280
 
281
  if ($szCurrencyShort != '' &&
282
  $iclISOCurrencyList->getISOCurrency($szCurrencyShort, $icISOCurrency))
285
  $cdtCardDetailsTransaction->getTransactionDetails()->getCurrencyCode()->setValue($icISOCurrency->getISOCode());
286
  }
287
 
288
+ $nDecimalAmount = $this->_getRoundedAmount($amount, $icISOCurrency->getExponent());
289
+
 
290
  $cdtCardDetailsTransaction->getTransactionDetails()->getAmount()->setValue($nDecimalAmount);
291
 
292
  $cdtCardDetailsTransaction->getTransactionDetails()->setOrderID($szOrderID);
362
  {
363
  $szLogMessage = "Transaction could not be completed for OrderID: ".$szOrderID.". Result details: ";
364
  $szNotificationMessage = 'Payment Processor Response: '.$cdtrCardDetailsTransactionResult->getMessage();
365
+ $szCrossReference = $todTransactionOutputData->getCrossReference();
366
+
367
+ /* serve out the CrossReference as the TransactionId - this need to be done to enable the "Refund" button
368
+ in the Magento CreditMemo internal refund mechanism */
369
+ $payment->setTransactionId($szCrossReference);
370
 
371
  switch ($cdtrCardDetailsTransactionResult->getStatusCode())
372
  {
373
  case 0:
374
  // status code of 0 - means transaction successful
375
+ $szLogMessage = "Transaction successfully completed for OrderID: ".$szOrderID.". Response object: ";
376
+
377
+ // serve out the CrossReference as a TransactionId in the Magento system
378
+ $order->setCustomerNote($szNotificationMessage);
379
+ $this->setPaymentAdditionalInformation($payment, $szCrossReference);
380
+
381
+ // deactivate the current quote - fixing the cart not emptied bug
382
+ Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save();
383
+
384
+ // add the success message
385
  Mage::getSingleton('core/session')->addSuccess($szNotificationMessage);
386
  break;
387
  case 3:
388
  // status code of 3 - means 3D Secure authentication required
389
+ $szLogMessage = "3D Secure Authentication required for OrderID: ".$szOrderID.". Response object: ";
390
  $szNotificationMessage = '';
391
 
392
  $szPaReq = $todTransactionOutputData->getThreeDSecureOutputData()->getPaREQ();
409
  case 20:
410
  // status code of 20 - means duplicate transaction
411
  $szPreviousTransactionMessage = $cdtrCardDetailsTransactionResult->getPreviousTransactionResult()->getMessage();
412
+ $szLogMessage = "Duplicate transaction for OrderID: ".$szOrderID.". A duplicate transaction means that a transaction with these details has already been processed by the payment provider. The details of the original transaction: ".$szPreviousTransactionMessage.". Response object: ";
413
  $szNotificationMessage = $szNotificationMessage.". A duplicate transaction means that a transaction with these details has already been processed by the payment provider. The details of the original transaction - Previous Transaction Response: ".$szPreviousTransactionMessage;
414
 
415
  if ($cdtrCardDetailsTransactionResult->getPreviousTransactionResult()->getStatusCode()->getValue() != 0)
435
  }
436
  $szLogMessage = $szLogMessage." ";
437
  }
438
+ $szLogMessage = $szLogMessage.' Response object: ';
439
  break;
440
  default:
441
  // unhandled status code
459
  $payment->setIsInvoicePaid(true);
460
  }
461
  }
462
+
 
 
 
 
 
 
463
  return $error;
464
  }
465
 
536
  $nCurrencyCode = $icISOCurrency->getISOCode();
537
  }
538
 
539
+ $nAmount = $this->_getRoundedAmount($amount, $icISOCurrency->getExponent());
 
540
 
541
  $szISO2CountryCode = $billingAddress->getCountry();
542
  $szCountryShort = $this->_getISO3Code($szISO2CountryCode);
546
  }
547
 
548
  $szOrderID = $payment->getOrder()->increment_id;
 
549
  //date time with 2008-12-01 14:12:00 +01:00 format
550
  $szTransactionDateTime = date('Y-m-d H:i:s P');
551
  $szOrderDescription = '';
552
+
553
+ //$szTransactionType = "SALE";
554
+ $paymentAction = $this->getConfigData('payment_action');
555
+ if($paymentAction == Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE_CAPTURE)
556
+ {
557
+ $szTransactionType = "SALE";
558
+ }
559
+ else if($paymentAction == Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE)
560
+ {
561
+ $szTransactionType = "PREAUTH";
562
+ }
563
+ else
564
+ {
565
+ Mage::throwException('Unknown payment action: '.$paymentAction);
566
+ }
567
 
568
  $szCustomerName = $billingAddress->getfirstname();
569
  if($billingAddress->getfirstname())
645
  $session->setRedirectionmethod('_runRedirectedPaymentComplete');
646
  $payment->getOrder()->setIsHostedPaymentPending(true);
647
  }
648
+
649
+ /* serve out a dummy CrossReference as the TransactionId - this need to be done to enable the "Refund" button
650
+ in the Magento CreditMemo internal refund mechanism */
651
+ $payment->setTransactionId($szOrderID."_".date('YmdHis'));
652
  }
653
 
654
  /**
682
  $nCurrencyCode = $icISOCurrency->getISOCode();
683
  }
684
 
685
+ $nAmount = $this->_getRoundedAmount($amount, $icISOCurrency->getExponent());
 
686
 
687
  $szOrderID = $payment->getOrder()->increment_id;
 
688
  //date time with 2008-12-01 14:12:00 +01:00 format
689
  $szTransactionDateTime = date('Y-m-d H:i:s P');
690
  $szOrderDescription = '';
691
 
692
+ //$szTransactionType = 'SALE';
693
+ $paymentAction = $this->getConfigData('payment_action');
694
+ if($paymentAction == Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE_CAPTURE)
695
+ {
696
+ $szTransactionType = "SALE";
697
+ }
698
+ else if($paymentAction == Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE)
699
+ {
700
+ $szTransactionType = "PREAUTH";
701
+ }
702
+ else
703
+ {
704
+ Mage::throwException('Unknown payment action: '.$paymentAction);
705
+ }
706
+
707
  $szAddress1 = $billingAddress->getStreet1();
708
  $szAddress2 = $billingAddress->getStreet2();
709
  $szAddress3 = $billingAddress->getStreet3();
766
  Mage::getSingleton('checkout/session')->setRedirectionmethod('_runRedirectedPaymentComplete');
767
  $payment->getOrder()->setIsHostedPaymentPending(true);
768
  }
769
+
770
+ /* serve out a dummy CrossReference as the TransactionId - this need to be done to enable the "Refund" button
771
+ in the Magento CreditMemo internal refund mechanism */
772
+ $payment->setTransactionId($szOrderID."_".date('YmdHis'));
773
  }
774
 
775
  /**
819
  else
820
  {
821
  $message = "Payment Processor Response: ".$tdsarThreeDSecureAuthenticationResult->getMessage();
822
+ $szLogMessage = "3D Secure transaction could not be completed for OrderID: ".$szOrderID.". Response object: ";
823
+ $szCrossReference = $todTransactionOutputData->getCrossReference();
824
 
825
  switch ($tdsarThreeDSecureAuthenticationResult->getStatusCode())
826
  {
827
  case 0:
828
  // status code of 0 - means transaction successful
829
+ $szLogMessage = "3D Secure transaction successfully completed for OrderID: ".$szOrderID.". Response object: ";
830
+
831
+ // serve out the CrossReference as a TransactionId in the Magento system
832
+ $this->setPaymentAdditionalInformation($payment, $szCrossReference);
833
+
834
+ // need to store the new CrossReference and only store it against the payment object in the payment controller class
835
+ $session->setNewCrossReference($szCrossReference);
836
  break;
837
  case 5:
838
  // status code of 5 - means transaction declined
841
  case 20:
842
  // status code of 20 - means duplicate transaction
843
  $szPreviousTransactionMessage = $tdsarThreeDSecureAuthenticationResult->getPreviousTransactionResult()->getMessage();
844
+ $szLogMessage = "Duplicate transaction for OrderID: ".$szOrderID.". A duplicate transaction means that a transaction with these details has already been processed by the payment provider. The details of the original transaction: ".$szPreviousTransactionMessage.". Response object: ";
845
 
846
  if ($tdsarThreeDSecureAuthenticationResult->getPreviousTransactionResult()->getStatusCode()->getValue() == 0)
847
  {
891
  {
892
  $payment->setStatus(self::STATUS_APPROVED);
893
 
894
+
895
+
896
  if($nVersion == 1324 || $nVersion == 1330)
897
  {
898
  $payment->setIsInvoicePaid(true);
920
  }
921
 
922
  $message = "Payment Processor Response: ".$szMessage;
923
+
924
  switch ($szStatusCode)
925
  {
926
  case "0":
927
  Mage::log($szWording."transaction successfully completed. ".$message);
928
+
929
+ // need to store the new CrossReference and only store it against the payment object in the payment controller class
930
+ $session->setNewCrossReference($szCrossReference);
931
  break;
932
  case "20":
933
  Mage::log("Duplicate ".$szWording."transaction. ".$message);
946
  }
947
 
948
  $session->setPaymentprocessorresponse($message);
949
+
950
+ // store the CrossReference and other data
951
+ $this->setPaymentAdditionalInformation($payment, $szCrossReference);
 
 
952
 
953
  if($error == true)
954
  {
978
  {
979
  $result = false;
980
  $session = Mage::getSingleton('checkout/session');
981
+ $nVersion = $this->getVersion();
982
+ $mode = $this->getConfigData('mode');
983
 
984
  if($session->getMd() &&
985
  $session->getAcsurl() &&
986
  $session->getPareq())
987
  {
988
  // Direct (API) for 3D Secure payments
989
+ if($nVersion >= 1410)
990
+ {
991
+ // need to re-add the ordered item quantity to stock as per not completed 3DS transaction
992
+ if($mode != Cardsave_Cardsaveonlinepayments_Model_Source_PaymentMode::PAYMENT_MODE_TRANSPARENT_REDIRECT)
993
+ {
994
+ $order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
995
+ $this->addOrderedItemsToStock($order);
996
+ }
997
+ }
998
+
999
  $result = Mage::getUrl('cardsaveonlinepayments/payment/threedsecure', array('_secure' => true));
1000
  }
1001
  if($session->getHashdigest())
1002
  {
1003
  // Hosted Payment Form and Transparent Redirect payments
1004
+ if($nVersion >= 1410)
1005
+ {
1006
+ // need to re-add the ordered item quantity to stock as per not completed 3DS transaction
1007
+ if(!Mage::getSingleton('checkout/session')->getPares())
1008
+ {
1009
+ $order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
1010
+ $this->addOrderedItemsToStock($order);
1011
+ }
1012
+ }
1013
+
1014
  $result = Mage::getUrl('cardsaveonlinepayments/payment/redirect', array('_secure' => true));
1015
  }
1016
 
1093
 
1094
  return $magentoVersion;
1095
  }
1096
+
1097
+ private function _getRoundedAmount($amount, $nExponent)
1098
+ {
1099
+ $nDecimalAmount;
1100
+
1101
+ // round the amount before use
1102
+ $amount = round($amount, $nExponent);
1103
+ $power = pow(10, $nExponent);
1104
+ $nDecimalAmount = $amount * $power;
1105
+
1106
+ return $nDecimalAmount;
1107
+ }
1108
+
1109
+ /**
1110
+ * Depreciated function - sets the additional_information column data in the sales_flat_order_payment table
1111
+ *
1112
+ * @param unknown_type $payment
1113
+ * @param unknown_type $szCrossReference
1114
+ * @param unknown_type $szTransactionType
1115
+ * @param unknown_type $szTransactionDate
1116
+ */
1117
+ public function setPaymentAdditionalInformation($payment, $szCrossReference)
1118
+ {
1119
+ $arAdditionalInformationArray = array();
1120
+
1121
+ $paymentAction = $this->getConfigData('payment_action');
1122
+ if($paymentAction == Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE_CAPTURE)
1123
+ {
1124
+ $szTransactionType = "SALE";
1125
+ }
1126
+ else if($paymentAction == Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE)
1127
+ {
1128
+ $szTransactionType = "PREAUTH";
1129
+ }
1130
+ else
1131
+ {
1132
+ Mage::throwException('Unknown payment action: '.$paymentAction);
1133
+ }
1134
+
1135
+ $szTransactionDate = date("Ymd");
1136
+
1137
+ $arAdditionalInformationArray["CrossReference"] = $szCrossReference;
1138
+ $arAdditionalInformationArray["TransactionType"] = $szTransactionType;
1139
+ $arAdditionalInformationArray["TransactionDateTime"] = $szTransactionDate;
1140
+
1141
+ $payment->setAdditionalInformation($arAdditionalInformationArray);
1142
+ }
1143
+
1144
+ /**
1145
+ * Deduct the order items from the stock
1146
+ *
1147
+ * @param unknown_type $order
1148
+ */
1149
+ public function subtractOrderedItemsFromStock($order)
1150
+ {
1151
+ $nVersion = Mage::getModel('cardsaveonlinepayments/direct')->getVersion();
1152
+ $isCustomStockManagementEnabled = Mage::getModel('cardsaveonlinepayments/direct')->getConfigData('customstockmanagementenabled');
1153
+
1154
+ if($nVersion >= 1410 &&
1155
+ $isCustomStockManagementEnabled)
1156
+ {
1157
+ $items = $order->getAllItems();
1158
+ foreach ($items as $itemId => $item)
1159
+ {
1160
+ // ordered quantity of the item from stock
1161
+ $quantity = $item->getQtyOrdered();
1162
+ $productId = $item->getProductId();
1163
+
1164
+ $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($productId);
1165
+ $stockManagement = $stock->getManageStock();
1166
+
1167
+ if($stockManagement)
1168
+ {
1169
+ $stock->setQty($stock->getQty() - $quantity);
1170
+ $stock->save();
1171
+ }
1172
+ }
1173
+ }
1174
+ }
1175
+
1176
+ /**
1177
+ * Re-add the order items to the stock to balance the incorrect stock management before a payment is completed
1178
+ *
1179
+ * @param unknown_type $order
1180
+ */
1181
+ public function addOrderedItemsToStock($order)
1182
+ {
1183
+ $nVersion = Mage::getModel('cardsaveonlinepayments/direct')->getVersion();
1184
+ $isCustomStockManagementEnabled = Mage::getModel('cardsaveonlinepayments/direct')->getConfigData('customstockmanagementenabled');
1185
+
1186
+ if($nVersion >= 1410 &&
1187
+ $isCustomStockManagementEnabled)
1188
+ {
1189
+ $items = $order->getAllItems();
1190
+ foreach ($items as $itemId => $item)
1191
+ {
1192
+ // ordered quantity of the item from stock
1193
+ $quantity = $item->getQtyOrdered();
1194
+ $productId = $item->getProductId();
1195
+
1196
+ $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($productId);
1197
+ $stockManagement = $stock->getManageStock();
1198
+
1199
+ if($stockManagement)
1200
+ {
1201
+ $stock->setQty($stock->getQty() + $quantity);
1202
+ $stock->save();
1203
+ }
1204
+ }
1205
+ }
1206
+ }
1207
+
1208
+ /**
1209
+ * Override the refund function to run a CrossReference transaction
1210
+ *
1211
+ * @param Varien_Object $payment
1212
+ * @param unknown_type $amount
1213
+ * @return unknown
1214
+ */
1215
+ public function refund(Varien_Object $payment, $amount)
1216
+ {
1217
+ $error = false;
1218
+ $szTransactionType = "REFUND";
1219
+ $orderStatus = 'csv_refunded';
1220
+ $szMessage = 'Payment refunded';
1221
+ $arAdditionalInformationArray;
1222
+
1223
+ if($amount > 0)
1224
+ {
1225
+ $error = $this->_runCrossReferenceTransaction($payment, $szTransactionType, $amount);
1226
+ }
1227
+ else
1228
+ {
1229
+ $error = 'Error in refunding the payment';
1230
+ }
1231
+
1232
+ if($error === false)
1233
+ {
1234
+ $order = $payment->getOrder();
1235
+ $payment = $order->getPayment();
1236
+ $arAdditionalInformationArray = $payment->getAdditionalInformation();
1237
+
1238
+ $arAdditionalInformationArray["Refunded"] = 1;
1239
+ $payment->setAdditionalInformation($arAdditionalInformationArray);
1240
+ $payment->save();
1241
+
1242
+ $order->setState('canceled', $orderStatus, $szMessage, false);
1243
+ $order->save();
1244
+ }
1245
+ else
1246
+ {
1247
+ Mage::throwException($error);
1248
+ }
1249
+
1250
+ return $this;
1251
+ }
1252
+
1253
+ /**
1254
+ * CardSave VOID functionality
1255
+ * Note: if a transaction (payment) is once voided (canceled) it isn't possible to redo this action
1256
+ *
1257
+ * @param Varien_Object $payment
1258
+ * @return unknown
1259
+ */
1260
+ public function csvVoid(Varien_Object $payment)
1261
+ {
1262
+ $error = false;
1263
+ $szTransactionType = "VOID";
1264
+ $orderStatus = "csv_voided";
1265
+ $arAdditionalInformationArray;
1266
+
1267
+ // attempt a VOID and accordingly to the last saved transaction id (CrossReference) set the new message
1268
+ $szLastTransId = $payment->getLastTransId();
1269
+ $transaction = $payment->getTransaction($szLastTransId);
1270
+ $szMagentoTxnType = $transaction->getTxnType();
1271
+ $szMessage = "Payment voided";
1272
+
1273
+ if($szMagentoTxnType == "capture")
1274
+ {
1275
+ $szMessage = "Payment voided";
1276
+ }
1277
+ else if($szMagentoTxnType == "authorization")
1278
+ {
1279
+ $szMessage = "PreAuthorization voided";
1280
+ }
1281
+ else if($szMagentoTxnType == "refund")
1282
+ {
1283
+ $szMessage = "Refund voided";
1284
+ }
1285
+ else
1286
+ {
1287
+ // general message
1288
+ $szMessage = "Payment voided";
1289
+ }
1290
+
1291
+ $error = $this->_runCrossReferenceTransaction($payment, $szTransactionType);
1292
+
1293
+ if ($error === false)
1294
+ {
1295
+ $order = $payment->getOrder();
1296
+ $invoices = $order->getInvoiceCollection();
1297
+ $payment = $order->getPayment();
1298
+ $arAdditionalInformationArray = $payment->getAdditionalInformation();
1299
+
1300
+ $arAdditionalInformationArray["Voided"] = 1;
1301
+ $payment->setAdditionalInformation($arAdditionalInformationArray);
1302
+ $payment->save();
1303
+
1304
+ // cancel the invoices
1305
+ foreach ($invoices as $invoice)
1306
+ {
1307
+ $invoice->cancel();
1308
+ $invoice->save();
1309
+ }
1310
+
1311
+ // udpate the order
1312
+ $order->setActionBy($payment->getLggdInAdminUname())
1313
+ ->setActionDate(date('Y-m-d H:i:s'))
1314
+ ->setVoided(1)
1315
+ ->setState('canceled', $orderStatus, $szMessage, false);
1316
+ $order->save();
1317
+
1318
+ $result = "0";
1319
+ }
1320
+ else
1321
+ {
1322
+ $result = $error;
1323
+ }
1324
+
1325
+ return $result;
1326
+ }
1327
+
1328
+ /**
1329
+ * CardSave COLLECTION functionality (capture called in Magento)
1330
+ *
1331
+ * @param Varien_Object $payment
1332
+ * @param unknown_type $szOrderID
1333
+ * @param unknown_type $szCrossReference
1334
+ * @return unknown
1335
+ */
1336
+ public function csvCollection(Varien_Object $payment, $szOrderID, $szCrossReference)
1337
+ {
1338
+ $szTransactionType = "COLLECTION";
1339
+ $orderStatus = 'csv_collected';
1340
+ $szMessage = 'Preauthorization successfully collected';
1341
+ $state = Mage_Sales_Model_Order::STATE_PROCESSING;
1342
+ $arAdditionalInformationArray;
1343
+
1344
+ $error = $this->_captureAuthorizedPayment($payment);
1345
+
1346
+ if($error === false)
1347
+ {
1348
+ $order = $payment->getOrder();
1349
+ $invoices = $order->getInvoiceCollection();
1350
+ $payment = $order->getPayment();
1351
+ $arAdditionalInformationArray = $payment->getAdditionalInformation();
1352
+
1353
+ $arAdditionalInformationArray["Collected"] = 1;
1354
+ $payment->setAdditionalInformation($arAdditionalInformationArray);
1355
+ $payment->save();
1356
+
1357
+ // update the invoices to paid status
1358
+ foreach ($invoices as $invoice)
1359
+ {
1360
+ $invoice->pay()->save();
1361
+ }
1362
+
1363
+ $order->setActionBy($payment->getLggdInAdminUname())
1364
+ ->setActionDate(date('Y-m-d H:i:s'))
1365
+ ->setState($state, $orderStatus, $szMessage, false);
1366
+ $order->save();
1367
+
1368
+ $result = "0";
1369
+ }
1370
+ else
1371
+ {
1372
+ $result = $error;
1373
+ }
1374
+
1375
+ return $result;
1376
+ }
1377
+
1378
+ /**
1379
+ * Private capture function for an authorized payment
1380
+ *
1381
+ * @param Varien_Object $payment
1382
+ * @return unknown
1383
+ */
1384
+ private function _captureAuthorizedPayment(Varien_Object $payment)
1385
+ {
1386
+ $error = false;
1387
+ $session = Mage::getSingleton('checkout/session');
1388
+
1389
+ try
1390
+ {
1391
+ // set the COLLECTION variable to true
1392
+ $session->setIsCollectionCrossReferenceTransaction(true);
1393
+
1394
+ $invoice = $payment->getOrder()->prepareInvoice();
1395
+ $invoice->register();
1396
+
1397
+ if ($this->_canCapture)
1398
+ {
1399
+ $invoice->capture();
1400
+ }
1401
+
1402
+ $payment->getOrder()->addRelatedObject($invoice);
1403
+ $payment->setCreatedInvoice($invoice);
1404
+ }
1405
+ catch(Exception $exc)
1406
+ {
1407
+ $error = "Couldn't capture pre-authorized payment. Message: ". $exc->getMessage();
1408
+ Mage::log($exc->getMessage());
1409
+ }
1410
+
1411
+ // remove the COLLECTION session variable once finished the COLLECTION attempt
1412
+ $session->setIsCollectionCrossReferenceTransaction(null);
1413
+
1414
+ return $error;
1415
+ }
1416
+
1417
+ /**
1418
+ * Internal CrossReference function for all VOID, REFUND, COLLECTION transaction types
1419
+ *
1420
+ * @param Varien_Object $payment
1421
+ * @param unknown_type $szTransactionType
1422
+ * @param unknown_type $amount
1423
+ * @return unknown
1424
+ */
1425
+ private function _runCrossReferenceTransaction(Varien_Object $payment, $szTransactionType, $amount = false)
1426
+ {
1427
+ $error = false;
1428
+ $boTransactionProcessed = false;
1429
+ $PaymentProcessorFullDomain;
1430
+ $rgeplRequestGatewayEntryPointList;
1431
+ $crtCrossReferenceTransaction;
1432
+ $crtrCrossReferenceTransactionResult;
1433
+ $todTransactionOutputData;
1434
+ $szMerchantID = $this->getConfigData('merchantid');
1435
+ $szPassword = $this->getConfigData('password');
1436
+ //
1437
+ $iclISOCurrencyList = CSV_ISOCurrencies::getISOCurrencyList();
1438
+ $szAmount;
1439
+ $nAmount;
1440
+ $szCurrencyShort;
1441
+ $iclISOCurrencyList;
1442
+ $power;
1443
+ $nDecimalAmount;
1444
+ $szNewCrossReference;
1445
+
1446
+ $order = $payment->getOrder();
1447
+ $szOrderID = $order->getRealOrderId();;
1448
+ //$szCrossReference = $payment->getLastTransId();
1449
+ $additionalInformation = $payment->getAdditionalInformation();
1450
+
1451
+ $szCrossReference = $additionalInformation["CrossReference"];
1452
+ $szCrossReference = $payment->getLastTransId();
1453
+
1454
+ // check the CrossRference and TransactionType parameters
1455
+ if(!$szCrossReference)
1456
+ {
1457
+ $error = 'Error occurred for '.$szTransactionType.': Missing Cross Reference';
1458
+ }
1459
+ if(!$szTransactionType)
1460
+ {
1461
+ $error = 'Error occurred for '.$szTransactionType.': Missing Transaction Type';
1462
+ }
1463
+
1464
+ if($error === false)
1465
+ {
1466
+ $PaymentProcessorFullDomain = $this->_getPaymentProcessorFullDomain();
1467
+
1468
+ $rgeplRequestGatewayEntryPointList = new CSV_RequestGatewayEntryPointList();
1469
+ $rgeplRequestGatewayEntryPointList->add("https://gw1.".$PaymentProcessorFullDomain, 100, 2);
1470
+ $rgeplRequestGatewayEntryPointList->add("https://gw2.".$PaymentProcessorFullDomain, 200, 2);
1471
+ $rgeplRequestGatewayEntryPointList->add("https://gw3.".$PaymentProcessorFullDomain, 300, 2);
1472
+
1473
+ $crtCrossReferenceTransaction = new CSV_CrossReferenceTransaction($rgeplRequestGatewayEntryPointList);
1474
+ $crtCrossReferenceTransaction->getMerchantAuthentication()->setMerchantID($szMerchantID);
1475
+ $crtCrossReferenceTransaction->getMerchantAuthentication()->setPassword($szPassword);
1476
+
1477
+ // if no amount is specified get the grand total amount
1478
+ if($amount === false)
1479
+ {
1480
+ $nAmount = $order->getBaseGrandTotal();
1481
+ }
1482
+ else
1483
+ {
1484
+ $nAmount = $amount;
1485
+ }
1486
+
1487
+ $szCurrencyShort = $order->getOrderCurrency()->getCurrencyCode();
1488
+ if ($szCurrencyShort != '' &&
1489
+ $iclISOCurrencyList->getISOCurrency($szCurrencyShort, $icISOCurrency))
1490
+ {
1491
+ $nCurrencyCode = new CSV_NullableInt($icISOCurrency->getISOCode());
1492
+ $crtCrossReferenceTransaction->getTransactionDetails()->getCurrencyCode()->setValue($icISOCurrency->getISOCode());
1493
+ }
1494
+
1495
+ // round the amount before use
1496
+ $nDecimalAmount = $this->_getRoundedAmount($nAmount, $icISOCurrency->getExponent());
1497
+
1498
+ $crtCrossReferenceTransaction->getTransactionDetails()->setOrderID($szOrderID);
1499
+ $crtCrossReferenceTransaction->getTransactionDetails()->getAmount()->setValue($nDecimalAmount);
1500
+
1501
+ $crtCrossReferenceTransaction->getTransactionDetails()->getMessageDetails()->setCrossReference($szCrossReference);
1502
+ $crtCrossReferenceTransaction->getTransactionDetails()->getMessageDetails()->setTransactionType($szTransactionType);
1503
+
1504
+ try
1505
+ {
1506
+ $boTransactionProcessed = $crtCrossReferenceTransaction->processTransaction($crtrCrossReferenceTransactionResult, $todTransactionOutputData);
1507
+ }
1508
+ catch (Exception $exc)
1509
+ {
1510
+ Mage::log("exception: ".$exc->getMessage());
1511
+ }
1512
+
1513
+ if ($boTransactionProcessed == false)
1514
+ {
1515
+ // could not communicate with the payment gateway
1516
+ $error = "Couldn't complete ".$szTransactionType." transaction. Details: ".$crtCrossReferenceTransaction->getLastException();
1517
+ $szLogMessage = $error;
1518
+ }
1519
+ else
1520
+ {
1521
+ switch($crtrCrossReferenceTransactionResult->getStatusCode())
1522
+ {
1523
+ case 0:
1524
+ $error = false;
1525
+ $szNewCrossReference = $todTransactionOutputData->getCrossReference();
1526
+ $szLogMessage = $szTransactionType . " CrossReference transaction successfully completed. Response object: ";
1527
+
1528
+ $payment->setTransactionId($szNewCrossReference)
1529
+ ->setParentTransactionId($szCrossReference)
1530
+ ->setIsTransactionClosed(1);
1531
+ $payment->save();
1532
+ break;
1533
+ default:
1534
+ $szLogMessage = $crtrCrossReferenceTransactionResult->getMessage();
1535
+ if ($crtrCrossReferenceTransactionResult->getErrorMessages()->getCount() > 0)
1536
+ {
1537
+ $szLogMessage = $szLogMessage.".";
1538
+
1539
+ for ($LoopIndex = 0; $LoopIndex < $crtrCrossReferenceTransactionResult->getErrorMessages()->getCount(); $LoopIndex++)
1540
+ {
1541
+ $szLogMessage = $szLogMessage.$crtrCrossReferenceTransactionResult->getErrorMessages()->getAt($LoopIndex).";";
1542
+ }
1543
+ $szLogMessage = $szLogMessage." ";
1544
+ }
1545
+
1546
+ $error = "Couldn't complete ".$szTransactionType." transaction for CrossReference: " . $szCrossReference . ". Payment Response: ".$szLogMessage;
1547
+ $szLogMessage = $szTransactionType . " CrossReference transaction failed. Response object: ";
1548
+ break;
1549
+ }
1550
+
1551
+ $szLogMessage = $szLogMessage.print_r($crtrCrossReferenceTransactionResult, 1);
1552
+ }
1553
+
1554
+ Mage::log($szLogMessage);
1555
+ }
1556
+
1557
+ return $error;
1558
+ }
1559
  }
app/code/local/Cardsave/Cardsaveonlinepayments/Model/Source/PaymentAction.php CHANGED
@@ -4,12 +4,19 @@ class Cardsave_Cardsaveonlinepayments_Model_Source_PaymentAction extends Mage_Pa
4
  {
5
  public function toOptionArray()
6
  {
7
- return array(
 
8
  // override the core class to ONLy allow capture transactions (immediate settlement)
9
- array(
10
- 'value' => Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE_CAPTURE,
11
- 'label' => Mage::helper('paygate')->__('Authorize and Capture')
 
12
  ),
 
 
 
 
 
13
  );
14
  }
15
  }
4
  {
5
  public function toOptionArray()
6
  {
7
+ return array
8
+ (
9
  // override the core class to ONLy allow capture transactions (immediate settlement)
10
+ array
11
+ (
12
+ 'value' => Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE,
13
+ 'label' => Mage::helper('paygate')->__('PREAUTH')
14
  ),
15
+ array
16
+ (
17
+ 'value' => Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE_CAPTURE,
18
+ 'label' => Mage::helper('paygate')->__('SALE')
19
+ )
20
  );
21
  }
22
  }
app/code/local/Cardsave/Cardsaveonlinepayments/controllers/PaymentController.php CHANGED
@@ -26,7 +26,7 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
26
  }
27
 
28
  /**
29
- * When a customer cancel payment from paypal.
30
  */
31
  public function cancelAction()
32
  {
@@ -42,17 +42,6 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
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
  }
58
 
@@ -62,20 +51,6 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
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());
80
  }
81
 
@@ -105,8 +80,8 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
105
  $cardsaveOrderId = Mage::getSingleton('checkout/session')->getCardsaveonlinepaymentsOrderId();
106
  $szOrderStatus = $order->getStatus();
107
 
108
- if($szOrderStatus != 'csv_paid')
109
- //if($cardsaveOrderId)
110
  {
111
  // cart is not empty
112
  // complete the 3D Secure transaction with the 3D Authorization result
@@ -185,7 +160,11 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
185
 
186
  if($nVersion >= 1410)
187
  {
188
- $this->_subtractOrderedItemsFromStock($order);
 
 
 
 
189
  $this->_updateInvoices($order, $szPaymentProcessorResponse);
190
  }
191
 
@@ -265,8 +244,8 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
265
  $szPreviousMessage = $this->getRequest()->getPost('PreviousMessage');
266
  $szOrderID = $this->getRequest()->getPost('OrderID');
267
 
268
- if($szOrderStatus != 'csv_paid')
269
- //if($cardsaveOrderId)
270
  {
271
  $checkout->saveOrderAfterRedirectedPaymentAction(true,
272
  $this->getRequest()->getPost('StatusCode'),
@@ -304,7 +283,8 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
304
  $szNotificationMessage = $szNotificationMessage.'<br/>'.$szPaymentProcessorResponse;
305
  }
306
 
307
- $order->getPayment()->setAdditionalData("CrossReference=".$this->getRequest()->getPost('CrossReference'));
 
308
 
309
  if($nVersion >= 1410)
310
  {
@@ -345,7 +325,11 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
345
 
346
  if($nVersion >= 1410)
347
  {
348
- $this->_subtractOrderedItemsFromStock($order);
 
 
 
 
349
  $this->_updateInvoices($order, $szPaymentProcessorResponse);
350
  }
351
 
@@ -419,7 +403,10 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
419
 
420
  if($nVersion >= 1410)
421
  {
422
- $this->_subtractOrderedItemsFromStock($order);
 
 
 
423
  $this->_updateInvoices($order, $szMessage);
424
  }
425
  }
@@ -547,7 +534,8 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
547
 
548
  if($szErrorMessage)
549
  {
550
- $order->getPayment()->setAdditionalData("CrossReference=".$szCrossReference);
 
551
 
552
  if($nVersion >= 1410)
553
  {
@@ -586,7 +574,10 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
586
 
587
  if($nVersion >= 1410)
588
  {
589
- $this->_subtractOrderedItemsFromStock($order);
 
 
 
590
  $this->_updateInvoices($order, $szMessage);
591
  }
592
 
@@ -780,8 +771,8 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
780
  $cardsaveOrderId = Mage::getSingleton('checkout/session')->getCardsaveonlinepaymentsOrderId();
781
  $szOrderStatus = $order->getStatus();
782
 
783
- if($szOrderStatus != 'csv_paid')
784
- //if($cardsaveOrderId)
785
  {
786
  $checkout->saveOrderAfterRedirectedPaymentAction(false,
787
  $this->getRequest()->getPost('StatusCode'),
@@ -824,7 +815,8 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
824
  $szNotificationMessage = $szNotificationMessage.'<br/>'.$szPaymentProcessorResponse;
825
  }
826
 
827
- $order->getPayment()->setAdditionalData("CrossReference=".$this->getRequest()->getPost('CrossReference'));
 
828
 
829
  if($nVersion >= 1410)
830
  {
@@ -866,7 +858,11 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
866
 
867
  if($nVersion >= 1410)
868
  {
869
- $this->_subtractOrderedItemsFromStock($order);
 
 
 
 
870
  $this->_updateInvoices($order, $szPaymentProcessorResponse);
871
  }
872
 
@@ -882,71 +878,6 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
882
  $this->_redirect('checkout/onepage/success', array('_secure' => true));
883
  }
884
  }
885
-
886
- /**
887
- * Deduct the order items from the stock
888
- *
889
- * @param unknown_type $order
890
- */
891
- private function _subtractOrderedItemsFromStock($order)
892
- {
893
- $nVersion = Mage::getModel('cardsaveonlinepayments/direct')->getVersion();
894
- $isCustomStockManagementEnabled = Mage::getModel('cardsaveonlinepayments/direct')->getConfigData('customstockmanagementenabled');
895
-
896
- if($nVersion >= 1410 &&
897
- $isCustomStockManagementEnabled)
898
- {
899
- $items = $order->getAllItems();
900
- foreach ($items as $itemId => $item)
901
- {
902
- // ordered quantity of the item from stock
903
- $quantity = $item->getQtyOrdered();
904
- $productId = $item->getProductId();
905
-
906
- $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($productId);
907
- $stockManagement = $stock->getManageStock();
908
-
909
- if($stockManagement)
910
- {
911
- $stock->setQty($stock->getQty() - $quantity);
912
- $stock->save();
913
- }
914
- }
915
- }
916
- }
917
-
918
- /**
919
- * Re-add the order items to the stock to balance the incorrect stock management before a payment is completed
920
- *
921
- * @param unknown_type $order
922
- */
923
- private function _addOrderedItemsToStock($order)
924
- {
925
- $nVersion = Mage::getModel('cardsaveonlinepayments/direct')->getVersion();
926
- $isCustomStockManagementEnabled = Mage::getModel('cardsaveonlinepayments/direct')->getConfigData('customstockmanagementenabled');
927
-
928
- if($nVersion >= 1410 &&
929
- $isCustomStockManagementEnabled)
930
- {
931
- $items = $order->getAllItems();
932
- foreach ($items as $itemId => $item)
933
- {
934
- // ordered quantity of the item from stock
935
- $quantity = $item->getQtyOrdered();
936
- $productId = $item->getProductId();
937
-
938
- $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($productId);
939
- $stockManagement = $stock->getManageStock();
940
-
941
- if($stockManagement)
942
- {
943
- $stock->setQty($stock->getQty() + $quantity);
944
- $stock->save();
945
- }
946
- }
947
- }
948
- }
949
-
950
 
951
  private function _clearSessionVariables()
952
  {
@@ -981,7 +912,25 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
981
  private function _updateInvoices($order, $message)
982
  {
983
  $invoices = $order->getInvoiceCollection();
984
- $status = Mage_Sales_Model_Order::STATE_PROCESSING;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
985
 
986
  foreach ($invoices as $invoice)
987
  {
@@ -989,8 +938,18 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
989
  $invoice->pay()->save();
990
  }
991
  // add a comment to the order comments
992
- //$order->addStatusToHistory($status, $message, false);
993
- $order->setState($status, 'csv_paid', $message, false);
 
 
 
 
 
 
 
 
 
 
994
  $order->save();
995
  }
996
 
@@ -1018,7 +977,7 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
1018
  }
1019
  else if($szStatusCode == '20')
1020
  {
1021
- Mage::getSingleton('core/session')->addError('Duplicate payment attempted for Order ID: '.$szOrderID.'. Previous message: '.$szPreviousMessage.'. This order has already been successfully paid and processed. </br/>IMPORTANT: please do not attempt to click the back button in your browser and re-submit the payment for this order as it could cause duplicate charges to your bank account.');
1022
  }
1023
  else
1024
  {
@@ -1026,4 +985,48 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
1026
  }
1027
  }
1028
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1029
  }
26
  }
27
 
28
  /**
29
+ * When a customer cancel payment.
30
  */
31
  public function cancelAction()
32
  {
42
  */
43
  public function redirectAction()
44
  {
 
 
 
 
 
 
 
 
 
 
 
45
  $this->getResponse()->setBody($this->getLayout()->createBlock('cardsaveonlinepayments/redirect')->toHtml());
46
  }
47
 
51
  */
52
  public function threedsecureAction()
53
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  $this->getResponse()->setBody($this->getLayout()->createBlock('cardsaveonlinepayments/threedsecure')->toHtml());
55
  }
56
 
80
  $cardsaveOrderId = Mage::getSingleton('checkout/session')->getCardsaveonlinepaymentsOrderId();
81
  $szOrderStatus = $order->getStatus();
82
 
83
+ if($szOrderStatus != 'csv_paid' &&
84
+ $szOrderStatus != 'csv_preauth')
85
  {
86
  // cart is not empty
87
  // complete the 3D Secure transaction with the 3D Authorization result
160
 
161
  if($nVersion >= 1410)
162
  {
163
+ // TODO : no need to remove stock item as the system will do it in 1.6 version
164
+ if($nVersion < 1600)
165
+ {
166
+ Mage::getModel('cardsaveonlinepayments/direct')->subtractOrderedItemsFromStock($order);
167
+ }
168
  $this->_updateInvoices($order, $szPaymentProcessorResponse);
169
  }
170
 
244
  $szPreviousMessage = $this->getRequest()->getPost('PreviousMessage');
245
  $szOrderID = $this->getRequest()->getPost('OrderID');
246
 
247
+ if($szOrderStatus != 'csv_paid' &&
248
+ $szOrderStatus != 'csv_preauth')
249
  {
250
  $checkout->saveOrderAfterRedirectedPaymentAction(true,
251
  $this->getRequest()->getPost('StatusCode'),
283
  $szNotificationMessage = $szNotificationMessage.'<br/>'.$szPaymentProcessorResponse;
284
  }
285
 
286
+ $model->setPaymentAdditionalInformation($order->getPayment(), $this->getRequest()->getPost('CrossReference'));
287
+ //$order->getPayment()->setAdditionalData("CrossReference=".$this->getRequest()->getPost('CrossReference'));
288
 
289
  if($nVersion >= 1410)
290
  {
325
 
326
  if($nVersion >= 1410)
327
  {
328
+ // TODO : no need to remove stock item as the system will do it in 1.6 version
329
+ if($nVersion < 1600)
330
+ {
331
+ $model->subtractOrderedItemsFromStock($order);
332
+ }
333
  $this->_updateInvoices($order, $szPaymentProcessorResponse);
334
  }
335
 
403
 
404
  if($nVersion >= 1410)
405
  {
406
+ if($nVersion < 1600)
407
+ {
408
+ $model->subtractOrderedItemsFromStock($order);
409
+ }
410
  $this->_updateInvoices($order, $szMessage);
411
  }
412
  }
534
 
535
  if($szErrorMessage)
536
  {
537
+ $model->setPaymentAdditionalInformation($order->getPayment(), $szCrossReference);
538
+ //$order->getPayment()->setAdditionalData("CrossReference=".$szCrossReference);
539
 
540
  if($nVersion >= 1410)
541
  {
574
 
575
  if($nVersion >= 1410)
576
  {
577
+ if($nVersion < 1600)
578
+ {
579
+ $model->subtractOrderedItemsFromStock($order);
580
+ }
581
  $this->_updateInvoices($order, $szMessage);
582
  }
583
 
771
  $cardsaveOrderId = Mage::getSingleton('checkout/session')->getCardsaveonlinepaymentsOrderId();
772
  $szOrderStatus = $order->getStatus();
773
 
774
+ if($szOrderStatus != 'csv_paid' &&
775
+ $szOrderStatus != 'csv_preauth')
776
  {
777
  $checkout->saveOrderAfterRedirectedPaymentAction(false,
778
  $this->getRequest()->getPost('StatusCode'),
815
  $szNotificationMessage = $szNotificationMessage.'<br/>'.$szPaymentProcessorResponse;
816
  }
817
 
818
+ $model->setPaymentAdditionalInformation($order->getPayment(), $this->getRequest()->getPost('CrossReference'));
819
+ //$order->getPayment()->setAdditionalData("CrossReference=".$this->getRequest()->getPost('CrossReference'));
820
 
821
  if($nVersion >= 1410)
822
  {
858
 
859
  if($nVersion >= 1410)
860
  {
861
+ // TODO : no need to remove stock item as the system will do it in 1.6 version
862
+ if($nVersion < 1600)
863
+ {
864
+ $model->subtractOrderedItemsFromStock($order);
865
+ }
866
  $this->_updateInvoices($order, $szPaymentProcessorResponse);
867
  }
868
 
878
  $this->_redirect('checkout/onepage/success', array('_secure' => true));
879
  }
880
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
881
 
882
  private function _clearSessionVariables()
883
  {
912
  private function _updateInvoices($order, $message)
913
  {
914
  $invoices = $order->getInvoiceCollection();
915
+ $state = Mage_Sales_Model_Order::STATE_PROCESSING;
916
+ $payment = $order->getPayment();
917
+ $transaction;
918
+ $session = Mage::getSingleton('checkout/session');
919
+ $szNewCrossReference;
920
+
921
+ $transactionId = $payment->getLastTransId();
922
+ $transaction = $payment->getTransaction($transactionId);
923
+ $transactionType = $transaction->getTxnType();
924
+
925
+ if($session->getNewCrossReference())
926
+ {
927
+ $szNewCrossReference = $session->getNewCrossReference();
928
+ $value = $transaction->setTxnId($szNewCrossReference);
929
+ $transaction->save();
930
+ $payment->setLastTransId($szNewCrossReference);
931
+
932
+ $session->setNewCrossReference(null);
933
+ }
934
 
935
  foreach ($invoices as $invoice)
936
  {
938
  $invoice->pay()->save();
939
  }
940
  // add a comment to the order comments
941
+ if($transactionType == 'authorization')
942
+ {
943
+ $order->setState($state, 'csv_preauth', $message, true);
944
+ }
945
+ else if($transactionType == 'capture')
946
+ {
947
+ $order->setState($state, 'csv_paid', $message, true);
948
+ }
949
+ else
950
+ {
951
+ Mage::throwException('invalid transaction type [' . $transactionType . '] for invoice updating');
952
+ }
953
  $order->save();
954
  }
955
 
977
  }
978
  else if($szStatusCode == '20')
979
  {
980
+ Mage::getSingleton('core/session')->addError('Duplicate payment attempted for Order ID: '.$szOrderID.'. Previous Payment Processor Response: '.$szPreviousMessage.'. This order has already been successfully paid and processed. </br/>IMPORTANT: please do not attempt to click the back button in your browser and re-submit the payment for this order as it could cause duplicate charges to your bank account.');
981
  }
982
  else
983
  {
985
  }
986
  }
987
  }
988
+
989
+ /**
990
+ * Refund actioned when the user clicks the VOID button in the admin backend
991
+ *
992
+ * @return unknown
993
+ */
994
+ public function voidAction()
995
+ {
996
+ $model = Mage::getSingleton('cardsaveonlinepayments/direct');
997
+ $parameters = $this->getRequest()->getParams();
998
+ $szOrderID = $parameters['OrderID'];
999
+ $szCrossReference = $parameters['CrossReference'];
1000
+
1001
+ $order = Mage::getModel('sales/order')->loadByIncrementId((int)$szOrderID);
1002
+ $payment = $order->getPayment();
1003
+
1004
+ $result = Mage::getModel('cardsaveonlinepayments/direct')->csvVoid($payment);
1005
+
1006
+ if($result == "0")
1007
+ {
1008
+ $model->addOrderedItemsToStock($order);
1009
+ }
1010
+
1011
+ return $this->getResponse()->setBody($result);
1012
+ }
1013
+
1014
+ /**
1015
+ * Refund actioned when the user clicks the COLLECT button in the admin backend
1016
+ *
1017
+ * @return unknown
1018
+ */
1019
+ public function collectionAction()
1020
+ {
1021
+ $parameters = $this->getRequest()->getParams();
1022
+ $szOrderID = $parameters['OrderID'];
1023
+ $szCrossReference = $parameters['CrossReference'];
1024
+
1025
+ $order = Mage::getModel('sales/order')->loadByIncrementId((int)$szOrderID);
1026
+ $payment = $order->getPayment();
1027
+
1028
+ $result = Mage::getModel('cardsaveonlinepayments/direct')->csvCollection($payment, $szOrderID, $szCrossReference);
1029
+
1030
+ return $this->getResponse()->setBody($result);
1031
+ }
1032
  }
app/code/local/Cardsave/Cardsaveonlinepayments/etc/config.xml CHANGED
@@ -37,6 +37,16 @@
37
  <cardsaveonlinepayments>
38
  <class>Cardsave_Cardsaveonlinepayments_Block</class>
39
  </cardsaveonlinepayments>
 
 
 
 
 
 
 
 
 
 
40
  </blocks>
41
  <!-- Define the helper class type -->
42
  <helpers>
@@ -51,6 +61,15 @@
51
  </helpers>
52
  </global>
53
 
 
 
 
 
 
 
 
 
 
54
  <frontend>
55
  <secure_url>
56
  <cardsaveonlinepayments>/cardsaveonlinepayments/standard</cardsaveonlinepayments>
37
  <cardsaveonlinepayments>
38
  <class>Cardsave_Cardsaveonlinepayments_Block</class>
39
  </cardsaveonlinepayments>
40
+ <payment>
41
+ <rewrite>
42
+ <info_cc>Cardsave_Cardsaveonlinepayments_Block_Payment_Info_Cc</info_cc>
43
+ </rewrite>
44
+ </payment>
45
+ <adminhtml>
46
+ <rewrite>
47
+ <sales_order_payment>Cardsave_Cardsaveonlinepayments_Block_Adminhtml_Sales_Order_Payment</sales_order_payment>
48
+ </rewrite>
49
+ </adminhtml>
50
  </blocks>
51
  <!-- Define the helper class type -->
52
  <helpers>
61
  </helpers>
62
  </global>
63
 
64
+ <adminhtml>
65
+ <layout>
66
+ <updates>
67
+ <cardsaveonlinepayments>
68
+ <file>cardsaveonlinepayments.xml</file>
69
+ </cardsaveonlinepayments>
70
+ </updates>
71
+ </layout>
72
+ </adminhtml>
73
  <frontend>
74
  <secure_url>
75
  <cardsaveonlinepayments>/cardsaveonlinepayments/standard</cardsaveonlinepayments>
app/code/local/Cardsave/Cardsaveonlinepayments/sql/cardsaveonlinepayments_setup/mysql4-install-0.1.0.php CHANGED
@@ -28,6 +28,10 @@ try
28
  DELETE FROM `{$installer->getTable('sales_order_status')}` WHERE (`status`='csv_pending');
29
  DELETE FROM `{$installer->getTable('sales_order_status')}` WHERE (`status`='csv_pending_hosted_payment');
30
  DELETE FROM `{$installer->getTable('sales_order_status')}` WHERE (`status`='csv_pending_threed_secure');
 
 
 
 
31
 
32
  INSERT INTO `{$installer->getTable('sales_order_status')}` (`status`, `label`) VALUES ('csv_failed_hosted_payment', 'CardSave - Failed Payment');
33
  INSERT INTO `{$installer->getTable('sales_order_status')}` (`status`, `label`) VALUES ('csv_failed_threed_secure', 'CardSave - Failed 3D Secure');
@@ -35,6 +39,10 @@ try
35
  INSERT INTO `{$installer->getTable('sales_order_status')}` (`status`, `label`) VALUES ('csv_pending', 'CardSave - Pending Payment');
36
  INSERT INTO `{$installer->getTable('sales_order_status')}` (`status`, `label`) VALUES ('csv_pending_hosted_payment', 'CardSave - Pending Hosted Payment');
37
  INSERT INTO `{$installer->getTable('sales_order_status')}` (`status`, `label`) VALUES ('csv_pending_threed_secure', 'CardSave - Pending 3D Secure');
 
 
 
 
38
  ");
39
  }
40
  catch(Exception $exc)
28
  DELETE FROM `{$installer->getTable('sales_order_status')}` WHERE (`status`='csv_pending');
29
  DELETE FROM `{$installer->getTable('sales_order_status')}` WHERE (`status`='csv_pending_hosted_payment');
30
  DELETE FROM `{$installer->getTable('sales_order_status')}` WHERE (`status`='csv_pending_threed_secure');
31
+ DELETE FROM `{$installer->getTable('sales_order_status')}` WHERE (`status`='csv_refunded');
32
+ DELETE FROM `{$installer->getTable('sales_order_status')}` WHERE (`status`='csv_voided');
33
+ DELETE FROM `{$installer->getTable('sales_order_status')}` WHERE (`status`='csv_preauth');
34
+ DELETE FROM `{$installer->getTable('sales_order_status')}` WHERE (`status`='csv_collected');
35
 
36
  INSERT INTO `{$installer->getTable('sales_order_status')}` (`status`, `label`) VALUES ('csv_failed_hosted_payment', 'CardSave - Failed Payment');
37
  INSERT INTO `{$installer->getTable('sales_order_status')}` (`status`, `label`) VALUES ('csv_failed_threed_secure', 'CardSave - Failed 3D Secure');
39
  INSERT INTO `{$installer->getTable('sales_order_status')}` (`status`, `label`) VALUES ('csv_pending', 'CardSave - Pending Payment');
40
  INSERT INTO `{$installer->getTable('sales_order_status')}` (`status`, `label`) VALUES ('csv_pending_hosted_payment', 'CardSave - Pending Hosted Payment');
41
  INSERT INTO `{$installer->getTable('sales_order_status')}` (`status`, `label`) VALUES ('csv_pending_threed_secure', 'CardSave - Pending 3D Secure');
42
+ INSERT INTO `{$installer->getTable('sales_order_status')}` (`status`, `label`) VALUES ('csv_refunded', 'CardSave - Payment Refunded');
43
+ INSERT INTO `{$installer->getTable('sales_order_status')}` (`status`, `label`) VALUES ('csv_voided', 'CardSave - Payment Voided');
44
+ INSERT INTO `{$installer->getTable('sales_order_status')}` (`status`, `label`) VALUES ('csv_preauth', 'CardSave - PreAuthorized');
45
+ INSERT INTO `{$installer->getTable('sales_order_status')}` (`status`, `label`) VALUES ('csv_collected', 'CardSave - Payment Collected');
46
  ");
47
  }
48
  catch(Exception $exc)
app/code/local/Cardsave/Sales/Model/Order/Payment.php CHANGED
@@ -175,7 +175,21 @@ class Cardsave_Sales_Model_Order_Payment extends Mage_Sales_Model_Order_Payment
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));
@@ -242,7 +256,14 @@ class Cardsave_Sales_Model_Order_Payment extends Mage_Sales_Model_Order_Payment
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())
@@ -263,11 +284,18 @@ class Cardsave_Sales_Model_Order_Payment extends Mage_Sales_Model_Order_Payment
263
  }
264
  else
265
  {
266
- $orderStatus = $methodInstance->getConfigData('order_status');
267
- if (!$orderStatus || $order->getIsVirtual())
268
  {
269
- $orderStatus = $order->getConfig()->getStateDefaultStatus($orderState);
270
- }
 
 
 
 
 
 
 
 
271
  }
272
 
273
  $isCustomerNotified = (null !== $orderIsNotified) ? $orderIsNotified : $order->getCustomerNoteNotify();
@@ -365,26 +393,45 @@ class Cardsave_Sales_Model_Order_Payment extends Mage_Sales_Model_Order_Payment
365
  }
366
 
367
  $orderIsNotified = null;
368
- if ($stateObject->getState() && $stateObject->getStatus()) {
 
369
  $orderState = $stateObject->getState();
370
- $orderStatus = $stateObject->getStatus();
 
 
 
 
 
 
 
371
  $orderIsNotified = $stateObject->getIsNotified();
372
- } else {
 
 
373
  /*
374
  * this flag will set if the order went to as authorization under fraud service for payflowpro
375
  */
376
- if ($this->getFraudFlag()) {
 
377
  $orderStatus = $methodInstance->getConfigData('fraud_order_status');
378
  $orderState = Mage_Sales_Model_Order::STATE_HOLDED;
379
- } else {
380
- /**
381
- * Change order status if it specified
382
- */
383
  $orderStatus = $methodInstance->getConfigData('order_status');
 
384
  }
385
 
386
- if (!$orderStatus || $this->getOrder()->getIsVirtual()) {
387
- $orderStatus = $this->getOrder()->getConfig()->getStateDefaultStatus($orderState);
 
 
 
 
 
 
 
 
388
  }
389
  }
390
 
@@ -400,4 +447,107 @@ class Cardsave_Sales_Model_Order_Payment extends Mage_Sales_Model_Order_Payment
400
  return $this;
401
  }
402
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
403
  }
175
  public function place()
176
  {
177
  $nVersion = Mage::getModel('cardsaveonlinepayments/direct')->getVersion();
178
+ $paymentAction = Mage::getModel('cardsaveonlinepayments/direct')->getConfigData('payment_action');
179
+
180
+ if($paymentAction == Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE_CAPTURE)
181
+ {
182
+ $csvOrderStatus = "csv_paid";
183
+ }
184
+ else if($paymentAction == Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE)
185
+ {
186
+ $csvOrderStatus = "csv_preauth";
187
+ }
188
+ else
189
+ {
190
+ $csvOrderStatus = null;
191
+ }
192
+
193
  if($nVersion >= 1411 || $nVersion == 1410 || $nVersion == 1401 || $nVersion == 1400)
194
  {
195
  Mage::dispatchEvent('sales_order_payment_place_start', array('payment' => $this));
256
  if ($stateObject->getState() && $stateObject->getStatus())
257
  {
258
  $orderState = $stateObject->getState();
259
+ if($csvOrderStatus == null)
260
+ {
261
+ $orderStatus = $stateObject->getStatus();
262
+ }
263
+ else
264
+ {
265
+ $orderStatus = $csvOrderStatus;
266
+ }
267
  $orderIsNotified = $stateObject->getIsNotified();
268
  }
269
  else if($order->getIsThreeDSecurePending())
284
  }
285
  else
286
  {
287
+ if($csvOrderStatus == null)
 
288
  {
289
+ $orderStatus = $methodInstance->getConfigData('order_status');
290
+ if (!$orderStatus || $order->getIsVirtual())
291
+ {
292
+ $orderStatus = $order->getConfig()->getStateDefaultStatus($orderState);
293
+ }
294
+ }
295
+ else
296
+ {
297
+ $orderStatus = $csvOrderStatus;
298
+ }
299
  }
300
 
301
  $isCustomerNotified = (null !== $orderIsNotified) ? $orderIsNotified : $order->getCustomerNoteNotify();
393
  }
394
 
395
  $orderIsNotified = null;
396
+ if ($stateObject->getState() && $stateObject->getStatus())
397
+ {
398
  $orderState = $stateObject->getState();
399
+ if($csvOrderStatus == null)
400
+ {
401
+ $orderStatus = $stateObject->getStatus();
402
+ }
403
+ else
404
+ {
405
+ $orderStatus = $csvOrderStatus;
406
+ }
407
  $orderIsNotified = $stateObject->getIsNotified();
408
+ }
409
+ else
410
+ {
411
  /*
412
  * this flag will set if the order went to as authorization under fraud service for payflowpro
413
  */
414
+ if ($this->getFraudFlag())
415
+ {
416
  $orderStatus = $methodInstance->getConfigData('fraud_order_status');
417
  $orderState = Mage_Sales_Model_Order::STATE_HOLDED;
418
+ }
419
+ else
420
+ {
 
421
  $orderStatus = $methodInstance->getConfigData('order_status');
422
+
423
  }
424
 
425
+ if($csvOrderStatus == null)
426
+ {
427
+ if (!$orderStatus || $this->getOrder()->getIsVirtual())
428
+ {
429
+ $orderStatus = $this->getOrder()->getConfig()->getStateDefaultStatus($orderState);
430
+ }
431
+ }
432
+ else
433
+ {
434
+ $orderStatus = $csvOrderStatus;
435
  }
436
  }
437
 
447
  return $this;
448
  }
449
  }
450
+
451
+ /**
452
+ * Create transaction,
453
+ * prepare its insertion into hierarchy and add its information to payment and comments
454
+ *
455
+ * To add transactions and related information,
456
+ * the following information should be set to payment before processing:
457
+ * - transaction_id
458
+ * - is_transaction_closed (optional) - whether transaction should be closed or open (closed by default)
459
+ * - parent_transaction_id (optional)
460
+ * - should_close_parent_transaction (optional) - whether to close parent transaction (closed by default)
461
+ *
462
+ * If the sales document is specified, it will be linked to the transaction as related for future usage.
463
+ * Currently transaction ID is set into the sales object
464
+ * This method writes the added transaction ID into last_trans_id field of the payment object
465
+ *
466
+ * To make sure transaction object won't cause trouble before saving, use $failsafe = true
467
+ *
468
+ * @param string $type
469
+ * @param Mage_Sales_Model_Abstract $salesDocument
470
+ * @param bool $failsafe
471
+ * @return null|Mage_Sales_Model_Order_Payment_Transaction
472
+ */
473
+ protected function _addTransaction($type, $salesDocument = null, $failsafe = false)
474
+ {
475
+ $model = Mage::getModel('cardsaveonlinepayments/direct');
476
+ $nVersion = $model->getVersion();
477
+
478
+ if($nVersion >= 1501)
479
+ {
480
+ if ($this->getSkipTransactionCreation())
481
+ {
482
+ $this->unsTransactionId();
483
+ return null;
484
+ }
485
+ }
486
+
487
+ // look for set transaction ids
488
+ $transactionId = $this->getTransactionId();
489
+ if (null !== $transactionId)
490
+ {
491
+ // set transaction parameters
492
+ $transaction = false;
493
+ if ($this->getOrder()->getId())
494
+ {
495
+ $transaction = $this->_lookupTransaction($transactionId);
496
+ }
497
+
498
+ if (!$transaction)
499
+ {
500
+ $transaction = Mage::getModel('sales/order_payment_transaction')->setTxnId($transactionId);
501
+ }
502
+ $transaction
503
+ ->setOrderPaymentObject($this)
504
+ ->setTxnType($type)
505
+ ->isFailsafe($failsafe);
506
+
507
+ if ($this->hasIsTransactionClosed())
508
+ {
509
+ $transaction->setIsClosed((int)$this->getIsTransactionClosed());
510
+ }
511
+
512
+ //set transaction addition information
513
+ if ($this->_transactionAdditionalInfo)
514
+ {
515
+ foreach ($this->_transactionAdditionalInfo as $key => $value)
516
+ {
517
+ $transaction->setAdditionalInformation($key, $value);
518
+ }
519
+ }
520
+
521
+ // link with sales entities
522
+ $this->setLastTransId($transactionId);
523
+ $this->setCreatedTransaction($transaction);
524
+ $this->getOrder()->addRelatedObject($transaction);
525
+ if ($salesDocument && $salesDocument instanceof Mage_Sales_Model_Abstract)
526
+ {
527
+ $salesDocument->setTransactionId($transactionId);
528
+ // TODO: linking transaction with the sales document
529
+ }
530
+
531
+ // link with parent transaction
532
+ $parentTransactionId = $this->getParentTransactionId();
533
+
534
+ if ($parentTransactionId)
535
+ {
536
+ $transaction->setParentTxnId($parentTransactionId);
537
+ if ($this->getShouldCloseParentTransaction())
538
+ {
539
+ $parentTransaction = $this->_lookupTransaction($parentTransactionId);
540
+ if ($parentTransaction)
541
+ {
542
+ if (!$parentTransaction->getIsClosed())
543
+ {
544
+ $parentTransaction->isFailsafe($failsafe)->close(false);
545
+ }
546
+ $this->getOrder()->addRelatedObject($parentTransaction);
547
+ }
548
+ }
549
+ }
550
+ return $transaction;
551
+ }
552
+ }
553
  }
app/code/local/Cardsave/Sales/etc/config.xml CHANGED
@@ -11,8 +11,8 @@
11
  <rewrite>
12
  <order>Cardsave_Sales_Model_Order</order>
13
  <order_invoice>Cardsave_Sales_Model_Order_Invoice</order_invoice>
14
- <order_payment>Cardsave_Sales_Model_Order_Payment</order_payment>
15
- <service_quote>Cardsave_Sales_Model_Service_Quote</service_quote>
16
  </rewrite>
17
  </sales>
18
  </models>
@@ -23,11 +23,11 @@
23
  <label>CardSave - Successful Payment</label>
24
  </csv_paid>
25
  <csv_pending_threed_secure translate="label">
26
- <label>CardSave - Pending 3D Secure</label>
27
- </csv_pending_threed_secure>
28
- <csv_failed_threed_secure translate="label">
29
- <label>CardSave - Failed 3D Secure</label>
30
- </csv_failed_threed_secure>
31
  <csv_pending translate="label">
32
  <label>CardSave - Pending Hosted Payment</label>
33
  </csv_pending>
@@ -37,6 +37,18 @@
37
  <csv_failed_hosted_payment translate="label">
38
  <label>CardSave - Failed Payment</label>
39
  </csv_failed_hosted_payment>
 
 
 
 
 
 
 
 
 
 
 
 
40
  </statuses>
41
  </order>
42
  </sales>
11
  <rewrite>
12
  <order>Cardsave_Sales_Model_Order</order>
13
  <order_invoice>Cardsave_Sales_Model_Order_Invoice</order_invoice>
14
+ <order_payment>Cardsave_Sales_Model_Order_Payment</order_payment>
15
+ <service_quote>Cardsave_Sales_Model_Service_Quote</service_quote>
16
  </rewrite>
17
  </sales>
18
  </models>
23
  <label>CardSave - Successful Payment</label>
24
  </csv_paid>
25
  <csv_pending_threed_secure translate="label">
26
+ <label>CardSave - Pending 3D Secure</label>
27
+ </csv_pending_threed_secure>
28
+ <csv_failed_threed_secure translate="label">
29
+ <label>CardSave - Failed 3D Secure</label>
30
+ </csv_failed_threed_secure>
31
  <csv_pending translate="label">
32
  <label>CardSave - Pending Hosted Payment</label>
33
  </csv_pending>
37
  <csv_failed_hosted_payment translate="label">
38
  <label>CardSave - Failed Payment</label>
39
  </csv_failed_hosted_payment>
40
+ <csv_refunded translate="label">
41
+ <label>CardSave - Payment Refunded</label>
42
+ </csv_refunded>
43
+ <csv_voided translate="label">
44
+ <label>CardSave - Payment Voided</label>
45
+ </csv_voided>
46
+ <csv_preauth translate="label">
47
+ <label>CardSave - Payment PreAuthorized</label>
48
+ </csv_preauth>
49
+ <csv_collected translate="label">
50
+ <label>CardSave - Payment Collected</label>
51
+ </csv_collected>
52
  </statuses>
53
  </order>
54
  </sales>
app/design/adminhtml/default/default/layout/cardsaveonlinepayments.xml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout>
3
+ <adminhtml_sales_order_view>
4
+ <reference name="head">
5
+ <action method="addItem">
6
+ <type>skin_js</type>
7
+ <name>cardsaveonlinepayments.js</name>
8
+ </action>
9
+ </reference>
10
+ </adminhtml_sales_order_view>
11
+ </layout>
app/design/adminhtml/default/default/template/payment/info/cc_cardsaveonlinepayments.phtml ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $m_boTransactionAuthorised = false;
3
+ $m_boValidCrossReference = false;
4
+ $m_boExtensionVersionWithCrossReferenceFeature = true;
5
+
6
+ $m_order = $this->getInfo()->getOrder();
7
+ $m_payment = $m_order->getPayment();
8
+ $m_szOrderID = $m_order->getRealOrderId();
9
+ $m_szOrderStatus = $m_order->getStatus();
10
+ $m_szAmount = $m_order->getBaseGrandTotal();
11
+ $m_nPaymentVoided = 0;//(int)$m_order->getVoided();
12
+ $m_nPaymentRefunded = 0;
13
+ $m_nPaymentCollected = 0;
14
+ $m_boCanVoid = false;
15
+ $m_boCanCollect = false;
16
+
17
+ // get the additional information column data for a Magento payment
18
+ $additional_info = $m_payment->getAdditionalInformation();
19
+ $szToday = date("Ymd");
20
+
21
+ // for redirected transactions the TransactionId can't be updated with a new CrossReference (ie: 3DS transaction), need to revert back to additional_info
22
+ $additionalInfo = $m_payment->getAdditionalInformation();
23
+ if(!key_exists("CrossReference", $additionalInfo))
24
+ {
25
+ $szCrossReference = false;
26
+ }
27
+ else
28
+ {
29
+ $szCrossReference = $additional_info["CrossReference"];
30
+ }
31
+
32
+ if(!key_exists("TransactionDateTime", $additionalInfo))
33
+ {
34
+ $szTransactionDateTime = false;
35
+ }
36
+ else
37
+ {
38
+ $szTransactionDateTime = $additional_info["TransactionDateTime"];
39
+ }
40
+
41
+ if(!key_exists("TransactionType", $additionalInfo))
42
+ {
43
+ $szTransactionType = false;
44
+ }
45
+ else
46
+ {
47
+ $szTransactionType = $additional_info["TransactionType"];
48
+ }
49
+
50
+
51
+ if(key_exists("Voided", $additionalInfo))
52
+ {
53
+ $m_nPaymentVoided = (int)$additional_info["Voided"];
54
+ }
55
+ if(key_exists("Refunded", $additionalInfo))
56
+ {
57
+ $m_nPaymentRefunded = (int)$additional_info["Refunded"];
58
+ }
59
+ if(key_exists("Collected", $additionalInfo))
60
+ {
61
+ $m_nPaymentCollected = (int)$additional_info["Collected"];
62
+ }
63
+
64
+ if(!$szCrossReference ||
65
+ !$szTransactionDateTime ||
66
+ !$szTransactionType)
67
+ {
68
+ $m_boExtensionVersionWithCrossReferenceFeature = false;
69
+ }
70
+ else
71
+ {
72
+ if($szTransactionType == 'PREAUTH')
73
+ {
74
+ $m_szTransactionType = "PREAUTH";
75
+
76
+ // check if payment can be voided
77
+ if (!$m_nPaymentVoided &&
78
+ !$m_nPaymentRefunded &&
79
+ // payment must be successful
80
+ $m_szOrderStatus == "csv_preauth")
81
+ {
82
+ if (strtotime($szToday) == strtotime($szTransactionDateTime))
83
+ {
84
+ $m_boCanVoid = true;
85
+ }
86
+ }
87
+
88
+ // check if payment can be collected
89
+ if(!$m_nPaymentVoided &&
90
+ !$m_nPaymentCollected &&
91
+ // payment must be successful
92
+ $m_szOrderStatus == "csv_preauth")
93
+ {
94
+ $m_boCanCollect = true;
95
+ }
96
+ }
97
+ else if($szTransactionType == 'SALE')
98
+ {
99
+ $m_szTransactionType = "SALE";
100
+
101
+ // check if payment can be voided
102
+ if(!$m_nPaymentVoided &&
103
+ !$m_nPaymentRefunded &&
104
+ // payment must be successful
105
+ $m_szOrderStatus == "csv_paid")
106
+ {
107
+ if(strtotime($szToday) == strtotime($szTransactionDateTime) &&
108
+ // for the time being only allow to execute a root VOID
109
+ $m_szOrderStatus == "pys_paid")
110
+ {
111
+ $m_boCanVoid = true;
112
+ }
113
+ }
114
+
115
+ // check if it can be collected - only preauth can be collected
116
+ $m_nPaymentCollected = 0;
117
+ }
118
+ else
119
+ {
120
+ Mage::log('Order info error: transaction type: '.$szTransactionType.' is not supported by the Cardsave/cardsaveonlinepayments extension');
121
+ }
122
+ }
123
+ ?>
124
+
125
+ <div>
126
+ CrossReference:
127
+ <?php
128
+ if(!$m_boExtensionVersionWithCrossReferenceFeature)
129
+ {
130
+ echo "<span style=\"font-weight:bold;color:Red;\">Missing data*</span>";
131
+ }
132
+ else
133
+ {
134
+ echo "<span style=\"font-weight:bold;\">".$szCrossReference."</span>";
135
+ }
136
+ ?>
137
+ </div>
138
+ <div>
139
+ Transaction Type:
140
+ <?php
141
+ if(!$m_boExtensionVersionWithCrossReferenceFeature)
142
+ {
143
+ echo "<span style=\"font-weight:bold;color:Red;\">Missing data*</span>";
144
+ }
145
+ else
146
+ {
147
+ echo "<span style=\"font-weight:bold;\">".$m_szTransactionType."</span>";
148
+ }
149
+ ?>
150
+ </div>
151
+ <div>
152
+ Amount: <?php echo "<span style=\"font-weight:bold\">".$m_szAmount."</span>"; ?>
153
+ </div>
154
+
155
+ <?php if(!$m_boExtensionVersionWithCrossReferenceFeature): ?>
156
+ <div>
157
+ <span style="font-weight:bold;color:Red;">* Incomplete orders and orders processed through an older payment extension will not have all the data necessary for CrossReference payments</span>
158
+ </div>
159
+ <?php else: ?>
160
+ <div>
161
+ <?php if($m_boCanVoid): ?>
162
+ <button type="button" id="voidButton" onclick="CSV_runCrossReferenceTransaction('<?php echo $this->getUrl('cardsaveonlinepayments/payment/void', array('_secure' => true)); ?>', '<?php echo $m_szOrderID; ?>', '<?php echo $szCrossReference; ?>', 'VOID');">
163
+ <span>VOID</span>
164
+ </button>
165
+ <?php endif; ?>
166
+ <?php if($m_boCanCollect): ?>
167
+ <button type="button" id="collectionButton" onclick="CSV_runCrossReferenceTransaction('<?php echo $this->getUrl('cardsaveonlinepayments/payment/collection', array('_secure' => true)); ?>', '<?php echo $m_szOrderID; ?>', '<?php echo $szCrossReference; ?>', 'COLLECTION');">
168
+ <span>COLLECT</span>
169
+ </button>
170
+ <?php endif; ?>
171
+ </div>
172
+ <?php endif; ?>
app/design/frontend/base/default/template/cardsaveonlinepayments/form.phtml CHANGED
@@ -11,6 +11,9 @@
11
  <li>
12
  <?php echo $this->__('You will be redirected to a secure page where you can complete your payment.') ?>
13
  </li>
 
 
 
14
  </ul>
15
  </fieldset>
16
  <?php } else {?>
@@ -28,7 +31,7 @@
28
  <li>
29
  <div class="input-box">
30
  <label for="<?php echo $_code; ?>_cc_number"><?php echo $this->__('Card Number') ?> <span class="required">*</span></label><br/>
31
- <input type="text" id="<?php echo $_code; ?>_cc_number" name="payment<?php echo $fieldCode; ?>[cc_number]" title="<?php echo $this->__('Card Number') ?>" class="input-text required-entry validate-digits validate-length maximum-length-20" value=""/>
32
  </div>
33
  </li>
34
  <li>
11
  <li>
12
  <?php echo $this->__('You will be redirected to a secure page where you can complete your payment.') ?>
13
  </li>
14
+ <li class='notice-msg'>
15
+ <?php echo $this->__('Please do not attempt to click the "BACK" button in your browser once you were redirected to the secure payment page to complete your payment. If you need to change your order you can do it before placing your order.') ?>
16
+ </li>
17
  </ul>
18
  </fieldset>
19
  <?php } else {?>
31
  <li>
32
  <div class="input-box">
33
  <label for="<?php echo $_code; ?>_cc_number"><?php echo $this->__('Card Number') ?> <span class="required">*</span></label><br/>
34
+ <input type="text" id="<?php echo $_code; ?>_cc_number" name="payment<?php echo $fieldCode; ?>[cc_number]" title="<?php echo $this->__('Card Number') ?>" class="input-text required-entry validate-digits validate-length maximum-length-20 validate-cc-number" value=""/>
35
  </div>
36
  </li>
37
  <li>
app/design/frontend/default/default/template/cardsaveonlinepayments/form.phtml CHANGED
@@ -11,6 +11,9 @@
11
  <li>
12
  <?php echo $this->__('You will be redirected to a secure page where you can complete your payment.') ?>
13
  </li>
 
 
 
14
  </ul>
15
  </fieldset>
16
  <?php } else {?>
@@ -28,7 +31,7 @@
28
  <li>
29
  <div class="input-box">
30
  <label for="<?php echo $_code; ?>_cc_number"><?php echo $this->__('Card Number') ?> <span class="required">*</span></label><br/>
31
- <input type="text" id="<?php echo $_code; ?>_cc_number" name="payment<?php echo $fieldCode; ?>[cc_number]" title="<?php echo $this->__('Card Number') ?>" class="input-text required-entry validate-digits validate-length maximum-length-20" value=""/>
32
  </div>
33
  </li>
34
  <li>
11
  <li>
12
  <?php echo $this->__('You will be redirected to a secure page where you can complete your payment.') ?>
13
  </li>
14
+ <li class='notice-msg'>
15
+ <?php echo $this->__('Please do not attempt to click the "BACK" button in your browser once you were redirected to the secure payment page to complete your payment. If you need to change your order you can do it before placing your order.') ?>
16
+ </li>
17
  </ul>
18
  </fieldset>
19
  <?php } else {?>
31
  <li>
32
  <div class="input-box">
33
  <label for="<?php echo $_code; ?>_cc_number"><?php echo $this->__('Card Number') ?> <span class="required">*</span></label><br/>
34
+ <input type="text" id="<?php echo $_code; ?>_cc_number" name="payment<?php echo $fieldCode; ?>[cc_number]" title="<?php echo $this->__('Card Number') ?>" class="input-text required-entry validate-digits validate-length maximum-length-20 validate-cc-number" value=""/>
35
  </div>
36
  </li>
37
  <li>
package.xml CHANGED
@@ -1,18 +1,20 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Cardsave_Cardsaveonlinepayments</name>
4
- <version>1.11.1</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.3, 1.4, 1.5 and 1.6</summary>
10
- <description>Fully supports 3D secure transactions. Also supports all of the integration methods provided by CardSave.</description>
11
- <notes>Html entity escaping fix placed in the integration library</notes>
 
 
12
  <authors><author><name>Cardsave</name><user>auto-converted</user><email>integrationsupport@cardsaveonlinepayments.com</email></author></authors>
13
- <date>2012-01-24</date>
14
- <time>15:47:33</time>
15
- <contents><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 name="base"><dir name="default"><dir name="images"><file name="cardsave_online.jpg" hash="abb239c81edb9ae8df8cf891e914e2aa"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="cardsaveonlinepayments"><file name="form.phtml" hash="bf8cf94001d912f6d1e77b1d2b03cf6e"/><file name="info.phtml" hash="9765a5eae50cb6fa21dcec22e7767e79"/></dir></dir></dir></dir><dir name="base"><dir name="default"><dir name="template"><dir name="cardsaveonlinepayments"><file name="form.phtml" hash="ad3f2b6304ce7e83e82195aa16fdb43a"/><file name="info.phtml" hash="9765a5eae50cb6fa21dcec22e7767e79"/></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="7f67d94e80b469997a5c1ca2f61a4e47"/><file name="info.phtml" hash="c378bb59f085df95a4a6a5d866fc512d"/></dir></dir></dir></dir><dir name="base"><dir name="default"><dir name="template"><dir name="cardsaveonlinepayments"><file name="form.phtml" hash="34e9854beb8479eef68f452efa803ec1"/><file name="info.phtml" hash="c378bb59f085df95a4a6a5d866fc512d"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Cardsave_All.xml" hash="e1d59fd8c4d4b5d87607f43fecf47e59"/></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="a296c18e805d796f1408ba73a28dcf2b"/></dir><dir name="etc"><file name="config.xml" hash="d42560b62660323b2139db8201c3205f"/><file name="system.xml" hash="946f07b53a3e5e321cdacb1bad97a469"/></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="e6d7c921f7bc404da6600e27289ca96b"/><file name="SOAP.php" hash="ed4585a1acc60a67fac72f6022084688"/><file name="TPG_Common.php" hash="0170a3c7f6a01faf9aee9b0f94da6d2a"/></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><dir name="Resource"><dir name="Eav"><dir name="Mysql4"><file name="Setup.php" hash="b2a7e887464ff91517dbb4fd62f13c66"/></dir></dir></dir><file name="Direct.php" hash="557a10ee62923ec7ddf7e1b58a43df33"/><file name="Request.php" hash="370f028086d13ae1df470e93a67dea66"/></dir><dir name="sql"><dir name="cardsaveonlinepayments_setup"><file name="mysql4-install-0.1.0.php" hash="f8d74ffd9920f7d3d6d63e5062204c61"/></dir></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="8122652860c5f9ac512b25e2088d1099"/></dir></dir></dir><dir name="Sales"><dir name="etc"><file name="config.xml" hash="9c884b19d80ee19e12bed268bb15e4ab"/></dir><dir name="Model"><dir name="Order"><file name="Invoice.php" hash="9be99f3fbe1c4fe98fb110d3daa8afe6"/><file name="Payment.php" hash="14f5fc7b55d07707e252f031f64cf18c"/></dir><dir name="Service"><file name="Quote.php" hash="a514922157b5690772d716c29f4a653e"/></dir><file name="Order.php" hash="9ffa9e06b0d5d8d2d810ab50017e81fa"/></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies/>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Cardsave_Cardsaveonlinepayments</name>
4
+ <version>1.12.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 v 1.3, 1.4, 1.5 and 1.6</summary>
10
+ <description>Fully supports 3D secure and CrossReference transactions. Also supports all of the integration methods provided by CardSave.</description>
11
+ <notes>Option to select transaction type: PREAUTH or SALE.&#xD;
12
+ CrossReference feature added with new transaction types: VOID, REFUND and COLLECTION.&#xD;
13
+ Fixed stock management bug on Hosted Payment Form payment when clicking on BACK button before payment is processed.</notes>
14
  <authors><author><name>Cardsave</name><user>auto-converted</user><email>integrationsupport@cardsaveonlinepayments.com</email></author></authors>
15
+ <date>2012-02-17</date>
16
+ <time>11:09:00</time>
17
+ <contents><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 name="base"><dir name="default"><dir name="images"><file name="cardsave_online.jpg" hash="abb239c81edb9ae8df8cf891e914e2aa"/></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><file name="cardsaveonlinepayments.js" hash="e7b2422644d39f0eb98e63d54a55ae4d"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="cardsaveonlinepayments"><file name="form.phtml" hash="bf8cf94001d912f6d1e77b1d2b03cf6e"/><file name="info.phtml" hash="9765a5eae50cb6fa21dcec22e7767e79"/></dir><dir name="payment"><dir name="info"><file name="cc_cardsaveonlinepayments.phtml" hash="88065460669f1112779264bdbf710af4"/></dir></dir></dir><dir name="layout"><file name="cardsaveonlinepayments.xml" hash="65e413716658a000d659271cd174b1e2"/></dir></dir></dir><dir name="base"><dir name="default"><dir name="template"><dir name="cardsaveonlinepayments"><file name="form.phtml" hash="ad3f2b6304ce7e83e82195aa16fdb43a"/><file name="info.phtml" hash="9765a5eae50cb6fa21dcec22e7767e79"/></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="8a0c644988ade86287a61ab812c8be1f"/><file name="info.phtml" hash="c378bb59f085df95a4a6a5d866fc512d"/></dir></dir></dir></dir><dir name="base"><dir name="default"><dir name="template"><dir name="cardsaveonlinepayments"><file name="form.phtml" hash="f6bf28657333e31a856074d02c1ef1f8"/><file name="info.phtml" hash="c378bb59f085df95a4a6a5d866fc512d"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Cardsave_All.xml" hash="e1d59fd8c4d4b5d87607f43fecf47e59"/></dir></target><target name="magelocal"><dir name="Cardsave"><dir name="Cardsaveonlinepayments"><dir name="Block"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><file name="Payment.php" hash="1cff6196bd79d3989b960506cc87201e"/></dir></dir></dir><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="e5e744834c4d5c82a803ce7455157237"/></dir><dir name="etc"><file name="config.xml" hash="64182ccad38661fcbf72e3d0506abfc4"/><file name="system.xml" hash="946f07b53a3e5e321cdacb1bad97a469"/></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="e206301745383a47a283cc69e4c5a8a9"/><file name="SOAP.php" hash="ed4585a1acc60a67fac72f6022084688"/><file name="TPG_Common.php" hash="0170a3c7f6a01faf9aee9b0f94da6d2a"/></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="3aab84053c69af1de2e743ee590fdf0c"/><file name="PaymentMode.php" hash="ea8af602bd09d54a123af64bc4b680d0"/><file name="ResultDeliveryMethod.php" hash="afb838319df715e604173d6aa143feab"/></dir><dir name="Resource"><dir name="Eav"><dir name="Mysql4"><file name="Setup.php" hash="b2a7e887464ff91517dbb4fd62f13c66"/></dir></dir></dir><file name="Direct.php" hash="b30f8f15c34ebf4900d3119e1a89a1bd"/><file name="Request.php" hash="370f028086d13ae1df470e93a67dea66"/></dir><dir name="sql"><dir name="cardsaveonlinepayments_setup"><file name="mysql4-install-0.1.0.php" hash="bda643d24b75e0dc527dc2caa6d47689"/></dir></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="8122652860c5f9ac512b25e2088d1099"/></dir></dir></dir><dir name="Sales"><dir name="etc"><file name="config.xml" hash="41f8d7978cb7e4cfffa0272d80e8f7bd"/></dir><dir name="Model"><dir name="Order"><file name="Invoice.php" hash="9be99f3fbe1c4fe98fb110d3daa8afe6"/><file name="Payment.php" hash="d413361faad1910189a63b53ed84df62"/></dir><dir name="Service"><file name="Quote.php" hash="a514922157b5690772d716c29f4a653e"/></dir><file name="Order.php" hash="9ffa9e06b0d5d8d2d810ab50017e81fa"/></dir></dir></dir></target></contents>
18
  <compatible/>
19
  <dependencies/>
20
  </package>
skin/adminhtml/default/default/cardsaveonlinepayments.js ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function CSV_runCrossReferenceTransaction(szActionURL, szOrderID, szCrossReference, szTransactionType)
2
+ {
3
+ var szConfirmMessage;
4
+ var szText;
5
+
6
+ if (szActionURL == "")
7
+ {
8
+ alert("Error: Invalid action URL");
9
+ }
10
+
11
+ if (szTransactionType == "VOID")
12
+ {
13
+ szConfirmMessage = "Are you sure you would like to void this payment?";
14
+ szText = "<ul class='messages'><li class='success-msg'><ul><li>Payment successfully voided</li></ul></li></ul>";
15
+ }
16
+ else if (szTransactionType == "COLLECTION")
17
+ {
18
+ szConfirmMessage = "Are you sure you would like to collect this authorized payment?";
19
+ szText = "<ul class='messages'><li class='success-msg'><ul><li>Authorized payment successfully collected</li></ul></li></ul>";
20
+ }
21
+ else
22
+ {
23
+ alert("Error: Unknown transaction type to run for this action: " + szTransactionType);
24
+ return;
25
+ }
26
+
27
+ if (confirm(szConfirmMessage))
28
+ {
29
+ new Ajax.Request(szActionURL,
30
+ { method: "post",
31
+ parameters: { OrderID: szOrderID, CrossReference: szCrossReference },
32
+ onSuccess: function (result) { var szMessage = result.responseText; if (szMessage == "0") { location.href = location.href; /* cheating with displaying a success message before the page is refreshed */ $('messages').update(szText); } else { alert(szMessage); } }
33
+ });
34
+ }
35
+ }