Version Notes
Fix to run on Magento v1.4.1.0 and above.
Fix to manage stock properly.
Fix to update the Order status properly.
Download this release
Release Info
Developer | Magento Core Team |
Extension | Cardsave_Cardsaveonlinepayments |
Version | 1.8.3 |
Comparing to | |
See all releases |
Code changes from version 1.8.2 to 1.8.3
- app/code/local/Cardsave/Cardsaveonlinepayments/Block/Threedsecure.php +10 -1
- app/code/local/Cardsave/Cardsaveonlinepayments/Model/{Tpg → Common}/GlobalErrors.php +1 -1
- app/code/local/Cardsave/Cardsaveonlinepayments/Model/{Tpg → Common}/ISOCountries.php +0 -0
- app/code/local/Cardsave/Cardsaveonlinepayments/Model/{Tpg → Common}/ISOCurrencies.php +0 -0
- app/code/local/Cardsave/Cardsaveonlinepayments/Model/{Tpg → Common}/PaymentFormHelper.php +21 -0
- app/code/local/Cardsave/Cardsaveonlinepayments/Model/{Tpg → Common}/ThePaymentGateway/PaymentSystem.php +0 -0
- app/code/local/Cardsave/Cardsaveonlinepayments/Model/{Tpg → Common}/ThePaymentGateway/SOAP.php +0 -0
- app/code/local/Cardsave/Cardsaveonlinepayments/Model/{Tpg → Common}/ThePaymentGateway/TPG_Common.php +0 -0
- app/code/local/Cardsave/Cardsaveonlinepayments/Model/Direct.php +20 -10
- app/code/local/Cardsave/Cardsaveonlinepayments/Model/Source/ResultDeliveryMethod.php +3 -3
- app/code/local/Cardsave/Cardsaveonlinepayments/controllers/PaymentController.php +205 -42
- app/code/local/Cardsave/Cardsaveonlinepayments/etc/config.xml +1 -0
- app/code/local/Cardsave/Cardsaveonlinepayments/etc/system.xml +12 -0
- app/code/local/Cardsave/Checkout/Model/Type/Onepage.php +690 -490
- app/code/local/Cardsave/Checkout/etc/config.xml +1 -1
- app/code/local/Cardsave/Sales/Model/Order/Payment.php +117 -0
- app/code/local/Cardsave/Sales/Model/Service/Quote.php +87 -0
- app/code/local/Cardsave/Sales/etc/config.xml +23 -0
- app/design/adminhtml/default/default/template/cardsaveonlinepayments/info.phtml +1 -1
- app/design/frontend/default/default/template/cardsaveonlinepayments/info.phtml +1 -1
- package.xml +9 -7
app/code/local/Cardsave/Cardsaveonlinepayments/Block/Threedsecure.php
CHANGED
@@ -8,7 +8,16 @@ class Cardsave_Cardsaveonlinepayments_Block_Threedsecure extends Mage_Core_Block
|
|
8 |
*/
|
9 |
protected function _toHtml()
|
10 |
{
|
11 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
$form = new Varien_Data_Form();
|
14 |
$form->setAction(Mage::getSingleton('checkout/session')->getAcsurl())
|
8 |
*/
|
9 |
protected function _toHtml()
|
10 |
{
|
11 |
+
$mode = Mage::getModel('cardsaveonlinepayments/direct')->getConfigData('mode');
|
12 |
+
|
13 |
+
if($mode == Cardsave_Cardsaveonlinepayments_Model_Source_PaymentMode::PAYMENT_MODE_TRANSPARENT_REDIRECT)
|
14 |
+
{
|
15 |
+
$szTermURL = 'cardsaveonlinepayments/payment/callbacktransparentredirect';
|
16 |
+
}
|
17 |
+
else
|
18 |
+
{
|
19 |
+
$szTermURL = 'cardsaveonlinepayments/payment/callback3d';
|
20 |
+
}
|
21 |
|
22 |
$form = new Varien_Data_Form();
|
23 |
$form->setAction(Mage::getSingleton('checkout/session')->getAcsurl())
|
app/code/local/Cardsave/Cardsaveonlinepayments/Model/{Tpg → Common}/GlobalErrors.php
RENAMED
@@ -1,6 +1,6 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
class
|
4 |
{
|
5 |
/*
|
6 |
* failure - probably a wrong card details entered in
|
1 |
<?php
|
2 |
|
3 |
+
class Cardsave_Cardsaveonlinepayments_Model_Common_GlobalErrors
|
4 |
{
|
5 |
/*
|
6 |
* failure - probably a wrong card details entered in
|
app/code/local/Cardsave/Cardsaveonlinepayments/Model/{Tpg → Common}/ISOCountries.php
RENAMED
File without changes
|
app/code/local/Cardsave/Cardsaveonlinepayments/Model/{Tpg → Common}/ISOCurrencies.php
RENAMED
File without changes
|
app/code/local/Cardsave/Cardsaveonlinepayments/Model/{Tpg → Common}/PaymentFormHelper.php
RENAMED
@@ -506,5 +506,26 @@
|
|
506 |
|
507 |
return $boMatch;
|
508 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
509 |
}
|
510 |
?>
|
506 |
|
507 |
return $boMatch;
|
508 |
}
|
509 |
+
|
510 |
+
/**
|
511 |
+
* Transform the string Magento version number into an integer ready for comparison
|
512 |
+
*
|
513 |
+
* @param unknown_type $magentoVersion
|
514 |
+
* @return unknown
|
515 |
+
*/
|
516 |
+
public static function getVersion($magentoVersion)
|
517 |
+
{
|
518 |
+
//$nVersion = Mage::getVersion();
|
519 |
+
$pattern = '/[^\d]/';
|
520 |
+
$magentoVersion = preg_replace($pattern, '', $magentoVersion);
|
521 |
+
|
522 |
+
while(strlen($magentoVersion) < 4)
|
523 |
+
{
|
524 |
+
$magentoVersion .= '0';
|
525 |
+
}
|
526 |
+
$magentoVersion = (int)$magentoVersion;
|
527 |
+
|
528 |
+
return $magentoVersion;
|
529 |
+
}
|
530 |
}
|
531 |
?>
|
app/code/local/Cardsave/Cardsaveonlinepayments/Model/{Tpg → Common}/ThePaymentGateway/PaymentSystem.php
RENAMED
File without changes
|
app/code/local/Cardsave/Cardsaveonlinepayments/Model/{Tpg → Common}/ThePaymentGateway/SOAP.php
RENAMED
File without changes
|
app/code/local/Cardsave/Cardsaveonlinepayments/Model/{Tpg → Common}/ThePaymentGateway/TPG_Common.php
RENAMED
File without changes
|
app/code/local/Cardsave/Cardsaveonlinepayments/Model/Direct.php
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
include ("
|
4 |
-
include_once ("
|
5 |
-
include ("
|
6 |
-
include ("
|
7 |
|
8 |
class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Method_Abstract
|
9 |
{
|
@@ -301,7 +301,7 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
|
|
301 |
if ($boTransactionProcessed == false)
|
302 |
{
|
303 |
// could not communicate with the payment gateway
|
304 |
-
$error =
|
305 |
|
306 |
$szLogMessage = "Couldn't complete transaction. Details: ".print_r($cdtrCardDetailsTransactionResult, 1)." ".print_r($todTransactionOutputData, 1); //"Couldn't communicate with payment gateway.";
|
307 |
Mage::log($szLogMessage);
|
@@ -329,7 +329,10 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
|
|
329 |
|
330 |
Mage::getSingleton('checkout/session')->setMd($szCrossReference)
|
331 |
->setAcsurl($szACSURL)
|
332 |
-
->setPareq($szPaReq)
|
|
|
|
|
|
|
333 |
break;
|
334 |
case 5:
|
335 |
// status code of 5 - means transaction declined
|
@@ -408,6 +411,7 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
|
|
408 |
$boCountryMandatory = 'false';
|
409 |
$rdmResultdeliveryMethod = $this->getConfigData('resultdeliverymethod');
|
410 |
$szServerResultURL = '';
|
|
|
411 |
$boPaymentFormDisplaysResult = '';
|
412 |
|
413 |
switch($rdmResultdeliveryMethod)
|
@@ -546,7 +550,10 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
|
|
546 |
->setPaymentformdisplaysresult($boPaymentFormDisplaysResult)
|
547 |
->setServerresulturlcookievariables($szServerResultURLCookieVariables)
|
548 |
->setServerresulturlformvariables($szServerResultURLFormVariables)
|
549 |
-
->setServerresulturlquerystringvariables($szServerResultURLQueryStringVariables)
|
|
|
|
|
|
|
550 |
}
|
551 |
|
552 |
/**
|
@@ -643,7 +650,10 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
|
|
643 |
->setStartdatemonth($szStartDateMonth)
|
644 |
->setStartdateyear($szStartDateYear)
|
645 |
->setIssuenumber($szIssueNumber)
|
646 |
-
->setCv2($szCV2)
|
|
|
|
|
|
|
647 |
}
|
648 |
|
649 |
/**
|
@@ -681,8 +691,8 @@ class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Me
|
|
681 |
if ($boTransactionProcessed == false)
|
682 |
{
|
683 |
// could not communicate with the payment gateway
|
684 |
-
$szLogMessage =
|
685 |
-
$message =
|
686 |
Mage::log($szLogMessage);
|
687 |
}
|
688 |
else
|
1 |
<?php
|
2 |
|
3 |
+
include ("Common/ThePaymentGateway/PaymentSystem.php");
|
4 |
+
include_once ("Common/PaymentFormHelper.php");
|
5 |
+
include ("Common/ISOCurrencies.php");
|
6 |
+
include ("Common/ISOCountries.php");
|
7 |
|
8 |
class Cardsave_Cardsaveonlinepayments_Model_Direct extends Mage_Payment_Model_Method_Abstract
|
9 |
{
|
301 |
if ($boTransactionProcessed == false)
|
302 |
{
|
303 |
// could not communicate with the payment gateway
|
304 |
+
$error = Cardsave_Cardsaveonlinepayments_Model_Common_GlobalErrors::ERROR_261;
|
305 |
|
306 |
$szLogMessage = "Couldn't complete transaction. Details: ".print_r($cdtrCardDetailsTransactionResult, 1)." ".print_r($todTransactionOutputData, 1); //"Couldn't communicate with payment gateway.";
|
307 |
Mage::log($szLogMessage);
|
329 |
|
330 |
Mage::getSingleton('checkout/session')->setMd($szCrossReference)
|
331 |
->setAcsurl($szACSURL)
|
332 |
+
->setPareq($szPaReq)
|
333 |
+
->setRedirectionmethod('_run3DSecureTransaction');
|
334 |
+
|
335 |
+
$order->setIsThreeDSecurePending(true);
|
336 |
break;
|
337 |
case 5:
|
338 |
// status code of 5 - means transaction declined
|
411 |
$boCountryMandatory = 'false';
|
412 |
$rdmResultdeliveryMethod = $this->getConfigData('resultdeliverymethod');
|
413 |
$szServerResultURL = '';
|
414 |
+
// set to always true to display the result on the Hosted Payment Form
|
415 |
$boPaymentFormDisplaysResult = '';
|
416 |
|
417 |
switch($rdmResultdeliveryMethod)
|
550 |
->setPaymentformdisplaysresult($boPaymentFormDisplaysResult)
|
551 |
->setServerresulturlcookievariables($szServerResultURLCookieVariables)
|
552 |
->setServerresulturlformvariables($szServerResultURLFormVariables)
|
553 |
+
->setServerresulturlquerystringvariables($szServerResultURLQueryStringVariables)
|
554 |
+
->setRedirectionmethod('_runRedirectedPaymentComplete');
|
555 |
+
|
556 |
+
$payment->getOrder()->setIsHostedPaymentPending(true);
|
557 |
}
|
558 |
|
559 |
/**
|
650 |
->setStartdatemonth($szStartDateMonth)
|
651 |
->setStartdateyear($szStartDateYear)
|
652 |
->setIssuenumber($szIssueNumber)
|
653 |
+
->setCv2($szCV2)
|
654 |
+
->setRedirectionmethod('_runRedirectedPaymentComplete');
|
655 |
+
|
656 |
+
$payment->getOrder()->setIsHostedPaymentPending(true);
|
657 |
}
|
658 |
|
659 |
/**
|
691 |
if ($boTransactionProcessed == false)
|
692 |
{
|
693 |
// could not communicate with the payment gateway
|
694 |
+
$szLogMessage = Cardsave_Cardsaveonlinepayments_Model_Common_GlobalErrors::ERROR_431;
|
695 |
+
$message = Cardsave_Cardsaveonlinepayments_Model_Common_GlobalErrors::ERROR_431;
|
696 |
Mage::log($szLogMessage);
|
697 |
}
|
698 |
else
|
app/code/local/Cardsave/Cardsaveonlinepayments/Model/Source/ResultDeliveryMethod.php
CHANGED
@@ -11,14 +11,14 @@ class Cardsave_Cardsaveonlinepayments_Model_Source_ResultDeliveryMethod
|
|
11 |
{
|
12 |
return array
|
13 |
(
|
14 |
-
|
15 |
'value' => self::RESULT_DELIVERY_METHOD_SERVER_PULL,
|
16 |
'label' => Mage::helper('cardsaveonlinepayments')->__('Server Pull')
|
17 |
),
|
18 |
-
array(
|
19 |
'value' => self::RESULT_DELIVERY_METHOD_SERVER,
|
20 |
'label' => Mage::helper('cardsaveonlinepayments')->__('Server')
|
21 |
-
)
|
22 |
array(
|
23 |
'value' => self::RESULT_DELIVERY_METHOD_POST,
|
24 |
'label' => Mage::helper('cardsaveonlinepayments')->__('Post')
|
11 |
{
|
12 |
return array
|
13 |
(
|
14 |
+
array(
|
15 |
'value' => self::RESULT_DELIVERY_METHOD_SERVER_PULL,
|
16 |
'label' => Mage::helper('cardsaveonlinepayments')->__('Server Pull')
|
17 |
),
|
18 |
+
/*array(
|
19 |
'value' => self::RESULT_DELIVERY_METHOD_SERVER,
|
20 |
'label' => Mage::helper('cardsaveonlinepayments')->__('Server')
|
21 |
+
),*/
|
22 |
array(
|
23 |
'value' => self::RESULT_DELIVERY_METHOD_POST,
|
24 |
'label' => Mage::helper('cardsaveonlinepayments')->__('Post')
|
app/code/local/Cardsave/Cardsaveonlinepayments/controllers/PaymentController.php
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
require_once "app/code/local/Cardsave/Cardsaveonlinepayments/Model/
|
4 |
|
5 |
/**
|
6 |
* Standard Checkout Controller
|
@@ -42,6 +42,12 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
|
|
42 |
*/
|
43 |
public function redirectAction()
|
44 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
$this->getResponse()->setBody($this->getLayout()->createBlock('cardsaveonlinepayments/redirect')->toHtml());
|
46 |
}
|
47 |
|
@@ -51,6 +57,15 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
|
|
51 |
*/
|
52 |
public function threedsecureAction()
|
53 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
$this->getResponse()->setBody($this->getLayout()->createBlock('cardsaveonlinepayments/threedsecure')->toHtml());
|
55 |
}
|
56 |
|
@@ -87,19 +102,33 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
|
|
87 |
}
|
88 |
else
|
89 |
{
|
90 |
-
$szMessage =
|
91 |
}
|
92 |
}
|
93 |
|
94 |
$szPaymentProcessorResponse = $session->getPaymentprocessorresponse();
|
95 |
-
|
|
|
|
|
|
|
96 |
{
|
97 |
if($szPaymentProcessorResponse != null &&
|
98 |
$szPaymentProcessorResponse != '')
|
99 |
{
|
100 |
$szMessage .= '<br/>'.$szPaymentProcessorResponse;
|
101 |
}
|
102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
Mage::getSingleton('core/session')->addError($szMessage);
|
104 |
$this->_redirect('checkout/onepage/failure');
|
105 |
}
|
@@ -109,14 +138,14 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
|
|
109 |
Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save();
|
110 |
|
111 |
// send confirmation email to customer
|
112 |
-
$order = Mage::getModel('sales/order');
|
113 |
-
|
114 |
-
$order->load(Mage::getSingleton('checkout/session')->getLastOrderId());
|
115 |
if($order->getId())
|
116 |
{
|
117 |
$order->sendNewOrderEmail();
|
118 |
}
|
119 |
|
|
|
|
|
|
|
120 |
if($szPaymentProcessorResponse != '')
|
121 |
{
|
122 |
Mage::getSingleton('core/session')->addSuccess($szPaymentProcessorResponse);
|
@@ -138,7 +167,9 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
|
|
138 |
$checkout = Mage::getSingleton('checkout/type_onepage');
|
139 |
$session = Mage::getSingleton('checkout/session');
|
140 |
$szPaymentProcessorResponse = '';
|
141 |
-
|
|
|
|
|
142 |
try
|
143 |
{
|
144 |
$hmHashMethod = $model->getConfigData('hashmethod');
|
@@ -176,7 +207,6 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
|
|
176 |
}
|
177 |
else
|
178 |
{
|
179 |
-
// need to finish off the transaction
|
180 |
$checkout->saveOrderAfterRedirectedPaymentAction(true,
|
181 |
$this->getRequest()->getPost('StatusCode'),
|
182 |
$this->getRequest()->getPost('Message'),
|
@@ -188,7 +218,7 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
|
|
188 |
catch (Exception $exc)
|
189 |
{
|
190 |
$boError = true;
|
191 |
-
$szNotificationMessage =
|
192 |
Mage::logException($exc);
|
193 |
}
|
194 |
|
@@ -200,24 +230,34 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
|
|
200 |
{
|
201 |
$szNotificationMessage = $szNotificationMessage.'<br/>'.$szPaymentProcessorResponse;
|
202 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
Mage::getSingleton('core/session')->addError($szNotificationMessage);
|
204 |
$this->_redirect('checkout/onepage/failure');
|
205 |
}
|
206 |
else
|
207 |
{
|
208 |
-
$order = Mage::getModel('sales/order');
|
209 |
-
|
210 |
// set the quote as inactive after back from paypal
|
211 |
Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save();
|
212 |
|
213 |
// send confirmation email to customer
|
214 |
-
$order->load(Mage::getSingleton('checkout/session')->getLastOrderId());
|
215 |
-
|
216 |
if($order->getId())
|
217 |
{
|
218 |
$order->sendNewOrderEmail();
|
219 |
}
|
220 |
|
|
|
|
|
|
|
221 |
if($szPaymentProcessorResponse != '')
|
222 |
{
|
223 |
Mage::getSingleton('core/session')->addSuccess($szPaymentProcessorResponse);
|
@@ -239,7 +279,7 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
|
|
239 |
|
240 |
try
|
241 |
{
|
242 |
-
//
|
243 |
$checkout->saveOrderAfterRedirectedPaymentAction(true,
|
244 |
$this->getRequest()->getPost('StatusCode'),
|
245 |
$this->getRequest()->getPost('Message'),
|
@@ -251,7 +291,7 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
|
|
251 |
{
|
252 |
$boError = true;
|
253 |
$szErrorMessage = $exc->getMessage();
|
254 |
-
$szNotificationMessage =
|
255 |
Mage::logException($exc);
|
256 |
}
|
257 |
|
@@ -262,13 +302,11 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
|
|
262 |
else
|
263 |
{
|
264 |
$order = Mage::getModel('sales/order');
|
265 |
-
|
266 |
// set the quote as inactive after back from paypal
|
267 |
Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save();
|
268 |
|
269 |
// send confirmation email to customer
|
270 |
-
$order->load(Mage::getSingleton('checkout/session')->getLastOrderId());
|
271 |
-
|
272 |
if($order->getId())
|
273 |
{
|
274 |
$order->sendNewOrderEmail();
|
@@ -279,6 +317,8 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
|
|
279 |
if($this->getRequest()->getPost('StatusCode') == '0')
|
280 |
{
|
281 |
Mage::getSingleton('checkout/session')->clear();
|
|
|
|
|
282 |
}
|
283 |
|
284 |
$this->getResponse()->setBody('StatusCode=0');
|
@@ -309,11 +349,13 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
|
|
309 |
$szPreSharedKey = $model->getConfigData('presharedkey');
|
310 |
$szURLVariableString = $this->getRequest()->getRequestUri();
|
311 |
$nStartIndex = strpos($szURLVariableString, "?");
|
|
|
|
|
312 |
|
313 |
if(!is_int($nStartIndex))
|
314 |
{
|
315 |
-
$szErrorMessage =
|
316 |
-
Mage::log(
|
317 |
}
|
318 |
else
|
319 |
{
|
@@ -323,7 +365,7 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
|
|
323 |
if(!CSV_PaymentFormHelper::compareServerHashDigest($arFormVariables, $szPassword, $hmHashMethod, $szPreSharedKey))
|
324 |
{
|
325 |
// report an error message
|
326 |
-
$szErrorMessage =
|
327 |
}
|
328 |
else
|
329 |
{
|
@@ -350,7 +392,7 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
|
|
350 |
{
|
351 |
Mage::log("Error happened while trying to retrieve the transaction result details for a SERVER_PULL method for CrossReference: ".$szCrossReference.". Error code: ".$nErrorNumber.", message: ".$szErrorMessage);
|
352 |
// suppress the message and use customer friendly instead
|
353 |
-
$szErrorMessage =
|
354 |
}
|
355 |
else
|
356 |
{
|
@@ -366,7 +408,7 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
|
|
366 |
|
367 |
if($szStatusCode !== '0')
|
368 |
{
|
369 |
-
$szErrorMessage =
|
370 |
$szErrorMessage .= " Message: ".$szMessage;
|
371 |
}
|
372 |
else
|
@@ -400,24 +442,33 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
|
|
400 |
|
401 |
if($szErrorMessage)
|
402 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
403 |
Mage::getSingleton('core/session')->addError($szErrorMessage);
|
404 |
$this->_redirect('checkout/onepage/failure');
|
405 |
}
|
406 |
else
|
407 |
-
{
|
408 |
-
$order = Mage::getModel('sales/order');
|
409 |
-
|
410 |
// set the quote as inactive after back from paypal
|
411 |
Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save();
|
412 |
|
413 |
// send confirmation email to customer
|
414 |
-
$order->load(Mage::getSingleton('checkout/session')->getLastOrderId());
|
415 |
-
|
416 |
if($order->getId())
|
417 |
{
|
418 |
$order->sendNewOrderEmail();
|
419 |
}
|
420 |
-
|
|
|
|
|
|
|
421 |
Mage::getSingleton('core/session')->addSuccess('Payment Processor Response: '.$szMessage);
|
422 |
$this->_redirect('checkout/onepage/success', array('_secure' => true));
|
423 |
}
|
@@ -430,6 +481,8 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
|
|
430 |
public function callbacktransparentredirectAction()
|
431 |
{
|
432 |
$model = Mage::getModel('cardsaveonlinepayments/direct');
|
|
|
|
|
433 |
|
434 |
try
|
435 |
{
|
@@ -460,9 +513,19 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
|
|
460 |
}
|
461 |
catch (Exception $exc)
|
462 |
{
|
463 |
-
$error =
|
464 |
Mage::logException($exc);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
465 |
|
|
|
466 |
Mage::getSingleton('core/session')->addError($error);
|
467 |
$this->_redirect('checkout/onepage/failure');
|
468 |
}
|
@@ -491,8 +554,10 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
|
|
491 |
|
492 |
if($error)
|
493 |
{
|
494 |
-
|
495 |
-
|
|
|
|
|
496 |
}
|
497 |
else
|
498 |
{
|
@@ -520,7 +585,6 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
|
|
520 |
$szCallbackURL = Mage::getUrl('cardsaveonlinepayments/payment/callbacktransparentredirect');
|
521 |
$szHashDigest = CSV_PaymentFormHelper::calculatePostThreeDSecureAuthenticationHashDigest($szMerchantID, $szPassword, $hmHashMethod, $szPreSharedKey, $szPaRES, $szCrossReference, $szTransactionDateTime, $szCallbackURL);
|
522 |
|
523 |
-
|
524 |
Mage::getSingleton('checkout/session')->setHashdigest($szHashDigest)
|
525 |
->setMerchantid($szMerchantID)
|
526 |
->setCrossreference($szCrossReference)
|
@@ -541,6 +605,8 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
|
|
541 |
$checkout = Mage::getSingleton('checkout/type_onepage');
|
542 |
$session = Mage::getSingleton('checkout/session');
|
543 |
$szPaymentProcessorResponse = '';
|
|
|
|
|
544 |
|
545 |
try
|
546 |
{
|
@@ -574,7 +640,6 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
|
|
574 |
}
|
575 |
else
|
576 |
{
|
577 |
-
// need to finish off the transaction
|
578 |
$checkout->saveOrderAfterRedirectedPaymentAction(false,
|
579 |
$this->getRequest()->getPost('StatusCode'),
|
580 |
$this->getRequest()->getPost('Message'),
|
@@ -586,7 +651,7 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
|
|
586 |
catch(Exception $exc)
|
587 |
{
|
588 |
$boError = true;
|
589 |
-
$szNotificationMessage =
|
590 |
Mage::logException($exc);
|
591 |
}
|
592 |
|
@@ -598,24 +663,33 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
|
|
598 |
{
|
599 |
$szNotificationMessage = $szNotificationMessage.'<br/>'.$szPaymentProcessorResponse;
|
600 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
601 |
Mage::getSingleton('core/session')->addError($szNotificationMessage);
|
602 |
$this->_redirect('checkout/onepage/failure');
|
603 |
}
|
604 |
else
|
605 |
{
|
606 |
-
|
607 |
-
|
608 |
-
// set the quote as inactive after back from paypal
|
609 |
Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save();
|
610 |
-
|
611 |
// send confirmation email to customer
|
612 |
-
$order->load(Mage::getSingleton('checkout/session')->getLastOrderId());
|
613 |
-
|
614 |
if($order->getId())
|
615 |
{
|
616 |
$order->sendNewOrderEmail();
|
617 |
}
|
618 |
|
|
|
|
|
|
|
619 |
if($szPaymentProcessorResponse != '')
|
620 |
{
|
621 |
Mage::getSingleton('core/session')->addSuccess($szPaymentProcessorResponse);
|
@@ -623,4 +697,93 @@ class Cardsave_Cardsaveonlinepayments_PaymentController extends Mage_Core_Contro
|
|
623 |
$this->_redirect('checkout/onepage/success', array('_secure' => true));
|
624 |
}
|
625 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
626 |
}
|
1 |
<?php
|
2 |
|
3 |
+
require_once "app/code/local/Cardsave/Cardsaveonlinepayments/Model/Common/PaymentFormHelper.php";
|
4 |
|
5 |
/**
|
6 |
* Standard Checkout Controller
|
42 |
*/
|
43 |
public function redirectAction()
|
44 |
{
|
45 |
+
// need to re-add the ordered item quantity to stock as per not completed 3DS transaction
|
46 |
+
if(!Mage::getSingleton('checkout/session')->getPares())
|
47 |
+
{
|
48 |
+
$order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
|
49 |
+
$this->_addOrderedItemsToStock($order);
|
50 |
+
}
|
51 |
$this->getResponse()->setBody($this->getLayout()->createBlock('cardsaveonlinepayments/redirect')->toHtml());
|
52 |
}
|
53 |
|
57 |
*/
|
58 |
public function threedsecureAction()
|
59 |
{
|
60 |
+
$mode = Mage::getModel('cardsaveonlinepayments/direct')->getConfigData('mode');
|
61 |
+
|
62 |
+
// need to re-add the ordered item quantity to stock as per not completed 3DS transaction
|
63 |
+
if($mode != Cardsave_Cardsaveonlinepayments_Model_Source_PaymentMode::PAYMENT_MODE_TRANSPARENT_REDIRECT)
|
64 |
+
{
|
65 |
+
$order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
|
66 |
+
$this->_addOrderedItemsToStock($order);
|
67 |
+
}
|
68 |
+
|
69 |
$this->getResponse()->setBody($this->getLayout()->createBlock('cardsaveonlinepayments/threedsecure')->toHtml());
|
70 |
}
|
71 |
|
102 |
}
|
103 |
else
|
104 |
{
|
105 |
+
$szMessage = Cardsave_Cardsaveonlinepayments_Model_Common_GlobalErrors::ERROR_7655;
|
106 |
}
|
107 |
}
|
108 |
|
109 |
$szPaymentProcessorResponse = $session->getPaymentprocessorresponse();
|
110 |
+
$order = Mage::getModel('sales/order');
|
111 |
+
$order->load(Mage::getSingleton('checkout/session')->getLastOrderId());
|
112 |
+
|
113 |
+
if ($boError)
|
114 |
{
|
115 |
if($szPaymentProcessorResponse != null &&
|
116 |
$szPaymentProcessorResponse != '')
|
117 |
{
|
118 |
$szMessage .= '<br/>'.$szPaymentProcessorResponse;
|
119 |
}
|
120 |
+
|
121 |
+
if($order)
|
122 |
+
{
|
123 |
+
$orderState = 'pending_payment';
|
124 |
+
$orderStatus = 'cardsave_failed_threed_secure';
|
125 |
+
$order->setCustomerNote(Mage::helper('cardsaveonlinepayments')->__('3D Secure Authentication Failed'));
|
126 |
+
$order->setState($orderState, $orderStatus, $szPaymentProcessorResponse, false);
|
127 |
+
$order->save();
|
128 |
+
}
|
129 |
+
$this->_clearSessionVariables();
|
130 |
+
|
131 |
+
// report out an fatal error
|
132 |
Mage::getSingleton('core/session')->addError($szMessage);
|
133 |
$this->_redirect('checkout/onepage/failure');
|
134 |
}
|
138 |
Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save();
|
139 |
|
140 |
// send confirmation email to customer
|
|
|
|
|
|
|
141 |
if($order->getId())
|
142 |
{
|
143 |
$order->sendNewOrderEmail();
|
144 |
}
|
145 |
|
146 |
+
// need to decrease the stock only after a succecssful payment
|
147 |
+
$this->_subtractOrderedItemsFromStock($order);
|
148 |
+
|
149 |
if($szPaymentProcessorResponse != '')
|
150 |
{
|
151 |
Mage::getSingleton('core/session')->addSuccess($szPaymentProcessorResponse);
|
167 |
$checkout = Mage::getSingleton('checkout/type_onepage');
|
168 |
$session = Mage::getSingleton('checkout/session');
|
169 |
$szPaymentProcessorResponse = '';
|
170 |
+
$order = Mage::getModel('sales/order');
|
171 |
+
$order->load(Mage::getSingleton('checkout/session')->getLastOrderId());
|
172 |
+
|
173 |
try
|
174 |
{
|
175 |
$hmHashMethod = $model->getConfigData('hashmethod');
|
207 |
}
|
208 |
else
|
209 |
{
|
|
|
210 |
$checkout->saveOrderAfterRedirectedPaymentAction(true,
|
211 |
$this->getRequest()->getPost('StatusCode'),
|
212 |
$this->getRequest()->getPost('Message'),
|
218 |
catch (Exception $exc)
|
219 |
{
|
220 |
$boError = true;
|
221 |
+
$szNotificationMessage = Cardsave_Cardsaveonlinepayments_Model_Common_GlobalErrors::ERROR_183;
|
222 |
Mage::logException($exc);
|
223 |
}
|
224 |
|
230 |
{
|
231 |
$szNotificationMessage = $szNotificationMessage.'<br/>'.$szPaymentProcessorResponse;
|
232 |
}
|
233 |
+
|
234 |
+
if($order)
|
235 |
+
{
|
236 |
+
$orderState = 'pending_payment';
|
237 |
+
$orderStatus = 'cardsave_failed_hosted_payment';
|
238 |
+
$order->setCustomerNote(Mage::helper('cardsaveonlinepayments')->__('Hosted Payment Failed'));
|
239 |
+
$order->setState($orderState, $orderStatus, $szPaymentProcessorResponse, false);
|
240 |
+
$order->save();
|
241 |
+
}
|
242 |
+
|
243 |
+
$this->_clearSessionVariables();
|
244 |
Mage::getSingleton('core/session')->addError($szNotificationMessage);
|
245 |
$this->_redirect('checkout/onepage/failure');
|
246 |
}
|
247 |
else
|
248 |
{
|
|
|
|
|
249 |
// set the quote as inactive after back from paypal
|
250 |
Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save();
|
251 |
|
252 |
// send confirmation email to customer
|
|
|
|
|
253 |
if($order->getId())
|
254 |
{
|
255 |
$order->sendNewOrderEmail();
|
256 |
}
|
257 |
|
258 |
+
// need to decrease the stock only after a succecssful payment
|
259 |
+
$this->_subtractOrderedItemsFromStock($order);
|
260 |
+
|
261 |
if($szPaymentProcessorResponse != '')
|
262 |
{
|
263 |
Mage::getSingleton('core/session')->addSuccess($szPaymentProcessorResponse);
|
279 |
|
280 |
try
|
281 |
{
|
282 |
+
// finish off the transaction: if StatusCode = 0 create an order otherwise do nothing
|
283 |
$checkout->saveOrderAfterRedirectedPaymentAction(true,
|
284 |
$this->getRequest()->getPost('StatusCode'),
|
285 |
$this->getRequest()->getPost('Message'),
|
291 |
{
|
292 |
$boError = true;
|
293 |
$szErrorMessage = $exc->getMessage();
|
294 |
+
$szNotificationMessage = Cardsave_Cardsaveonlinepayments_Model_Common_GlobalErrors::ERROR_183;
|
295 |
Mage::logException($exc);
|
296 |
}
|
297 |
|
302 |
else
|
303 |
{
|
304 |
$order = Mage::getModel('sales/order');
|
305 |
+
$order->load(Mage::getSingleton('checkout/session')->getLastOrderId());
|
306 |
// set the quote as inactive after back from paypal
|
307 |
Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save();
|
308 |
|
309 |
// send confirmation email to customer
|
|
|
|
|
310 |
if($order->getId())
|
311 |
{
|
312 |
$order->sendNewOrderEmail();
|
317 |
if($this->getRequest()->getPost('StatusCode') == '0')
|
318 |
{
|
319 |
Mage::getSingleton('checkout/session')->clear();
|
320 |
+
// need to decrease the stock only after a succecssful payment
|
321 |
+
$this->_subtractOrderedItemsFromStock($order);
|
322 |
}
|
323 |
|
324 |
$this->getResponse()->setBody('StatusCode=0');
|
349 |
$szPreSharedKey = $model->getConfigData('presharedkey');
|
350 |
$szURLVariableString = $this->getRequest()->getRequestUri();
|
351 |
$nStartIndex = strpos($szURLVariableString, "?");
|
352 |
+
$order = Mage::getModel('sales/order');
|
353 |
+
$order->load(Mage::getSingleton('checkout/session')->getLastOrderId());
|
354 |
|
355 |
if(!is_int($nStartIndex))
|
356 |
{
|
357 |
+
$szErrorMessage = Cardsave_Cardsaveonlinepayments_Model_Common_GlobalErrors::ERROR_309;
|
358 |
+
Mage::log(Cardsave_Cardsaveonlinepayments_Model_Common_GlobalErrors::ERROR_309." Request URI: ".$szURLVariableString);
|
359 |
}
|
360 |
else
|
361 |
{
|
365 |
if(!CSV_PaymentFormHelper::compareServerHashDigest($arFormVariables, $szPassword, $hmHashMethod, $szPreSharedKey))
|
366 |
{
|
367 |
// report an error message
|
368 |
+
$szErrorMessage = Cardsave_Cardsaveonlinepayments_Model_Common_GlobalErrors::ERROR_304;
|
369 |
}
|
370 |
else
|
371 |
{
|
392 |
{
|
393 |
Mage::log("Error happened while trying to retrieve the transaction result details for a SERVER_PULL method for CrossReference: ".$szCrossReference.". Error code: ".$nErrorNumber.", message: ".$szErrorMessage);
|
394 |
// suppress the message and use customer friendly instead
|
395 |
+
$szErrorMessage = Cardsave_Cardsaveonlinepayments_Model_Common_GlobalErrors::ERROR_329." Message: ".$szErrorMessage;
|
396 |
}
|
397 |
else
|
398 |
{
|
408 |
|
409 |
if($szStatusCode !== '0')
|
410 |
{
|
411 |
+
$szErrorMessage = Cardsave_Cardsaveonlinepayments_Model_Common_GlobalErrors::ERROR_381;
|
412 |
$szErrorMessage .= " Message: ".$szMessage;
|
413 |
}
|
414 |
else
|
442 |
|
443 |
if($szErrorMessage)
|
444 |
{
|
445 |
+
if($order)
|
446 |
+
{
|
447 |
+
$orderState = 'pending_payment';
|
448 |
+
$orderStatus = 'cardsave_failed_hosted_payment';
|
449 |
+
$order->setCustomerNote(Mage::helper('cardsaveonlinepayments')->__('Hosted Payment Failed'));
|
450 |
+
$order->setState($orderState, $orderStatus, $szErrorMessage, false);
|
451 |
+
$order->save();
|
452 |
+
}
|
453 |
+
|
454 |
+
$this->_clearSessionVariables();
|
455 |
Mage::getSingleton('core/session')->addError($szErrorMessage);
|
456 |
$this->_redirect('checkout/onepage/failure');
|
457 |
}
|
458 |
else
|
459 |
+
{
|
|
|
|
|
460 |
// set the quote as inactive after back from paypal
|
461 |
Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save();
|
462 |
|
463 |
// send confirmation email to customer
|
|
|
|
|
464 |
if($order->getId())
|
465 |
{
|
466 |
$order->sendNewOrderEmail();
|
467 |
}
|
468 |
+
|
469 |
+
// need to decrease the stock only after a succecssful payment
|
470 |
+
$this->_subtractOrderedItemsFromStock($order);
|
471 |
+
|
472 |
Mage::getSingleton('core/session')->addSuccess('Payment Processor Response: '.$szMessage);
|
473 |
$this->_redirect('checkout/onepage/success', array('_secure' => true));
|
474 |
}
|
481 |
public function callbacktransparentredirectAction()
|
482 |
{
|
483 |
$model = Mage::getModel('cardsaveonlinepayments/direct');
|
484 |
+
$order = Mage::getModel('sales/order');
|
485 |
+
$order->load(Mage::getSingleton('checkout/session')->getLastOrderId());
|
486 |
|
487 |
try
|
488 |
{
|
513 |
}
|
514 |
catch (Exception $exc)
|
515 |
{
|
516 |
+
$error = Cardsave_Cardsaveonlinepayments_Model_Common_GlobalErrors::ERROR_260;
|
517 |
Mage::logException($exc);
|
518 |
+
|
519 |
+
if($order)
|
520 |
+
{
|
521 |
+
$orderState = 'pending_payment';
|
522 |
+
$orderStatus = 'cardsave_failed_hosted_payment';
|
523 |
+
$order->setCustomerNote(Mage::helper('cardsaveonlinepayments')->__('Transparent Redirect Payment Failed'));
|
524 |
+
$order->setState($orderState, $orderStatus, $exc->getMessage(), false);
|
525 |
+
$order->save();
|
526 |
+
}
|
527 |
|
528 |
+
$this->_clearSessionVariables();
|
529 |
Mage::getSingleton('core/session')->addError($error);
|
530 |
$this->_redirect('checkout/onepage/failure');
|
531 |
}
|
554 |
|
555 |
if($error)
|
556 |
{
|
557 |
+
$this->_clearSessionVariables();
|
558 |
+
//Mage::getSingleton('core/session')->addError($error);
|
559 |
+
//$this->_redirect('checkout/onepage/failure');
|
560 |
+
Mage::throwException($error);
|
561 |
}
|
562 |
else
|
563 |
{
|
585 |
$szCallbackURL = Mage::getUrl('cardsaveonlinepayments/payment/callbacktransparentredirect');
|
586 |
$szHashDigest = CSV_PaymentFormHelper::calculatePostThreeDSecureAuthenticationHashDigest($szMerchantID, $szPassword, $hmHashMethod, $szPreSharedKey, $szPaRES, $szCrossReference, $szTransactionDateTime, $szCallbackURL);
|
587 |
|
|
|
588 |
Mage::getSingleton('checkout/session')->setHashdigest($szHashDigest)
|
589 |
->setMerchantid($szMerchantID)
|
590 |
->setCrossreference($szCrossReference)
|
605 |
$checkout = Mage::getSingleton('checkout/type_onepage');
|
606 |
$session = Mage::getSingleton('checkout/session');
|
607 |
$szPaymentProcessorResponse = '';
|
608 |
+
$order = Mage::getModel('sales/order');
|
609 |
+
$order->load(Mage::getSingleton('checkout/session')->getLastOrderId());
|
610 |
|
611 |
try
|
612 |
{
|
640 |
}
|
641 |
else
|
642 |
{
|
|
|
643 |
$checkout->saveOrderAfterRedirectedPaymentAction(false,
|
644 |
$this->getRequest()->getPost('StatusCode'),
|
645 |
$this->getRequest()->getPost('Message'),
|
651 |
catch(Exception $exc)
|
652 |
{
|
653 |
$boError = true;
|
654 |
+
$szNotificationMessage = Cardsave_Cardsaveonlinepayments_Model_Common_GlobalErrors::ERROR_183;
|
655 |
Mage::logException($exc);
|
656 |
}
|
657 |
|
663 |
{
|
664 |
$szNotificationMessage = $szNotificationMessage.'<br/>'.$szPaymentProcessorResponse;
|
665 |
}
|
666 |
+
|
667 |
+
if($order)
|
668 |
+
{
|
669 |
+
$orderState = 'pending_payment';
|
670 |
+
$orderStatus = 'cardsave_failed_hosted_payment';
|
671 |
+
$order->setCustomerNote(Mage::helper('cardsaveonlinepayments')->__('Transparent Redirect Payment Failed'));
|
672 |
+
$order->setState($orderState, $orderStatus, $szPaymentProcessorResponse, false);
|
673 |
+
$order->save();
|
674 |
+
}
|
675 |
+
|
676 |
+
$this->_clearSessionVariables();
|
677 |
Mage::getSingleton('core/session')->addError($szNotificationMessage);
|
678 |
$this->_redirect('checkout/onepage/failure');
|
679 |
}
|
680 |
else
|
681 |
{
|
682 |
+
// set the quote as inactive after back from paypal
|
|
|
|
|
683 |
Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save();
|
|
|
684 |
// send confirmation email to customer
|
|
|
|
|
685 |
if($order->getId())
|
686 |
{
|
687 |
$order->sendNewOrderEmail();
|
688 |
}
|
689 |
|
690 |
+
// need to decrease the stock only after a succecssful payment
|
691 |
+
$this->_subtractOrderedItemsFromStock($order);
|
692 |
+
|
693 |
if($szPaymentProcessorResponse != '')
|
694 |
{
|
695 |
Mage::getSingleton('core/session')->addSuccess($szPaymentProcessorResponse);
|
697 |
$this->_redirect('checkout/onepage/success', array('_secure' => true));
|
698 |
}
|
699 |
}
|
700 |
+
|
701 |
+
/**
|
702 |
+
* Deduct the order items from the stock
|
703 |
+
*
|
704 |
+
* @param unknown_type $order
|
705 |
+
*/
|
706 |
+
private function _subtractOrderedItemsFromStock($order)
|
707 |
+
{
|
708 |
+
$nVersion = CSV_PaymentFormHelper::getVersion(Mage::getVersion());
|
709 |
+
$isCustomStockManagementEnabled = Mage::getModel('cardsaveonlinepayments/direct')->getConfigData('customstockmanagementenabled');
|
710 |
+
|
711 |
+
if($nVersion >= 1410 &&
|
712 |
+
$isCustomStockManagementEnabled)
|
713 |
+
{
|
714 |
+
$items = $order->getAllItems();
|
715 |
+
foreach ($items as $itemId => $item)
|
716 |
+
{
|
717 |
+
// ordered quantity of the item from stock
|
718 |
+
$quantity = $item->getQtyOrdered();
|
719 |
+
$productId = $item->getProductId();
|
720 |
+
|
721 |
+
$stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($productId);
|
722 |
+
$stockManagement = $stock->getManageStock();
|
723 |
+
|
724 |
+
if($stockManagement)
|
725 |
+
{
|
726 |
+
$stock->setQty($stock->getQty() - $quantity);
|
727 |
+
$stock->save();
|
728 |
+
}
|
729 |
+
}
|
730 |
+
}
|
731 |
+
}
|
732 |
+
|
733 |
+
/**
|
734 |
+
* Re-add the order items to the stock to balance the incorrect stock management before a payment is completed
|
735 |
+
*
|
736 |
+
* @param unknown_type $order
|
737 |
+
*/
|
738 |
+
private function _addOrderedItemsToStock($order)
|
739 |
+
{
|
740 |
+
$nVersion = CSV_PaymentFormHelper::getVersion(Mage::getVersion());
|
741 |
+
$isCustomStockManagementEnabled = Mage::getModel('cardsaveonlinepayments/direct')->getConfigData('customstockmanagementenabled');
|
742 |
+
|
743 |
+
if($nVersion >= 1410 &&
|
744 |
+
$isCustomStockManagementEnabled)
|
745 |
+
{
|
746 |
+
$items = $order->getAllItems();
|
747 |
+
foreach ($items as $itemId => $item)
|
748 |
+
{
|
749 |
+
// ordered quantity of the item from stock
|
750 |
+
$quantity = $item->getQtyOrdered();
|
751 |
+
$productId = $item->getProductId();
|
752 |
+
|
753 |
+
$stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($productId);
|
754 |
+
$stockManagement = $stock->getManageStock();
|
755 |
+
|
756 |
+
if($stockManagement)
|
757 |
+
{
|
758 |
+
$stock->setQty($stock->getQty() + $quantity);
|
759 |
+
$stock->save();
|
760 |
+
}
|
761 |
+
}
|
762 |
+
}
|
763 |
+
}
|
764 |
+
|
765 |
+
|
766 |
+
private function _clearSessionVariables()
|
767 |
+
{
|
768 |
+
// clear all the custom session variables used in the payment module in case of a failed payment
|
769 |
+
Mage::getSingleton('checkout/session')->setHashdigest(null)
|
770 |
+
->setMerchantid(null)
|
771 |
+
->setCrossreference(null)
|
772 |
+
->setTransactiondatetime(null)
|
773 |
+
->setCallbackurl(null)
|
774 |
+
->setPareq(null)
|
775 |
+
->setPares(null)
|
776 |
+
->setMd(null)
|
777 |
+
->setAcsurl(null)
|
778 |
+
->setTermurl(null)
|
779 |
+
->setThreedsecurerequired(null)
|
780 |
+
->setIshostedpayment(null)
|
781 |
+
->setStatuscode(null)
|
782 |
+
->setMessage(null)
|
783 |
+
->setPreviousstatuscode(null)
|
784 |
+
->setPreviousmessage(null)
|
785 |
+
->setOrderid(null)
|
786 |
+
->setRedirectedpayment(null)
|
787 |
+
->setCardsaveonlinepaymentsOrderId(null);
|
788 |
+
}
|
789 |
}
|
app/code/local/Cardsave/Cardsaveonlinepayments/etc/config.xml
CHANGED
@@ -97,6 +97,7 @@
|
|
97 |
<countrymandatory>1</countrymandatory>
|
98 |
<resultdeliverymethod>POST</resultdeliverymethod>
|
99 |
<allowspecific>0</allowspecific>
|
|
|
100 |
</cardsaveonlinepayments>
|
101 |
</payment>
|
102 |
</default>
|
97 |
<countrymandatory>1</countrymandatory>
|
98 |
<resultdeliverymethod>POST</resultdeliverymethod>
|
99 |
<allowspecific>0</allowspecific>
|
100 |
+
<customstockmanagementenabled>1</customstockmanagementenabled>
|
101 |
</cardsaveonlinepayments>
|
102 |
</payment>
|
103 |
</default>
|
app/code/local/Cardsave/Cardsaveonlinepayments/etc/system.xml
CHANGED
@@ -226,6 +226,18 @@
|
|
226 |
<![CDATA[<strong>Please note</strong>: The above value is only applicable to Hosted Payment Form payment mode]]>
|
227 |
</comment>
|
228 |
</resultdeliverymethod>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
</fields>
|
230 |
</cardsaveonlinepayments>
|
231 |
</groups>
|
226 |
<![CDATA[<strong>Please note</strong>: The above value is only applicable to Hosted Payment Form payment mode]]>
|
227 |
</comment>
|
228 |
</resultdeliverymethod>
|
229 |
+
<customstockmanagementenabled>
|
230 |
+
<label>Custom Stock Management Enabled</label>
|
231 |
+
<sort_order>210</sort_order>
|
232 |
+
<frontend_type>select</frontend_type>
|
233 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
234 |
+
<show_in_default>1</show_in_default>
|
235 |
+
<show_in_website>1</show_in_website>
|
236 |
+
<show_in_store>0</show_in_store>
|
237 |
+
<comment>
|
238 |
+
<![CDATA[<strong>Please note</strong>: The above setting is only applicable to Magento version 1.4.1.0 and above]]>
|
239 |
+
</comment>
|
240 |
+
</customstockmanagementenabled>
|
241 |
</fields>
|
242 |
</cardsaveonlinepayments>
|
243 |
</groups>
|
app/code/local/Cardsave/Checkout/Model/Type/Onepage.php
CHANGED
@@ -2,6 +2,20 @@
|
|
2 |
|
3 |
class Cardsave_Checkout_Model_Type_Onepage extends Mage_Checkout_Model_Type_Onepage
|
4 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
/**
|
6 |
* Create an order
|
7 |
*
|
@@ -9,254 +23,356 @@ class Cardsave_Checkout_Model_Type_Onepage extends Mage_Checkout_Model_Type_Onep
|
|
9 |
*/
|
10 |
public function saveOrder()
|
11 |
{
|
12 |
-
$this->
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
{
|
25 |
-
|
26 |
}
|
27 |
-
$
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
38 |
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
{
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
}
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
{
|
49 |
-
$
|
50 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
-
|
55 |
-
|
|
|
|
|
56 |
|
57 |
-
|
58 |
-
Mage::log(time());
|
59 |
-
break;
|
60 |
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
66 |
{
|
67 |
-
|
68 |
-
$customer->addAddress($customerBilling);
|
69 |
}
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
}
|
77 |
-
$customer->
|
78 |
$customer->save();
|
79 |
|
80 |
-
$
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
|
|
83 |
{
|
84 |
-
$
|
85 |
-
$changed = true;
|
86 |
}
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
{
|
92 |
-
$customer->setDefaultShipping($customerBilling->getId());
|
93 |
-
$changed = true;
|
94 |
}
|
95 |
-
|
96 |
-
isset($customerShipping) &&
|
97 |
-
!$customer->getDefaultShipping())
|
98 |
{
|
99 |
-
$customer->
|
100 |
-
$changed = true;
|
101 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
{
|
105 |
-
|
|
|
|
|
106 |
}
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
if (!$this->getQuote()->isVirtual())
|
124 |
-
{
|
125 |
-
$order->setShippingAddress($convertQuote->addressToOrderAddress($shipping));
|
126 |
-
}
|
127 |
-
|
128 |
-
$order->setPayment($convertQuote->paymentToOrderPayment($this->getQuote()->getPayment()));
|
129 |
-
|
130 |
-
foreach ($this->getQuote()->getAllItems() as $item)
|
131 |
-
{
|
132 |
-
$orderItem = $convertQuote->itemToOrderItem($item);
|
133 |
-
if ($item->getParentItem())
|
134 |
-
{
|
135 |
-
$orderItem->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId()));
|
136 |
-
}
|
137 |
-
$order->addItem($orderItem);
|
138 |
-
}
|
139 |
-
|
140 |
-
// We can use configuration data for declare new order status
|
141 |
-
Mage::dispatchEvent('checkout_type_onepage_save_order', array('order'=>$order, 'quote'=>$this->getQuote()));
|
142 |
-
// check again, if customer exists
|
143 |
-
if ($this->getQuote()->getCheckoutMethod() == Mage_Sales_Model_Quote::CHECKOUT_METHOD_REGISTER)
|
144 |
-
{
|
145 |
-
if ($this->_customerEmailExists($customer->getEmail(), Mage::app()->getWebsite()->getId()))
|
146 |
-
{
|
147 |
-
Mage::throwException(Mage::helper('checkout')->__('There is already a customer registered using this email address'));
|
148 |
-
}
|
149 |
-
}
|
150 |
-
|
151 |
-
// clear 3dSecure session variables
|
152 |
-
Mage::getSingleton('checkout/session')->setThreedsecurerequired(null);
|
153 |
-
Mage::getSingleton('checkout/session')->setMd(null);
|
154 |
-
Mage::getSingleton('checkout/session')->setPares(null);
|
155 |
-
Mage::getSingleton('checkout/session')->setAcsurl(null);
|
156 |
-
|
157 |
-
$order->place();
|
158 |
-
|
159 |
-
if ($this->getQuote()->getCheckoutMethod()==Mage_Sales_Model_Quote::CHECKOUT_METHOD_REGISTER)
|
160 |
-
{
|
161 |
-
$customer->save();
|
162 |
-
$customerBillingId = $customerBilling->getId();
|
163 |
-
if (!$this->getQuote()->isVirtual())
|
164 |
-
{
|
165 |
-
$customerShippingId = isset($customerShipping) ? $customerShipping->getId() : $customerBillingId;
|
166 |
-
$customer->setDefaultShipping($customerShippingId);
|
167 |
-
}
|
168 |
-
$customer->setDefaultBilling($customerBillingId);
|
169 |
-
$customer->save();
|
170 |
-
|
171 |
-
$this->getQuote()->setCustomerId($customer->getId());
|
172 |
-
|
173 |
-
$order->setCustomerId($customer->getId());
|
174 |
-
Mage::helper('core')->copyFieldset('customer_account', 'to_order', $customer, $order);
|
175 |
-
|
176 |
-
$billing->setCustomerId($customer->getId())->setCustomerAddressId($customerBillingId);
|
177 |
-
if (!$this->getQuote()->isVirtual())
|
178 |
-
{
|
179 |
-
$shipping->setCustomerId($customer->getId())->setCustomerAddressId($customerShippingId);
|
180 |
-
}
|
181 |
-
|
182 |
-
if ($customer->isConfirmationRequired())
|
183 |
-
{
|
184 |
-
$customer->sendNewAccountEmail('confirmation');
|
185 |
-
}
|
186 |
-
else
|
187 |
-
{
|
188 |
-
$customer->sendNewAccountEmail();
|
189 |
-
}
|
190 |
-
}
|
191 |
-
|
192 |
-
/**
|
193 |
-
* a flag to set that there will be redirect to third party after confirmation
|
194 |
-
* eg: paypal standard ipn
|
195 |
-
*/
|
196 |
-
$redirectUrl = $this->getQuote()->getPayment()->getOrderPlaceRedirectUrl();
|
197 |
-
if(!$redirectUrl)
|
198 |
-
{
|
199 |
-
$order->setEmailSent(true);
|
200 |
-
}
|
201 |
-
|
202 |
-
if(!$redirectUrl ||
|
203 |
-
$this->getQuote()->getPayment()->getMethodInstance()->getCode() != 'cardsaveonlinepayments')
|
204 |
-
{
|
205 |
-
$order->save();
|
206 |
-
}
|
207 |
-
|
208 |
-
Mage::dispatchEvent('checkout_type_onepage_save_order_after', array('order'=>$order, 'quote'=>$this->getQuote()));
|
209 |
-
|
210 |
-
|
211 |
-
/**
|
212 |
-
* need to have somelogic to set order as new status to make sure order is not finished yet
|
213 |
-
* quote will be still active when we send the customer to paypal
|
214 |
-
*/
|
215 |
-
|
216 |
-
$orderId = $order->getIncrementId();
|
217 |
-
$this->getCheckout()->setLastQuoteId($this->getQuote()->getId());
|
218 |
-
$this->getCheckout()->setLastOrderId($order->getId());
|
219 |
-
$this->getCheckout()->setLastRealOrderId($order->getIncrementId());
|
220 |
-
$this->getCheckout()->setRedirectUrl($redirectUrl);
|
221 |
-
|
222 |
-
/**
|
223 |
-
* we only want to send to customer about new order when there is no redirect to third party
|
224 |
-
*/
|
225 |
-
if(!$redirectUrl)
|
226 |
-
{
|
227 |
-
$order->sendNewOrderEmail();
|
228 |
-
}
|
229 |
-
|
230 |
-
if ($this->getQuote()->getCheckoutMethod(true) == Mage_Sales_Model_Quote::CHECKOUT_METHOD_REGISTER &&
|
231 |
-
!Mage::getSingleton('customer/session')->isLoggedIn())
|
232 |
-
{
|
233 |
-
/**
|
234 |
-
* we need to save quote here to have it saved with Customer Id.
|
235 |
-
* so when loginById() executes checkout/session method loadCustomerQuote
|
236 |
-
* it would not create new quotes and merge it with old one.
|
237 |
-
*/
|
238 |
-
$this->getQuote()->save();
|
239 |
-
if ($customer->isConfirmationRequired())
|
240 |
-
{
|
241 |
-
Mage::getSingleton('checkout/session')->addSuccess(Mage::helper('customer')->__('Account confirmation is required. Please, check your e-mail for confirmation link. To resend confirmation email please <a href="%s">click here</a>.',
|
242 |
-
Mage::helper('customer')->getEmailConfirmationUrl($customer->getEmail())
|
243 |
-
));
|
244 |
-
}
|
245 |
-
else
|
246 |
-
{
|
247 |
-
Mage::getSingleton('customer/session')->loginById($customer->getId());
|
248 |
-
}
|
249 |
-
}
|
250 |
-
|
251 |
-
//Setting this one more time like control flag that we haves saved order
|
252 |
-
//Must be checkout on success page to show it or not.
|
253 |
-
$this->getCheckout()->setLastSuccessQuoteId($this->getQuote()->getId());
|
254 |
-
|
255 |
-
/*
|
256 |
-
* Fix for v1.4.1.0 and above
|
257 |
-
*/
|
258 |
-
//$this->getQuote()->setIsActive(false);
|
259 |
-
//$this->getQuote()->save();
|
260 |
|
261 |
return $this;
|
262 |
}
|
@@ -270,141 +386,180 @@ class Cardsave_Checkout_Model_Type_Onepage extends Mage_Checkout_Model_Type_Onep
|
|
270 |
*/
|
271 |
public function saveOrderAfter3dSecure($pares, $md)
|
272 |
{
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
$customerShipping = $shipping->exportCustomerAddress();
|
302 |
-
$customer->addAddress($customerShipping);
|
303 |
-
}
|
304 |
-
$customer->setSavedFromQuote(true);
|
305 |
-
$customer->save();
|
306 |
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
}
|
322 |
-
elseif (!$this->getQuote()->isVirtual() &&
|
323 |
-
isset($customerShipping) &&
|
324 |
-
!$customer->getDefaultShipping())
|
325 |
-
{
|
326 |
-
$customer->setDefaultShipping($customerShipping->getId());
|
327 |
-
$changed = true;
|
328 |
-
}
|
329 |
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
408 |
return $this;
|
409 |
}
|
410 |
|
@@ -421,143 +576,188 @@ class Cardsave_Checkout_Model_Type_Onepage extends Mage_Checkout_Model_Type_Onep
|
|
421 |
*/
|
422 |
public function saveOrderAfterRedirectedPaymentAction($boIsHostedPaymentAction, $szStatusCode, $szMessage, $szPreviousStatusCode, $szPreviousMessage, $szOrderID)
|
423 |
{
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
$customer->addAddress($customerShipping);
|
455 |
-
}
|
456 |
-
$customer->setSavedFromQuote(true);
|
457 |
-
$customer->save();
|
458 |
|
459 |
-
|
460 |
-
if (isset($customerBilling) &&
|
461 |
-
!$customer->getDefaultBilling())
|
462 |
-
{
|
463 |
-
$customer->setDefaultBilling($customerBilling->getId());
|
464 |
-
$changed = true;
|
465 |
-
}
|
466 |
-
if (!$this->getQuote()->isVirtual() &&
|
467 |
-
isset($customerBilling) &&
|
468 |
-
!$customer->getDefaultShipping() &&
|
469 |
-
$shipping->getSameAsBilling())
|
470 |
-
{
|
471 |
-
$customer->setDefaultShipping($customerBilling->getId());
|
472 |
-
$changed = true;
|
473 |
-
}
|
474 |
-
elseif (!$this->getQuote()->isVirtual() &&
|
475 |
-
isset($customerShipping) &&
|
476 |
-
!$customer->getDefaultShipping())
|
477 |
-
{
|
478 |
-
$customer->setDefaultShipping($customerShipping->getId());
|
479 |
-
$changed = true;
|
480 |
-
}
|
481 |
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
561 |
|
562 |
return $this;
|
563 |
}
|
2 |
|
3 |
class Cardsave_Checkout_Model_Type_Onepage extends Mage_Checkout_Model_Type_Onepage
|
4 |
{
|
5 |
+
public function getVersion($magentoVersion)
|
6 |
+
{
|
7 |
+
$pattern = '/[^\d]/';
|
8 |
+
$magentoVersion = preg_replace($pattern, '', $magentoVersion);
|
9 |
+
|
10 |
+
while(strlen($magentoVersion) < 4)
|
11 |
+
{
|
12 |
+
$magentoVersion .= '0';
|
13 |
+
}
|
14 |
+
$magentoVersion = (int)$magentoVersion;
|
15 |
+
|
16 |
+
return $magentoVersion;
|
17 |
+
}
|
18 |
+
|
19 |
/**
|
20 |
* Create an order
|
21 |
*
|
23 |
*/
|
24 |
public function saveOrder()
|
25 |
{
|
26 |
+
$nVersion = $this->getVersion(Mage::getVersion());
|
27 |
+
|
28 |
+
if($nVersion >= 1410)
|
29 |
+
{
|
30 |
+
// logic for version 1.4.1.0 and above
|
31 |
+
$this->validate();
|
32 |
+
$isNewCustomer = false;
|
33 |
+
|
34 |
+
switch ($this->getCheckoutMethod())
|
35 |
+
{
|
36 |
+
case self::METHOD_GUEST:
|
37 |
+
$this->_prepareGuestQuote();
|
38 |
+
break;
|
39 |
+
case self::METHOD_REGISTER:
|
40 |
+
$this->_prepareNewCustomerQuote();
|
41 |
+
$isNewCustomer = true;
|
42 |
+
break;
|
43 |
+
default:
|
44 |
+
$this->_prepareCustomerQuote();
|
45 |
+
break;
|
46 |
+
}
|
47 |
+
|
48 |
+
$service = Mage::getModel('sales/service_quote', $this->getQuote());
|
49 |
+
$redirectUrl = $this->getQuote()->getPayment()->getOrderPlaceRedirectUrl();
|
50 |
+
|
51 |
+
if(!$redirectUrl ||
|
52 |
+
$this->getQuote()->getPayment()->getMethodInstance()->getCode() != 'cardsaveonlinepayments')
|
53 |
+
{
|
54 |
+
$service->submitAll();
|
55 |
+
}
|
56 |
+
|
57 |
+
if ($isNewCustomer)
|
58 |
+
{
|
59 |
+
try
|
60 |
{
|
61 |
+
$this->_involveNewCustomer();
|
62 |
}
|
63 |
+
catch (Exception $e)
|
64 |
+
{
|
65 |
+
Mage::logException($e);
|
66 |
+
}
|
67 |
+
}
|
68 |
+
|
69 |
+
$this->_checkoutSession->setLastQuoteId($this->getQuote()->getId())
|
70 |
+
->setLastSuccessQuoteId($this->getQuote()->getId());
|
71 |
+
#->clearHelperData();
|
72 |
+
|
73 |
+
$order = $service->getOrder();
|
74 |
+
if ($order)
|
75 |
+
{
|
76 |
+
Mage::dispatchEvent('checkout_type_onepage_save_order_after', array('order'=>$order, 'quote'=>$this->getQuote()));
|
77 |
|
78 |
+
/**
|
79 |
+
* a flag to set that there will be redirect to third party after confirmation
|
80 |
+
* eg: paypal standard ipn
|
81 |
+
*/
|
82 |
+
$redirectUrl = $this->getQuote()->getPayment()->getOrderPlaceRedirectUrl();
|
83 |
+
/**
|
84 |
+
* we only want to send to customer about new order when there is no redirect to third party
|
85 |
+
*/
|
86 |
+
if(!$redirectUrl)
|
87 |
{
|
88 |
+
try
|
89 |
+
{
|
90 |
+
$order->sendNewOrderEmail();
|
91 |
+
}
|
92 |
+
catch (Exception $e)
|
93 |
+
{
|
94 |
+
Mage::logException($e);
|
95 |
+
}
|
96 |
}
|
97 |
+
|
98 |
+
// add order information to the session
|
99 |
+
$this->_checkoutSession->setLastOrderId($order->getId())
|
100 |
+
->setRedirectUrl($redirectUrl)
|
101 |
+
->setLastRealOrderId($order->getIncrementId());
|
102 |
|
103 |
+
// as well a billing agreement can be created
|
104 |
+
$agreement = $order->getPayment()->getBillingAgreement();
|
105 |
+
if ($agreement)
|
106 |
+
{
|
107 |
+
$this->_checkoutSession->setLastBillingAgreementId($agreement->getId());
|
108 |
+
}
|
109 |
+
}
|
110 |
+
|
111 |
+
// add recurring profiles information to the session
|
112 |
+
$profiles = $service->getRecurringPaymentProfiles();
|
113 |
+
if ($profiles)
|
114 |
+
{
|
115 |
+
$ids = array();
|
116 |
+
foreach($profiles as $profile)
|
117 |
{
|
118 |
+
$ids[] = $profile->getId();
|
119 |
}
|
120 |
+
$this->_checkoutSession->setLastRecurringProfileIds($ids);
|
121 |
+
// TODO: send recurring profile emails
|
122 |
+
}
|
123 |
+
}
|
124 |
+
else
|
125 |
+
{
|
126 |
+
// logic for version below 1.4.0.1 and below
|
127 |
+
$this->validateOrder();
|
128 |
+
$billing = $this->getQuote()->getBillingAddress();
|
129 |
+
|
130 |
+
if (!$this->getQuote()->isVirtual())
|
131 |
+
{
|
132 |
+
$shipping = $this->getQuote()->getShippingAddress();
|
133 |
+
}
|
134 |
+
|
135 |
+
switch ($this->getQuote()->getCheckoutMethod())
|
136 |
+
{
|
137 |
+
case Mage_Sales_Model_Quote::CHECKOUT_METHOD_GUEST:
|
138 |
+
if (!$this->getQuote()->isAllowedGuestCheckout())
|
139 |
+
{
|
140 |
+
Mage::throwException(Mage::helper('checkout')->__('Sorry, guest checkout is not enabled. Please try again or contact store owner.'));
|
141 |
+
}
|
142 |
+
$this->getQuote()->setCustomerId(null)
|
143 |
+
->setCustomerEmail($billing->getEmail())
|
144 |
+
->setCustomerIsGuest(true)
|
145 |
+
->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
|
146 |
+
break;
|
147 |
+
|
148 |
+
case Mage_Sales_Model_Quote::CHECKOUT_METHOD_REGISTER:
|
149 |
+
$customer = Mage::getModel('customer/customer');
|
150 |
+
|
151 |
+
$customerBilling = $billing->exportCustomerAddress();
|
152 |
+
$customer->addAddress($customerBilling);
|
153 |
+
|
154 |
+
if (!$this->getQuote()->isVirtual() &&
|
155 |
+
!$shipping->getSameAsBilling())
|
156 |
+
{
|
157 |
+
$customerShipping = $shipping->exportCustomerAddress();
|
158 |
+
$customer->addAddress($customerShipping);
|
159 |
+
}
|
160 |
+
|
161 |
+
if ($this->getQuote()->getCustomerDob() &&
|
162 |
+
!$billing->getCustomerDob())
|
163 |
+
{
|
164 |
+
$billing->setCustomerDob($this->getQuote()->getCustomerDob());
|
165 |
+
}
|
166 |
+
|
167 |
+
Mage::helper('core')->copyFieldset('checkout_onepage_billing', 'to_customer', $billing, $customer);
|
168 |
+
|
169 |
+
$customer->setPassword($customer->decryptPassword($this->getQuote()->getPasswordHash()));
|
170 |
+
$customer->setPasswordHash($customer->hashPassword($customer->getPassword()));
|
171 |
+
|
172 |
+
$this->getQuote()->setCustomer($customer);
|
173 |
+
Mage::log(time());
|
174 |
+
break;
|
175 |
+
|
176 |
+
default:
|
177 |
+
$customer = Mage::getSingleton('customer/session')->getCustomer();
|
178 |
+
|
179 |
+
if (!$billing->getCustomerId() ||
|
180 |
+
$billing->getSaveInAddressBook())
|
181 |
+
{
|
182 |
+
$customerBilling = $billing->exportCustomerAddress();
|
183 |
+
$customer->addAddress($customerBilling);
|
184 |
+
}
|
185 |
+
if (!$this->getQuote()->isVirtual() &&
|
186 |
+
((!$shipping->getCustomerId() && !$shipping->getSameAsBilling()) ||
|
187 |
+
(!$shipping->getSameAsBilling() && $shipping->getSaveInAddressBook())))
|
188 |
+
{
|
189 |
+
$customerShipping = $shipping->exportCustomerAddress();
|
190 |
+
$customer->addAddress($customerShipping);
|
191 |
+
}
|
192 |
+
$customer->setSavedFromQuote(true);
|
193 |
+
$customer->save();
|
194 |
+
|
195 |
+
$changed = false;
|
196 |
+
if (isset($customerBilling) &&
|
197 |
+
!$customer->getDefaultBilling())
|
198 |
+
{
|
199 |
+
$customer->setDefaultBilling($customerBilling->getId());
|
200 |
+
$changed = true;
|
201 |
+
}
|
202 |
+
if (!$this->getQuote()->isVirtual() &&
|
203 |
+
isset($customerBilling) &&
|
204 |
+
!$customer->getDefaultShipping() &&
|
205 |
+
$shipping->getSameAsBilling())
|
206 |
+
{
|
207 |
+
$customer->setDefaultShipping($customerBilling->getId());
|
208 |
+
$changed = true;
|
209 |
+
}
|
210 |
+
elseif (!$this->getQuote()->isVirtual() &&
|
211 |
+
isset($customerShipping) &&
|
212 |
+
!$customer->getDefaultShipping())
|
213 |
+
{
|
214 |
+
$customer->setDefaultShipping($customerShipping->getId());
|
215 |
+
$changed = true;
|
216 |
+
}
|
217 |
+
|
218 |
+
if ($changed)
|
219 |
+
{
|
220 |
+
$customer->save();
|
221 |
+
}
|
222 |
+
}
|
223 |
|
224 |
+
$this->getQuote()->reserveOrderId();
|
225 |
+
$convertQuote = Mage::getModel('sales/convert_quote');
|
226 |
+
// @var $convertQuote Mage_Sales_Model_Convert_Quote
|
227 |
+
if ($this->getQuote()->isVirtual())
|
228 |
+
{
|
229 |
+
$order = $convertQuote->addressToOrder($billing);
|
230 |
+
}
|
231 |
+
else
|
232 |
+
{
|
233 |
+
$order = $convertQuote->addressToOrder($shipping);
|
234 |
+
}
|
235 |
+
// @var $order Mage_Sales_Model_Order
|
236 |
+
$order->setBillingAddress($convertQuote->addressToOrderAddress($billing));
|
237 |
|
238 |
+
if (!$this->getQuote()->isVirtual())
|
239 |
+
{
|
240 |
+
$order->setShippingAddress($convertQuote->addressToOrderAddress($shipping));
|
241 |
+
}
|
242 |
|
243 |
+
$order->setPayment($convertQuote->paymentToOrderPayment($this->getQuote()->getPayment()));
|
|
|
|
|
244 |
|
245 |
+
foreach ($this->getQuote()->getAllItems() as $item)
|
246 |
+
{
|
247 |
+
$orderItem = $convertQuote->itemToOrderItem($item);
|
248 |
+
if ($item->getParentItem())
|
249 |
+
{
|
250 |
+
$orderItem->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId()));
|
251 |
+
}
|
252 |
+
$order->addItem($orderItem);
|
253 |
+
}
|
254 |
|
255 |
+
// We can use configuration data for declare new order status
|
256 |
+
Mage::dispatchEvent('checkout_type_onepage_save_order', array('order'=>$order, 'quote'=>$this->getQuote()));
|
257 |
+
// check again, if customer exists
|
258 |
+
if ($this->getQuote()->getCheckoutMethod() == Mage_Sales_Model_Quote::CHECKOUT_METHOD_REGISTER)
|
259 |
+
{
|
260 |
+
if ($this->_customerEmailExists($customer->getEmail(), Mage::app()->getWebsite()->getId()))
|
261 |
{
|
262 |
+
Mage::throwException(Mage::helper('checkout')->__('There is already a customer registered using this email address'));
|
|
|
263 |
}
|
264 |
+
}
|
265 |
+
|
266 |
+
// clear 3dSecure session variables
|
267 |
+
Mage::getSingleton('checkout/session')->setThreedsecurerequired(null)
|
268 |
+
->setMd(null)
|
269 |
+
->setPares(null)
|
270 |
+
->setAcsurl(null);
|
271 |
+
|
272 |
+
$order->place();
|
273 |
+
|
274 |
+
if ($this->getQuote()->getCheckoutMethod()==Mage_Sales_Model_Quote::CHECKOUT_METHOD_REGISTER)
|
275 |
+
{
|
276 |
+
$customer->save();
|
277 |
+
$customerBillingId = $customerBilling->getId();
|
278 |
+
if (!$this->getQuote()->isVirtual())
|
279 |
+
{
|
280 |
+
$customerShippingId = isset($customerShipping) ? $customerShipping->getId() : $customerBillingId;
|
281 |
+
$customer->setDefaultShipping($customerShippingId);
|
282 |
}
|
283 |
+
$customer->setDefaultBilling($customerBillingId);
|
284 |
$customer->save();
|
285 |
|
286 |
+
$this->getQuote()->setCustomerId($customer->getId());
|
287 |
+
|
288 |
+
$order->setCustomerId($customer->getId());
|
289 |
+
Mage::helper('core')->copyFieldset('customer_account', 'to_order', $customer, $order);
|
290 |
+
|
291 |
+
$billing->setCustomerId($customer->getId())->setCustomerAddressId($customerBillingId);
|
292 |
+
if (!$this->getQuote()->isVirtual())
|
293 |
{
|
294 |
+
$shipping->setCustomerId($customer->getId())->setCustomerAddressId($customerShippingId);
|
|
|
295 |
}
|
296 |
+
|
297 |
+
if ($customer->isConfirmationRequired())
|
298 |
+
{
|
299 |
+
$customer->sendNewAccountEmail('confirmation');
|
|
|
|
|
|
|
300 |
}
|
301 |
+
else
|
|
|
|
|
302 |
{
|
303 |
+
$customer->sendNewAccountEmail();
|
|
|
304 |
}
|
305 |
+
}
|
306 |
+
|
307 |
+
/**
|
308 |
+
* a flag to set that there will be redirect to third party after confirmation
|
309 |
+
* eg: paypal standard ipn
|
310 |
+
*/
|
311 |
+
$redirectUrl = $this->getQuote()->getPayment()->getOrderPlaceRedirectUrl();
|
312 |
+
if(!$redirectUrl)
|
313 |
+
{
|
314 |
+
$order->setEmailSent(true);
|
315 |
+
}
|
316 |
+
|
317 |
+
if(!$redirectUrl ||
|
318 |
+
$this->getQuote()->getPayment()->getMethodInstance()->getCode() != 'cardsaveonlinepayments')
|
319 |
+
{
|
320 |
+
$order->save();
|
321 |
+
}
|
322 |
+
|
323 |
+
Mage::dispatchEvent('checkout_type_onepage_save_order_after', array('order'=>$order, 'quote'=>$this->getQuote()));
|
324 |
+
|
325 |
|
326 |
+
/**
|
327 |
+
* need to have some logic to set order as new status to make sure order is not finished yet
|
328 |
+
* quote will be still active when we send the customer to paypal
|
329 |
+
*/
|
330 |
+
|
331 |
+
$orderId = $order->getIncrementId();
|
332 |
+
$this->getCheckout()->setLastQuoteId($this->getQuote()->getId());
|
333 |
+
$this->getCheckout()->setLastOrderId($order->getId());
|
334 |
+
$this->getCheckout()->setLastRealOrderId($order->getIncrementId());
|
335 |
+
$this->getCheckout()->setRedirectUrl($redirectUrl);
|
336 |
+
|
337 |
+
/**
|
338 |
+
* we only want to send to customer about new order when there is no redirect to third party
|
339 |
+
*/
|
340 |
+
if(!$redirectUrl)
|
341 |
+
{
|
342 |
+
$order->sendNewOrderEmail();
|
343 |
+
}
|
344 |
+
|
345 |
+
if ($this->getQuote()->getCheckoutMethod(true) == Mage_Sales_Model_Quote::CHECKOUT_METHOD_REGISTER &&
|
346 |
+
!Mage::getSingleton('customer/session')->isLoggedIn())
|
347 |
+
{
|
348 |
+
/**
|
349 |
+
* we need to save quote here to have it saved with Customer Id.
|
350 |
+
* so when loginById() executes checkout/session method loadCustomerQuote
|
351 |
+
* it would not create new quotes and merge it with old one.
|
352 |
+
*/
|
353 |
+
$this->getQuote()->save();
|
354 |
+
if ($customer->isConfirmationRequired())
|
355 |
{
|
356 |
+
Mage::getSingleton('checkout/session')->addSuccess(Mage::helper('customer')->__('Account confirmation is required. Please, check your e-mail for confirmation link. To resend confirmation email please <a href="%s">click here</a>.',
|
357 |
+
Mage::helper('customer')->getEmailConfirmationUrl($customer->getEmail())
|
358 |
+
));
|
359 |
}
|
360 |
+
else
|
361 |
+
{
|
362 |
+
Mage::getSingleton('customer/session')->loginById($customer->getId());
|
363 |
+
}
|
364 |
+
}
|
365 |
+
|
366 |
+
//Setting this one more time like control flag that we haves saved order
|
367 |
+
//Must be checkout on success page to show it or not.
|
368 |
+
$this->getCheckout()->setLastSuccessQuoteId($this->getQuote()->getId());
|
369 |
+
|
370 |
+
/*
|
371 |
+
* Fix for v1.4.1.0 and above - need to comment the below lines
|
372 |
+
*/
|
373 |
+
//$this->getQuote()->setIsActive(false);
|
374 |
+
//$this->getQuote()->save();
|
375 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
376 |
|
377 |
return $this;
|
378 |
}
|
386 |
*/
|
387 |
public function saveOrderAfter3dSecure($pares, $md)
|
388 |
{
|
389 |
+
$nVersion = $this->getVersion(Mage::getVersion());
|
390 |
+
|
391 |
+
if($nVersion >= 1410)
|
392 |
+
{
|
393 |
+
$_order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getCardsaveonlinepaymentsOrderId());
|
394 |
+
|
395 |
+
if(!$_order->getId())
|
396 |
+
{
|
397 |
+
Mage::throwException('Could not load order.');
|
398 |
+
}
|
399 |
+
|
400 |
+
Mage::getSingleton('checkout/session')->setThreedsecurerequired(true)
|
401 |
+
->setMd($md)
|
402 |
+
->setPares($pares);
|
403 |
+
|
404 |
+
$method = Mage::getSingleton('checkout/session')->getRedirectionmethod();
|
405 |
+
$_order->getPayment()->getMethodInstance()->{$method}($_order->getPayment(), $pares, $md);
|
406 |
+
|
407 |
+
if ($_order->getFailedThreed() !== true &&
|
408 |
+
$_order->getPayment()->getMethodInstance()->getCode() == 'cardsaveonlinepayments' &&
|
409 |
+
$_order->getStatus() != 'pending')
|
410 |
+
{
|
411 |
+
$order_status = Mage::getStoreConfig('payment/cardsaveonlinepayments/order_status', Mage::app()->getStore()->getId());
|
412 |
+
$_order->addStatusToHistory($order_status);
|
413 |
+
$_order->setStatus($order_status);
|
414 |
+
}
|
415 |
+
|
416 |
+
$_order->save();
|
|
|
|
|
|
|
|
|
|
|
417 |
|
418 |
+
Mage::getSingleton('checkout/session')->setThreedsecurerequired(null)
|
419 |
+
->setMd(null)
|
420 |
+
->setPareq(null)
|
421 |
+
->setAcsurl(null)
|
422 |
+
->setCardsaveonlinepaymentsOrderId(null);
|
423 |
+
}
|
424 |
+
else
|
425 |
+
{
|
426 |
+
$this->validateOrder();
|
427 |
+
$billing = $this->getQuote()->getBillingAddress();
|
428 |
+
if (!$this->getQuote()->isVirtual())
|
429 |
+
{
|
430 |
+
$shipping = $this->getQuote()->getShippingAddress();
|
431 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
432 |
|
433 |
+
switch ($this->getQuote()->getCheckoutMethod())
|
434 |
+
{
|
435 |
+
case 'guest':
|
436 |
+
$this->getQuote()->setCustomerEmail($billing->getEmail())
|
437 |
+
->setCustomerIsGuest(true)
|
438 |
+
->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
|
439 |
+
break;
|
440 |
+
|
441 |
+
default:
|
442 |
+
$customer = Mage::getSingleton('customer/session')->getCustomer();
|
443 |
+
|
444 |
+
if (!$billing->getCustomerId() ||
|
445 |
+
$billing->getSaveInAddressBook())
|
446 |
+
{
|
447 |
+
$customerBilling = $billing->exportCustomerAddress();
|
448 |
+
$customer->addAddress($customerBilling);
|
449 |
+
}
|
450 |
+
if (!$this->getQuote()->isVirtual() &&
|
451 |
+
((!$shipping->getCustomerId() && !$shipping->getSameAsBilling()) ||
|
452 |
+
(!$shipping->getSameAsBilling() && $shipping->getSaveInAddressBook())))
|
453 |
+
{
|
454 |
+
$customerShipping = $shipping->exportCustomerAddress();
|
455 |
+
$customer->addAddress($customerShipping);
|
456 |
+
}
|
457 |
+
$customer->setSavedFromQuote(true);
|
458 |
+
$customer->save();
|
459 |
+
|
460 |
+
$changed = false;
|
461 |
+
if (isset($customerBilling) &&
|
462 |
+
!$customer->getDefaultBilling())
|
463 |
+
{
|
464 |
+
$customer->setDefaultBilling($customerBilling->getId());
|
465 |
+
$changed = true;
|
466 |
+
}
|
467 |
+
if (!$this->getQuote()->isVirtual() &&
|
468 |
+
isset($customerBilling) &&
|
469 |
+
!$customer->getDefaultShipping() &&
|
470 |
+
$shipping->getSameAsBilling())
|
471 |
+
{
|
472 |
+
$customer->setDefaultShipping($customerBilling->getId());
|
473 |
+
$changed = true;
|
474 |
+
}
|
475 |
+
elseif (!$this->getQuote()->isVirtual() &&
|
476 |
+
isset($customerShipping) &&
|
477 |
+
!$customer->getDefaultShipping())
|
478 |
+
{
|
479 |
+
$customer->setDefaultShipping($customerShipping->getId());
|
480 |
+
$changed = true;
|
481 |
+
}
|
482 |
+
|
483 |
+
if ($changed)
|
484 |
+
{
|
485 |
+
$customer->save();
|
486 |
+
}
|
487 |
+
}
|
488 |
+
|
489 |
+
$this->getQuote()->reserveOrderId();
|
490 |
+
$convertQuote = Mage::getModel('sales/convert_quote');
|
491 |
+
// @var $convertQuote Mage_Sales_Model_Convert_Quote
|
492 |
+
if ($this->getQuote()->isVirtual())
|
493 |
+
{
|
494 |
+
$order = $convertQuote->addressToOrder($billing);
|
495 |
+
}
|
496 |
+
else
|
497 |
+
{
|
498 |
+
$order = $convertQuote->addressToOrder($shipping);
|
499 |
+
}
|
500 |
+
/* @var $order Mage_Sales_Model_Order */
|
501 |
+
$order->setBillingAddress($convertQuote->addressToOrderAddress($billing));
|
502 |
+
|
503 |
+
if (!$this->getQuote()->isVirtual())
|
504 |
+
{
|
505 |
+
$order->setShippingAddress($convertQuote->addressToOrderAddress($shipping));
|
506 |
+
}
|
507 |
+
|
508 |
+
$order->setPayment($convertQuote->paymentToOrderPayment($this->getQuote()->getPayment()));
|
509 |
+
|
510 |
+
foreach ($this->getQuote()->getAllItems() as $item)
|
511 |
+
{
|
512 |
+
$order->addItem($convertQuote->itemToOrderItem($item));
|
513 |
+
}
|
514 |
+
|
515 |
+
/**
|
516 |
+
* We can use configuration data for declare new order status
|
517 |
+
*/
|
518 |
+
Mage::dispatchEvent('checkout_type_onepage_save_order', array('order'=>$order, 'quote'=>$this->getQuote()));
|
519 |
+
|
520 |
+
Mage::getSingleton('checkout/session')->setThreedsecurerequired(true)
|
521 |
+
->setMd($md)
|
522 |
+
->setPares($pares);
|
523 |
+
|
524 |
+
$order->place();
|
525 |
+
|
526 |
+
if ( $order->getPayment()->getMethodInstance()->getCode() == 'cardsaveonlinepayments' &&
|
527 |
+
$order->getStatus() != 'pending' )
|
528 |
+
{
|
529 |
+
$order_status = Mage::getStoreConfig('payment/cardsaveonlinepayments/order_status', Mage::app()->getStore()->getId());
|
530 |
+
|
531 |
+
$order->addStatusToHistory($order_status);
|
532 |
+
$order->setStatus($order_status);
|
533 |
+
}
|
534 |
+
|
535 |
+
$order->save();
|
536 |
+
|
537 |
+
|
538 |
+
|
539 |
+
Mage::dispatchEvent('checkout_type_onepage_save_order_after', array('order'=>$order, 'quote'=>$this->getQuote()));
|
540 |
+
|
541 |
+
|
542 |
+
$this->getQuote()->setIsActive(false);
|
543 |
+
$this->getQuote()->save();
|
544 |
+
|
545 |
+
$orderId = $order->getIncrementId();
|
546 |
+
$this->getCheckout()->setLastQuoteId($this->getQuote()->getId());
|
547 |
+
$this->getCheckout()->setLastOrderId($order->getId());
|
548 |
+
$this->getCheckout()->setLastRealOrderId($order->getIncrementId());
|
549 |
+
// $this->getCheckout()->setRedirectUrl($redirectUrl);
|
550 |
+
|
551 |
+
/**
|
552 |
+
* we only want to send to customer about new order when there is no redirect to third party
|
553 |
+
*/
|
554 |
+
/*if(!$redirectUrl){
|
555 |
+
$order->sendNewOrderEmail();
|
556 |
+
}*/
|
557 |
+
|
558 |
+
if ($this->getQuote()->getCheckoutMethod() == 'register')
|
559 |
+
{
|
560 |
+
Mage::getSingleton('customer/session')->loginById($customer->getId());
|
561 |
+
}
|
562 |
+
}
|
563 |
return $this;
|
564 |
}
|
565 |
|
576 |
*/
|
577 |
public function saveOrderAfterRedirectedPaymentAction($boIsHostedPaymentAction, $szStatusCode, $szMessage, $szPreviousStatusCode, $szPreviousMessage, $szOrderID)
|
578 |
{
|
579 |
+
$nVersion = $this->getVersion(Mage::getVersion());
|
580 |
+
|
581 |
+
if($nVersion >= 1410)
|
582 |
+
{
|
583 |
+
$_order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getCardsaveonlinepaymentsOrderId());
|
584 |
+
|
585 |
+
if(!$_order->getId())
|
586 |
+
{
|
587 |
+
Mage::throwException('Could not load order.');
|
588 |
+
}
|
589 |
+
|
590 |
+
Mage::getSingleton('checkout/session')->setRedirectedpayment(true)
|
591 |
+
->setIshostedpayment($boIsHostedPaymentAction)
|
592 |
+
->setStatuscode($szStatusCode)
|
593 |
+
->setMessage($szMessage)
|
594 |
+
->setPreviousstatuscode($szPreviousStatusCode)
|
595 |
+
->setPreviousmessage($szPreviousMessage)
|
596 |
+
->setOrderid($szOrderID);
|
597 |
+
|
598 |
+
$method = Mage::getSingleton('checkout/session')->getRedirectionmethod();
|
599 |
+
$_order->getPayment()->getMethodInstance()->{$method}($_order->getPayment(), $boIsHostedPaymentAction, $szStatusCode, $szMessage, $szPreviousStatusCode, $szPreviousMessage, $szOrderID);
|
600 |
+
|
601 |
+
if ($_order->getFailedThreed() !== true &&
|
602 |
+
$_order->getPayment()->getMethodInstance()->getCode() == 'cardsaveonlinepayments' &&
|
603 |
+
$_order->getStatus() != 'pending')
|
604 |
+
{
|
605 |
+
$order_status = Mage::getStoreConfig('payment/cardsaveonlinepayments/order_status', Mage::app()->getStore()->getId());
|
606 |
+
$_order->addStatusToHistory($order_status);
|
607 |
+
$_order->setStatus($order_status);
|
608 |
+
}
|
|
|
|
|
|
|
|
|
609 |
|
610 |
+
$_order->save();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
611 |
|
612 |
+
Mage::getSingleton('checkout/session')->setRedirectedpayment(null)
|
613 |
+
->setIshostedpayment(null)
|
614 |
+
->setStatuscode(null)
|
615 |
+
->setMessage(null)
|
616 |
+
->setPreviousstatuscode(null)
|
617 |
+
->setPreviousmessage(null)
|
618 |
+
->setOrderid(null)
|
619 |
+
->setCardsaveonlinepaymentsOrderId(null);
|
620 |
+
}
|
621 |
+
else
|
622 |
+
{
|
623 |
+
$this->validateOrder();
|
624 |
+
$billing = $this->getQuote()->getBillingAddress();
|
625 |
+
|
626 |
+
if (!$this->getQuote()->isVirtual())
|
627 |
+
{
|
628 |
+
$shipping = $this->getQuote()->getShippingAddress();
|
629 |
+
}
|
630 |
+
|
631 |
+
switch ($this->getQuote()->getCheckoutMethod())
|
632 |
+
{
|
633 |
+
case 'guest':
|
634 |
+
$this->getQuote()->setCustomerEmail($billing->getEmail())
|
635 |
+
->setCustomerIsGuest(true)
|
636 |
+
->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
|
637 |
+
break;
|
638 |
+
|
639 |
+
default:
|
640 |
+
$customer = Mage::getSingleton('customer/session')->getCustomer();
|
641 |
+
|
642 |
+
if (!$billing->getCustomerId() ||
|
643 |
+
$billing->getSaveInAddressBook())
|
644 |
+
{
|
645 |
+
$customerBilling = $billing->exportCustomerAddress();
|
646 |
+
$customer->addAddress($customerBilling);
|
647 |
+
}
|
648 |
+
if (!$this->getQuote()->isVirtual() &&
|
649 |
+
((!$shipping->getCustomerId() && !$shipping->getSameAsBilling()) ||
|
650 |
+
(!$shipping->getSameAsBilling() && $shipping->getSaveInAddressBook())))
|
651 |
+
{
|
652 |
+
$customerShipping = $shipping->exportCustomerAddress();
|
653 |
+
$customer->addAddress($customerShipping);
|
654 |
+
}
|
655 |
+
$customer->setSavedFromQuote(true);
|
656 |
+
$customer->save();
|
657 |
+
|
658 |
+
$changed = false;
|
659 |
+
if (isset($customerBilling) &&
|
660 |
+
!$customer->getDefaultBilling())
|
661 |
+
{
|
662 |
+
$customer->setDefaultBilling($customerBilling->getId());
|
663 |
+
$changed = true;
|
664 |
+
}
|
665 |
+
if (!$this->getQuote()->isVirtual() &&
|
666 |
+
isset($customerBilling) &&
|
667 |
+
!$customer->getDefaultShipping() &&
|
668 |
+
$shipping->getSameAsBilling())
|
669 |
+
{
|
670 |
+
$customer->setDefaultShipping($customerBilling->getId());
|
671 |
+
$changed = true;
|
672 |
+
}
|
673 |
+
elseif (!$this->getQuote()->isVirtual() &&
|
674 |
+
isset($customerShipping) &&
|
675 |
+
!$customer->getDefaultShipping())
|
676 |
+
{
|
677 |
+
$customer->setDefaultShipping($customerShipping->getId());
|
678 |
+
$changed = true;
|
679 |
+
}
|
680 |
+
|
681 |
+
if ($changed)
|
682 |
+
{
|
683 |
+
$customer->save();
|
684 |
+
}
|
685 |
+
}
|
686 |
+
|
687 |
+
$this->getQuote()->reserveOrderId();
|
688 |
+
$convertQuote = Mage::getModel('sales/convert_quote');
|
689 |
+
// @var $convertQuote Mage_Sales_Model_Convert_Quote
|
690 |
+
if ($this->getQuote()->isVirtual())
|
691 |
+
{
|
692 |
+
$order = $convertQuote->addressToOrder($billing);
|
693 |
+
}
|
694 |
+
else
|
695 |
+
{
|
696 |
+
$order = $convertQuote->addressToOrder($shipping);
|
697 |
+
}
|
698 |
+
/* @var $order Mage_Sales_Model_Order */
|
699 |
+
$order->setBillingAddress($convertQuote->addressToOrderAddress($billing));
|
700 |
+
|
701 |
+
if (!$this->getQuote()->isVirtual())
|
702 |
+
{
|
703 |
+
$order->setShippingAddress($convertQuote->addressToOrderAddress($shipping));
|
704 |
+
}
|
705 |
+
|
706 |
+
$order->setPayment($convertQuote->paymentToOrderPayment($this->getQuote()->getPayment()));
|
707 |
+
|
708 |
+
foreach ($this->getQuote()->getAllItems() as $item)
|
709 |
+
{
|
710 |
+
$order->addItem($convertQuote->itemToOrderItem($item));
|
711 |
+
}
|
712 |
+
|
713 |
+
/**
|
714 |
+
* We can use configuration data for declare new order status
|
715 |
+
*/
|
716 |
+
Mage::dispatchEvent('checkout_type_onepage_save_order', array('order'=>$order, 'quote'=>$this->getQuote()));
|
717 |
+
|
718 |
+
Mage::getSingleton('checkout/session')->setRedirectedpayment(true)
|
719 |
+
->setIshostedpayment($boIsHostedPaymentAction)
|
720 |
+
->setStatuscode($szStatusCode)
|
721 |
+
->setMessage($szMessage)
|
722 |
+
->setPreviousstatuscode($szPreviousStatusCode)
|
723 |
+
->setPreviousmessage($szPreviousMessage)
|
724 |
+
->setOrderid($szOrderID);
|
725 |
+
|
726 |
+
$order->place();
|
727 |
+
|
728 |
+
if ( $order->getPayment()->getMethodInstance()->getCode() == 'cardsaveonlinepayments' &&
|
729 |
+
$order->getStatus() != 'pending' )
|
730 |
+
{
|
731 |
+
$order_status = Mage::getStoreConfig('payment/cardsaveonlinepayments/order_status', Mage::app()->getStore()->getId());
|
732 |
+
|
733 |
+
$order->addStatusToHistory($order_status);
|
734 |
+
$order->setStatus($order_status);
|
735 |
+
}
|
736 |
+
|
737 |
+
$order->save();
|
738 |
+
|
739 |
+
Mage::dispatchEvent('checkout_type_onepage_save_order_after', array('order'=>$order, 'quote'=>$this->getQuote()));
|
740 |
+
|
741 |
+
$this->getQuote()->setIsActive(false);
|
742 |
+
$this->getQuote()->save();
|
743 |
+
|
744 |
+
$orderId = $order->getIncrementId();
|
745 |
+
$this->getCheckout()->setLastQuoteId($this->getQuote()->getId());
|
746 |
+
$this->getCheckout()->setLastOrderId($order->getId());
|
747 |
+
$this->getCheckout()->setLastRealOrderId($order->getIncrementId());
|
748 |
+
|
749 |
+
/**
|
750 |
+
* we only want to send to customer about new order when there is no redirect to third party
|
751 |
+
*/
|
752 |
+
/*if(!$redirectUrl){
|
753 |
+
$order->sendNewOrderEmail();
|
754 |
+
}*/
|
755 |
+
|
756 |
+
if ($this->getQuote()->getCheckoutMethod()=='register')
|
757 |
+
{
|
758 |
+
Mage::getSingleton('customer/session')->loginById($customer->getId());
|
759 |
+
}
|
760 |
+
}
|
761 |
|
762 |
return $this;
|
763 |
}
|
app/code/local/Cardsave/Checkout/etc/config.xml
CHANGED
@@ -21,4 +21,4 @@
|
|
21 |
</checkout>
|
22 |
</blocks>
|
23 |
</global>
|
24 |
-
</config>
|
21 |
</checkout>
|
22 |
</blocks>
|
23 |
</global>
|
24 |
+
</config>
|
app/code/local/Cardsave/Sales/Model/Order/Payment.php
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Cardsave_Sales_Model_Order_Payment extends Mage_Sales_Model_Order_Payment
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Authorize or authorize and capture payment on gateway, if applicable
|
7 |
+
* This method is supposed to be called only when order is placed
|
8 |
+
*
|
9 |
+
* @return Mage_Sales_Model_Order_Payment
|
10 |
+
*/
|
11 |
+
public function place()
|
12 |
+
{
|
13 |
+
Mage::dispatchEvent('sales_order_payment_place_start', array('payment' => $this));
|
14 |
+
$order = $this->getOrder();
|
15 |
+
|
16 |
+
$this->setAmountOrdered($order->getTotalDue());
|
17 |
+
$this->setBaseAmountOrdered($order->getBaseTotalDue());
|
18 |
+
$this->setShippingAmount($order->getShippingAmount());
|
19 |
+
$this->setBaseShippingAmount($order->getBaseShippingAmount());
|
20 |
+
|
21 |
+
$methodInstance = $this->getMethodInstance();
|
22 |
+
$methodInstance->setStore($order->getStoreId());
|
23 |
+
|
24 |
+
$orderState = Mage_Sales_Model_Order::STATE_NEW;
|
25 |
+
$orderStatus= false;
|
26 |
+
|
27 |
+
$stateObject = new Varien_Object();
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Do order payment validation on payment method level
|
31 |
+
*/
|
32 |
+
$methodInstance->validate();
|
33 |
+
$action = $methodInstance->getConfigPaymentAction();
|
34 |
+
if ($action) {
|
35 |
+
if ($methodInstance->isInitializeNeeded()) {
|
36 |
+
/**
|
37 |
+
* For method initialization we have to use original config value for payment action
|
38 |
+
*/
|
39 |
+
$methodInstance->initialize($methodInstance->getConfigData('payment_action'), $stateObject);
|
40 |
+
} else {
|
41 |
+
$orderState = Mage_Sales_Model_Order::STATE_PROCESSING;
|
42 |
+
switch ($action) {
|
43 |
+
case Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE:
|
44 |
+
$this->_authorize(true, $order->getBaseTotalDue()); // base amount will be set inside
|
45 |
+
$this->setAmountAuthorized($order->getTotalDue());
|
46 |
+
break;
|
47 |
+
case Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE:
|
48 |
+
$this->setAmountAuthorized($order->getTotalDue());
|
49 |
+
$this->setBaseAmountAuthorized($order->getBaseTotalDue());
|
50 |
+
$this->capture(null);
|
51 |
+
break;
|
52 |
+
default:
|
53 |
+
break;
|
54 |
+
}
|
55 |
+
}
|
56 |
+
}
|
57 |
+
|
58 |
+
$this->_createBillingAgreement();
|
59 |
+
|
60 |
+
$orderIsNotified = null;
|
61 |
+
if ($stateObject->getState() && $stateObject->getStatus())
|
62 |
+
{
|
63 |
+
$orderState = $stateObject->getState();
|
64 |
+
$orderStatus = $stateObject->getStatus();
|
65 |
+
$orderIsNotified = $stateObject->getIsNotified();
|
66 |
+
}
|
67 |
+
else if($order->getIsThreeDSecurePending())
|
68 |
+
{
|
69 |
+
$orderState = 'pending_payment';
|
70 |
+
$orderStatus = 'cardsave_pending_threed_secure';
|
71 |
+
$orderIsNotified = false;
|
72 |
+
$order->setCustomerNote(Mage::helper('cardsaveonlinepayments')->__('Pending 3D Secure Authentication.'));
|
73 |
+
}
|
74 |
+
else if($order->getIsHostedPaymentPending())
|
75 |
+
{
|
76 |
+
$order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, true)->save();
|
77 |
+
$orderState = 'pending_payment';
|
78 |
+
$orderStatus = 'cardsave_pending_hosted_payment';
|
79 |
+
$orderIsNotified = false;
|
80 |
+
$order->setCustomerNote(Mage::helper('cardsaveonlinepayments')->__('Pending Hosted Payment.'));
|
81 |
+
}
|
82 |
+
else
|
83 |
+
{
|
84 |
+
$orderStatus = $methodInstance->getConfigData('order_status');
|
85 |
+
if (!$orderStatus || $order->getIsVirtual())
|
86 |
+
{
|
87 |
+
$orderStatus = $order->getConfig()->getStateDefaultStatus($orderState);
|
88 |
+
}
|
89 |
+
}
|
90 |
+
|
91 |
+
$isCustomerNotified = (null !== $orderIsNotified) ? $orderIsNotified : $order->getCustomerNoteNotify();
|
92 |
+
$message = $order->getCustomerNote();
|
93 |
+
|
94 |
+
// add message if order was put into review during authorization or capture
|
95 |
+
if ($order->getState() == Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW)
|
96 |
+
{
|
97 |
+
if ($message)
|
98 |
+
{
|
99 |
+
$order->addStatusToHistory($order->getStatus(), $message, $isCustomerNotified);
|
100 |
+
}
|
101 |
+
}
|
102 |
+
// add message to history if order state already declared
|
103 |
+
elseif ($order->getState() && ($orderStatus !== $order->getStatus() || $message))
|
104 |
+
{
|
105 |
+
$order->setState($orderState, $orderStatus, $message, $isCustomerNotified);
|
106 |
+
}
|
107 |
+
// set order state
|
108 |
+
elseif (($order->getState() != $orderState) || ($order->getStatus() != $orderStatus) || $message)
|
109 |
+
{
|
110 |
+
$order->setState($orderState, $orderStatus, $message, $isCustomerNotified);
|
111 |
+
}
|
112 |
+
|
113 |
+
Mage::dispatchEvent('sales_order_payment_place_end', array('payment' => $this));
|
114 |
+
|
115 |
+
return $this;
|
116 |
+
}
|
117 |
+
}
|
app/code/local/Cardsave/Sales/Model/Service/Quote.php
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Cardsave_Sales_Model_Service_Quote extends Mage_Sales_Model_Service_Quote
|
4 |
+
{
|
5 |
+
public function submitOrder()
|
6 |
+
{
|
7 |
+
if ($this->_quote->getPayment()->getMethodInstance()->getCode() != 'cardsaveonlinepayments')
|
8 |
+
{
|
9 |
+
return parent::submitOrder();
|
10 |
+
}
|
11 |
+
|
12 |
+
$this->_deleteNominalItems();
|
13 |
+
$this->_validate();
|
14 |
+
$quote = $this->_quote;
|
15 |
+
$isVirtual = $quote->isVirtual();
|
16 |
+
|
17 |
+
$transaction = Mage::getModel('core/resource_transaction');
|
18 |
+
if ($quote->getCustomerId())
|
19 |
+
{
|
20 |
+
$transaction->addObject($quote->getCustomer());
|
21 |
+
}
|
22 |
+
$transaction->addObject($quote);
|
23 |
+
|
24 |
+
$quote->reserveOrderId();
|
25 |
+
if ($isVirtual)
|
26 |
+
{
|
27 |
+
$order = $this->_convertor->addressToOrder($quote->getBillingAddress());
|
28 |
+
}
|
29 |
+
else
|
30 |
+
{
|
31 |
+
$order = $this->_convertor->addressToOrder($quote->getShippingAddress());
|
32 |
+
}
|
33 |
+
$order->setBillingAddress($this->_convertor->addressToOrderAddress($quote->getBillingAddress()));
|
34 |
+
|
35 |
+
if (!$isVirtual)
|
36 |
+
{
|
37 |
+
$order->setShippingAddress($this->_convertor->addressToOrderAddress($quote->getShippingAddress()));
|
38 |
+
}
|
39 |
+
$order->setPayment($this->_convertor->paymentToOrderPayment($quote->getPayment()));
|
40 |
+
|
41 |
+
foreach ($this->_orderData as $key => $value)
|
42 |
+
{
|
43 |
+
$order->setData($key, $value);
|
44 |
+
}
|
45 |
+
|
46 |
+
foreach ($quote->getAllItems() as $item)
|
47 |
+
{
|
48 |
+
$orderItem = $this->_convertor->itemToOrderItem($item);
|
49 |
+
if ($item->getParentItem())
|
50 |
+
{
|
51 |
+
$orderItem->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId()));
|
52 |
+
}
|
53 |
+
$order->addItem($orderItem);
|
54 |
+
}
|
55 |
+
$quote->setIsActive(false);
|
56 |
+
|
57 |
+
$transaction->addObject($order);
|
58 |
+
$transaction->addCommitCallback(array($order, 'place'));
|
59 |
+
$transaction->addCommitCallback(array($order, 'save'));
|
60 |
+
|
61 |
+
/**
|
62 |
+
* We can use configuration data for declare new order status
|
63 |
+
*/
|
64 |
+
Mage::dispatchEvent('checkout_type_onepage_save_order', array('order'=>$order, 'quote'=>$quote));
|
65 |
+
Mage::dispatchEvent('sales_model_service_quote_submit_before', array('order'=>$order, 'quote'=>$quote));
|
66 |
+
try
|
67 |
+
{
|
68 |
+
$transaction->save();
|
69 |
+
Mage::dispatchEvent('sales_model_service_quote_submit_success', array('order'=>$order, 'quote'=>$quote));
|
70 |
+
|
71 |
+
// need to store the orderID in the session for the callback from an external page
|
72 |
+
Mage::getSingleton('checkout/session')->setCardsaveonlinepaymentsOrderId($order->getId());
|
73 |
+
|
74 |
+
}
|
75 |
+
catch (Exception $e)
|
76 |
+
{
|
77 |
+
Mage::logException($e);
|
78 |
+
Mage::dispatchEvent('sales_model_service_quote_submit_failure', array('order'=>$order, 'quote'=>$quote));
|
79 |
+
throw $e;
|
80 |
+
}
|
81 |
+
Mage::dispatchEvent('sales_model_service_quote_submit_after', array('order'=>$order, 'quote'=>$quote));
|
82 |
+
$this->_order = $order;
|
83 |
+
|
84 |
+
return $order;
|
85 |
+
}
|
86 |
+
|
87 |
+
}
|
app/code/local/Cardsave/Sales/etc/config.xml
CHANGED
@@ -11,8 +11,31 @@
|
|
11 |
<rewrite>
|
12 |
<order>Cardsave_Sales_Model_Order</order>
|
13 |
<order_invoice>Cardsave_Sales_Model_Order_Invoice</order_invoice>
|
|
|
|
|
14 |
</rewrite>
|
15 |
</sales>
|
16 |
</models>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
</global>
|
18 |
</config>
|
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>
|
19 |
+
<sales>
|
20 |
+
<order>
|
21 |
+
<statuses>
|
22 |
+
<cardsave_pending_threed_secure translate="label">
|
23 |
+
<label>CardSave - Pending 3D Secure</label>
|
24 |
+
</cardsave_pending_threed_secure>
|
25 |
+
<cardsave_failed_threed_secure translate="label">
|
26 |
+
<label>CardSave - Failed 3D Secure</label>
|
27 |
+
</cardsave_failed_threed_secure>
|
28 |
+
<cardsave_pending translate="label">
|
29 |
+
<label>CardSave - Pending Hosted Payment</label>
|
30 |
+
</cardsave_pending>
|
31 |
+
<cardsave_pending_hosted_payment translate="label">
|
32 |
+
<label>CardSave - Pending Hosted Payment</label>
|
33 |
+
</cardsave_pending_hosted_payment>
|
34 |
+
<cardsave_failed_hosted_payment translate="label">
|
35 |
+
<label>CardSave - Failed Hosted Payment</label>
|
36 |
+
</cardsave_failed_hosted_payment>
|
37 |
+
</statuses>
|
38 |
+
</order>
|
39 |
+
</sales>
|
40 |
</global>
|
41 |
</config>
|
app/design/adminhtml/default/default/template/cardsaveonlinepayments/info.phtml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php $direct = Mage::getModel('cardsaveonlinepayments/direct'); ?>
|
2 |
<?php if ($direct->getConfigData('mode') != Cardsave_Cardsaveonlinepayments_Model_Source_PaymentMode::PAYMENT_MODE_DIRECT_API) {?>
|
3 |
<?php if ($direct->getConfigData('mode') == Cardsave_Cardsaveonlinepayments_Model_Source_PaymentMode::PAYMENT_MODE_HOSTED_PAYMENT_FORM) {?>
|
4 |
-
<?php echo $this->__('
|
5 |
<?php } else {?>
|
6 |
<?php echo $this->__('No card information is available'); ?>
|
7 |
<?php }?>
|
1 |
<?php $direct = Mage::getModel('cardsaveonlinepayments/direct'); ?>
|
2 |
<?php if ($direct->getConfigData('mode') != Cardsave_Cardsaveonlinepayments_Model_Source_PaymentMode::PAYMENT_MODE_DIRECT_API) {?>
|
3 |
<?php if ($direct->getConfigData('mode') == Cardsave_Cardsaveonlinepayments_Model_Source_PaymentMode::PAYMENT_MODE_HOSTED_PAYMENT_FORM) {?>
|
4 |
+
<?php echo $this->__('You will be redirected to a secure payment page'); ?>
|
5 |
<?php } else {?>
|
6 |
<?php echo $this->__('No card information is available'); ?>
|
7 |
<?php }?>
|
app/design/frontend/default/default/template/cardsaveonlinepayments/info.phtml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php $direct = Mage::getModel('cardsaveonlinepayments/direct'); ?>
|
2 |
<?php if ($direct->getConfigData('mode') != Cardsave_Cardsaveonlinepayments_Model_Source_PaymentMode::PAYMENT_MODE_DIRECT_API) {?>
|
3 |
<?php if ($direct->getConfigData('mode') == Cardsave_Cardsaveonlinepayments_Model_Source_PaymentMode::PAYMENT_MODE_HOSTED_PAYMENT_FORM) {?>
|
4 |
-
<?php echo $this->__('
|
5 |
<?php } else {?>
|
6 |
<?php echo $this->__('No card information is available'); ?>
|
7 |
<?php }?>
|
1 |
<?php $direct = Mage::getModel('cardsaveonlinepayments/direct'); ?>
|
2 |
<?php if ($direct->getConfigData('mode') != Cardsave_Cardsaveonlinepayments_Model_Source_PaymentMode::PAYMENT_MODE_DIRECT_API) {?>
|
3 |
<?php if ($direct->getConfigData('mode') == Cardsave_Cardsaveonlinepayments_Model_Source_PaymentMode::PAYMENT_MODE_HOSTED_PAYMENT_FORM) {?>
|
4 |
+
<?php echo $this->__('You will be redirected to a secure payment page'); ?>
|
5 |
<?php } else {?>
|
6 |
<?php echo $this->__('No card information is available'); ?>
|
7 |
<?php }?>
|
package.xml
CHANGED
@@ -1,18 +1,20 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Cardsave_Cardsaveonlinepayments</name>
|
4 |
-
<version>1.8.
|
5 |
<stability>stable</stability>
|
6 |
<license>OSL v3.0</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
-
<summary>
|
10 |
<description>Fully supports 3D secure transactions. Also supports all of the integration methods provided by Cardsave.</description>
|
11 |
-
<notes>
|
12 |
-
|
13 |
-
|
14 |
-
<
|
15 |
-
<
|
|
|
|
|
16 |
<compatible/>
|
17 |
<dependencies/>
|
18 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Cardsave_Cardsaveonlinepayments</name>
|
4 |
+
<version>1.8.3</version>
|
5 |
<stability>stable</stability>
|
6 |
<license>OSL v3.0</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
+
<summary>Cardsave Payment Extension for Magento v1.4.1.0 and above</summary>
|
10 |
<description>Fully supports 3D secure transactions. Also supports all of the integration methods provided by Cardsave.</description>
|
11 |
+
<notes>Fix to run on Magento v1.4.1.0 and above.
|
12 |
+
Fix to manage stock properly.
|
13 |
+
Fix to update the Order status properly.</notes>
|
14 |
+
<authors><author><name>cardsave</name><user>auto-converted</user><email>integrationsupport@cardsaveonlinepayments.com</email></author></authors>
|
15 |
+
<date>2010-10-18</date>
|
16 |
+
<time>09:24:20</time>
|
17 |
+
<contents><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="cardsaveonlinepayments"><file name="form.phtml" hash="2b0b8a72c9f4a6d2ab9f0ea020c8f2ed"/><file name="info.phtml" hash="935e10cad0632d558b2db1913cb80a2a"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="template"><dir name="cardsaveonlinepayments"><file name="form.phtml" hash="206c8703ef4d160dfc6c739c128ab47b"/><file name="info.phtml" hash="7256464904bbad66a821dea898d657a6"/></dir></dir></dir></dir></dir></target><target name="magelocal"><dir name="Cardsave"><dir name="Cardsaveonlinepayments"><dir name="Block"><file name="Error.php" hash="660d3cbde48910ef271df9e05130a6d7"/><file name="Form.php" hash="ea5b3817c9607a94f4685d53d0b18569"/><file name="Info.php" hash="57a4bfec1a1c769de063be2b922f4a97"/><file name="Redirect.php" hash="b5a1f7af807dc9a41ec5b9db5c74e87e"/><file name="Threedsecure.php" hash="1715396760374c5bf11cc7e86d75e6ce"/></dir><dir name="controllers"><file name="PaymentController.php" hash="3075aa96039c0fd29aeacbe1db4685c4"/></dir><dir name="etc"><file name="config.xml" hash="14507a95509d6366272555a05ba110c9"/><file name="system.xml" hash="4d0eab1c1a11d3e2078802499ad49f1e"/></dir><dir name="Helper"><file name="Data.php" hash="e024ec0479d1e8e7efcf4751b05194d6"/></dir><dir name="Model"><file name="Direct.php" hash="b49148a9a4647226b29575e734b912e5"/><file name="Request.php" hash="370f028086d13ae1df470e93a67dea66"/><dir name="Common"><file name="GlobalErrors.php" hash="04d277d4a763efa508bf36d29c7dc8c4"/><file name="ISOCountries.php" hash="78dc558da68ca9a6ef44898a3980ecf2"/><file name="ISOCurrencies.php" hash="a32bc47b2d9896c293ecdcbf847144f9"/><file name="PaymentFormHelper.php" hash="75d4ea669fae3eb62df24c45f83a5a60"/><dir name="ThePaymentGateway"><file name="PaymentSystem.php" hash="e4d4df170c21b7e3571b3ba1205ca979"/><file name="SOAP.php" hash="a0e5474dce51dc90ba4d37b5de3cdd84"/><file name="TPG_Common.php" hash="d86997c977cfd55b8ab577a514ab149c"/></dir></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></dir><dir name="Checkout"><dir name="Block"><dir name="Onepage"><dir name="Payment"><file name="Methods.php" hash="695d628564f6e1e0c85e3821699e6b45"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="9dbd58b6b32491d65e5c7d5850aa3420"/></dir><dir name="Model"><dir name="Type"><file name="Onepage.php" hash="e3d27996d67ced85884ab3dbd9dd1199"/></dir></dir></dir><dir name="Sales"><dir name="etc"><file name="config.xml" hash="01b499b658358c8d6f608d8f01158e54"/></dir><dir name="Model"><file name="Order.php" hash="9ffa9e06b0d5d8d2d810ab50017e81fa"/><dir name="Order"><file name="Invoice.php" hash="e7e1e003f4e8c0540ff8e9ad0465a6cb"/><file name="Payment.php" hash="caba45b28b4e369c89deae6f81f5a8b2"/></dir><dir name="Service"><file name="Quote.php" hash="2cca459cf3338bf53501fe836b8b9f96"/></dir></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="default"><dir name="default"><dir name="images"><file name="cardsave_online.jpg" hash="abb239c81edb9ae8df8cf891e914e2aa"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Cardsave_All.xml" hash="e1d59fd8c4d4b5d87607f43fecf47e59"/></dir></target></contents>
|
18 |
<compatible/>
|
19 |
<dependencies/>
|
20 |
</package>
|