Litle_Payments - Version 8.13.0

Version Notes

This extension implements Litle XML version 8.13

Additional features include enhanced reporting on orders, transactions, and customers.

Download this release

Release Info

Developer Litle
Extension Litle_Payments
Version 8.13.0
Comparing to
See all releases


Code changes from version 8.10.2 to 8.13.0

Files changed (44) hide show
  1. app/code/local/Litle/CreditCard/Block/Adminhtml/Ordergrid.php +14 -0
  2. app/code/local/Litle/CreditCard/Block/Adminhtml/Orderview.php +103 -0
  3. app/code/local/Litle/CreditCard/Block/Form/CreditCard.php +178 -0
  4. app/code/local/Litle/CreditCard/Helper/Data.php +66 -0
  5. app/code/local/Litle/CreditCard/Model/Cctypes.php +43 -0
  6. app/code/local/Litle/CreditCard/Model/Lpayment.php +452 -0
  7. app/code/local/Litle/CreditCard/Model/Order/Payment.php +166 -0
  8. app/code/local/Litle/CreditCard/Model/PaymentLogic.php +378 -55
  9. app/code/local/Litle/CreditCard/Model/ValidateMerchantId.php +31 -0
  10. app/code/local/Litle/CreditCard/Model/Validatehttp.php +11 -1
  11. app/code/local/Litle/CreditCard/controllers/Adminhtml/OrderController.php +47 -0
  12. app/code/local/Litle/CreditCard/etc/config.xml +71 -16
  13. app/code/local/Litle/CreditCard/etc/system.xml +37 -10
  14. app/code/local/Litle/LEcheck/Model/PaymentLogic.php +56 -29
  15. app/code/local/Litle/LEcheck/etc/config.xml +1 -1
  16. app/code/local/Litle/LEcheck/etc/system.xml +1 -59
  17. app/code/local/Litle/LitleSDK/Checker.php +1 -1
  18. app/code/local/Litle/LitleSDK/LitleOnline.php +2 -1
  19. app/code/local/Litle/LitleSDK/LitleOnlineRequest.php +28 -7
  20. app/code/local/Litle/LitleSDK/Obj2xml.php +22 -8
  21. app/code/local/Litle/LitleSDK/Setup.php +5 -21
  22. app/code/local/Litle/LitleSDK/UrlMapper.php +42 -0
  23. app/code/local/Litle/LitleSDK/XmlFields.php +34 -6
  24. app/code/local/Litle/Palorus/Block/Adminhtml/Palorus/Insight/Tab.php +190 -0
  25. app/code/local/Litle/Palorus/Block/Adminhtml/Transaction.php +104 -0
  26. app/code/local/Litle/Palorus/Helper/Data.php +128 -0
  27. app/code/local/Litle/Palorus/Model/Insight.php +13 -0
  28. app/code/local/Litle/Palorus/Model/Mysql4/Insight.php +9 -0
  29. app/code/local/Litle/Palorus/Model/Mysql4/Insight/Collection.php +11 -0
  30. app/code/local/Litle/Palorus/Model/Mysql4/Vault.php +9 -0
  31. app/code/local/Litle/Palorus/Model/Mysql4/Vault/Collection.php +11 -0
  32. app/code/local/Litle/Palorus/Model/Vault.php +13 -0
  33. app/code/local/Litle/Palorus/controllers/Adminhtml/MyformController.php +77 -0
  34. app/code/local/Litle/Palorus/etc/config.xml +190 -0
  35. app/code/local/Litle/Palorus/sql/palorus_setup/mysql4-install-8.13.0.php +47 -0
  36. app/design/adminhtml/default/default/layout/litle.xml +19 -0
  37. app/design/adminhtml/default/default/template/payment/form/litlecc.phtml +138 -0
  38. app/design/adminhtml/default/default/template/payment/form/litleecheck.phtml +35 -0
  39. app/design/frontend/base/default/layout/litlecreditcard.xml +7 -0
  40. app/design/frontend/base/default/template/payment/form/litlecc.phtml +254 -0
  41. app/design/frontend/base/default/template/payment/form/litlejs.phtml +9 -0
  42. app/design/frontend/default/default/template/payment/form/litlecc.phtml +254 -0
  43. app/etc/modules/Litle_All.xml +7 -0
  44. package.xml +6 -7
app/code/local/Litle/CreditCard/Block/Adminhtml/Ordergrid.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Litle_CreditCard_Block_Adminhtml_Ordergrid extends Mage_Adminhtml_Block_Sales_Order_Grid {
4
+
5
+ protected function _prepareMassaction()
6
+ {
7
+ parent::_prepareMassaction();
8
+
9
+ $this->getMassactionBlock()->addItem('Capture', array(
10
+ 'label' => Mage::helper('sales')->__('Capture'),
11
+ 'url' => $this->getUrl('creditcard/adminhtml_order/massCapture')
12
+ ));
13
+ }
14
+ }
app/code/local/Litle/CreditCard/Block/Adminhtml/Orderview.php ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento Plieninger Editable Module
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ *
22
+ * @category Plieninger
23
+ * @package Plieninger_Editable
24
+ * @copyright Copyright (c) 2009 Andreas Plieninger
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL)
26
+ * @author Andreas Plieninger <aplieninger@gmx.de> www.plieninger.org
27
+ * @version 0.1.0
28
+ * @date 18.12.2009
29
+ */
30
+
31
+
32
+ class Litle_CreditCard_Block_Adminhtml_Orderview extends Mage_Adminhtml_Block_Sales_Order_View {
33
+
34
+ public function __construct() {
35
+ parent::__construct();
36
+
37
+
38
+ $order = $this->getOrder();
39
+ if(Mage::helper("creditcard")->isMOPLitle($order->getPayment()))
40
+ {
41
+ // check if Auth-Reversal needs to be shown
42
+ if( Mage::helper("creditcard")->isStateOfOrderEqualTo($order, Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH) &&
43
+ !(Mage::helper("creditcard")->isMOPLitleECheck($order->getPayment()->getData('method')))
44
+ )
45
+ {
46
+ $message = 'Are you sure you want to reverse the authorization?';
47
+ $this->_updateButton('void_payment', 'label','Auth-Reversal');
48
+ $this->_updateButton('void_payment', 'onclick', "confirmSetLocation('{$message}', '{$this->getVoidPaymentUrl()}')");
49
+ }
50
+ // check if Void-Refund needs to be shown
51
+ else if( Mage::helper("creditcard")->isStateOfOrderEqualTo($order, Mage_Sales_Model_Order_Payment_Transaction::TYPE_REFUND))
52
+ {
53
+ $onclickJs = 'deleteConfirm(\''
54
+ . Mage::helper('sales')->__('Are you sure? The refund request will be canceled.')
55
+ . '\', \'' . $this->getVoidPaymentUrl() . '\');';
56
+
57
+ $this->_addButton('void_refund', array(
58
+ 'label' => 'Void Refund',
59
+ 'onclick' => $onclickJs,
60
+ ));
61
+ }
62
+ //check if void capture or void sale needs to be shown
63
+ else if(Mage::helper("creditcard")->isStateOfOrderEqualTo($order, Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE) &&
64
+ $this->wasLastTxnLessThan48HrsAgo($order->getPayment()))
65
+ {
66
+ $mop = $order->getPayment()->getData('method');
67
+ //check if paying with a credit card
68
+ if(Mage::helper("creditcard")->isMOPLitleCC($mop)){
69
+ $onclickJs = 'deleteConfirm(\''
70
+ . Mage::helper('sales')->__('Are you sure? If any previous partial captures were done on this order, or if capture was not done today then do a refund instead.')
71
+ . '\', \'' . $this->getVoidPaymentUrl() . '\');';
72
+
73
+ $this->_addButton('void_capture', array(
74
+ 'label' => 'Void Capture',
75
+ 'onclick' => $onclickJs,
76
+ ));
77
+ }
78
+ //check if paying with Litle echeck
79
+ elseif(Mage::helper("creditcard")->isMOPLitleECheck($mop)){
80
+ $onclickJs = 'deleteConfirm(\''
81
+ . Mage::helper('sales')->__('Are you sure? If any previous partial captures were done on this order, or if capture was not done today then do a refund instead.')
82
+ . '\', \'' . $this->getVoidPaymentUrl() . '\');';
83
+
84
+ $this->_addButton('void_sale', array(
85
+ 'label' => 'Void Sale',
86
+ 'onclick' => $onclickJs,
87
+ ));
88
+ }
89
+ }
90
+ }
91
+ }
92
+
93
+ public function wasLastTxnLessThan48HrsAgo(Varien_Object $payment)
94
+ {
95
+ $lastTxnId = $payment->getLastTransId();
96
+ $lastTxn = $payment->getTransaction($lastTxnId);
97
+ $timeOfLastTxn = $lastTxn->getData('created_at');
98
+
99
+ //check if last txn was less than 48 hrs ago (172800 seconds == 48 hrs)
100
+ return ((time()-strtotime($timeOfLastTxn)) < 172800);
101
+ }
102
+
103
+ }
app/code/local/Litle/CreditCard/Block/Form/CreditCard.php ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Payment
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+
28
+ class Litle_CreditCard_Block_Form_CreditCard extends Mage_Payment_Block_Form
29
+ {
30
+ protected function _construct()
31
+ {
32
+ parent::_construct();
33
+ $this->setTemplate('payment/form/litlecc.phtml');
34
+ }
35
+
36
+ /**
37
+ * Retrieve payment configuration object
38
+ *
39
+ * @return Mage_Payment_Model_Config
40
+ */
41
+ protected function _getConfig()
42
+ {
43
+ return Mage::getSingleton('payment/config');
44
+ }
45
+
46
+ public function getCurrency()
47
+ {
48
+ return Mage::app()->getStore()->getCurrentCurrencyCode();
49
+ }
50
+
51
+ public function getMerchantIdMap()
52
+ {
53
+ return Mage::getStoreConfig('payment/CreditCard/merchant_id');
54
+ }
55
+
56
+ public function getReportGroup()
57
+ {
58
+ $string2Eval = 'return array' . $this->getMerchantIdMap() . ";";
59
+ $merchant_map = eval($string2Eval);
60
+ $reportGroup = $merchant_map[$this->getCurrency()];
61
+ return $reportGroup;
62
+ }
63
+
64
+ /**
65
+ * Retrieve availables credit card types
66
+ *
67
+ * @return array
68
+ */
69
+ public function getCcAvailableTypes()
70
+ {
71
+ $types = $this->_getConfig()->getCcTypes();
72
+ if ($method = $this->getMethod()) {
73
+ $availableTypes = $method->getConfigData('cctypes');
74
+ if ($availableTypes) {
75
+ $availableTypes = explode(',', $availableTypes);
76
+ foreach ($types as $code=>$name) {
77
+ if (!in_array($code, $availableTypes)) {
78
+ unset($types[$code]);
79
+ }
80
+ }
81
+ }
82
+ }
83
+ return $types;
84
+ }
85
+
86
+ /**
87
+ * Retrieve credit card expire months
88
+ *
89
+ * @return array
90
+ */
91
+ public function getCcMonths()
92
+ {
93
+ $months = $this->getData('cc_months');
94
+ if (is_null($months)) {
95
+ $months[0] = $this->__('Month');
96
+ $months = array_merge($months, $this->_getConfig()->getMonths());
97
+ $this->setData('cc_months', $months);
98
+ }
99
+ return $months;
100
+ }
101
+
102
+ /**
103
+ * Retrieve credit card expire years
104
+ *
105
+ * @return array
106
+ */
107
+ public function getCcYears()
108
+ {
109
+ $years = $this->getData('cc_years');
110
+ if (is_null($years)) {
111
+ $years = $this->_getConfig()->getYears();
112
+ $years = array(0=>$this->__('Year'))+$years;
113
+ $this->setData('cc_years', $years);
114
+ }
115
+ return $years;
116
+ }
117
+
118
+ /**
119
+ * Retrive has verification configuration
120
+ *
121
+ * @return boolean
122
+ */
123
+ public function hasVerification()
124
+ {
125
+ if ($this->getMethod()) {
126
+ $configData = $this->getMethod()->getConfigData('useccv');
127
+ if(is_null($configData)){
128
+ return true;
129
+ }
130
+ return (bool) $configData;
131
+ }
132
+ return true;
133
+ }
134
+
135
+ /*
136
+ * Whether switch/solo card type available
137
+ */
138
+ public function hasSsCardType()
139
+ {
140
+ $availableTypes = explode(',', $this->getMethod()->getConfigData('cctypes'));
141
+ $ssPresenations = array_intersect(array('SS', 'SM', 'SO'), $availableTypes);
142
+ if ($availableTypes && count($ssPresenations) > 0) {
143
+ return true;
144
+ }
145
+ return false;
146
+ }
147
+
148
+ /*
149
+ * solo/switch card start year
150
+ * @return array
151
+ */
152
+ public function getSsStartYears()
153
+ {
154
+ $years = array();
155
+ $first = date("Y");
156
+
157
+ for ($index=5; $index>=0; $index--) {
158
+ $year = $first - $index;
159
+ $years[$year] = $year;
160
+ }
161
+ $years = array(0=>$this->__('Year'))+$years;
162
+ return $years;
163
+ }
164
+
165
+ /**
166
+ * Render block HTML
167
+ *
168
+ * @return string
169
+ */
170
+ protected function _toHtml()
171
+ {
172
+ Mage::dispatchEvent('payment_form_block_to_html_before', array(
173
+ 'block' => $this
174
+ ));
175
+ return parent::_toHtml();
176
+ }
177
+ }
178
+
app/code/local/Litle/CreditCard/Helper/Data.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Litle_CreditCard_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ public function isStateOfOrderEqualTo($order, $inOrderState){
5
+ $payment = $order->getPayment();
6
+ $lastTxnId = $payment->getLastTransId();
7
+ $lastTxn = $payment->getTransaction($lastTxnId);
8
+
9
+ if( $lastTxn->getTxnType() === $inOrderState )
10
+ return true;
11
+ else
12
+ return false;
13
+ }
14
+
15
+ // TODO:: Needs to be implemented.
16
+ public function isMOPLitleCC($mop){
17
+ return ($mop === "creditcard");
18
+ }
19
+
20
+ // TODO:: Needs to be implemented.
21
+ public function isMOPLitleECheck($mop){
22
+ return ($mop === "lecheck");
23
+ }
24
+
25
+ public function isMOPLitle($payment){
26
+ $mop = $payment->getData('method');
27
+ return ($this->isMOPLitleCC($mop) || $this->isMOPLitleECheck($mop));
28
+ }
29
+
30
+ public function uniqueCreditCard($customerId) {
31
+ $collection = array();
32
+ $collection = Mage::getModel('palorus/vault')
33
+ ->getCollection()
34
+ ->addFieldToFilter('customer_id',$customerId);
35
+
36
+ $purchases = array();
37
+ $unique = array();
38
+ $i=0;
39
+ foreach ($collection as $purchase) {
40
+ $purchases[$i] = $purchase->getData();
41
+ $i++;
42
+ }
43
+
44
+ return $this->populateStoredCreditCard($purchases);
45
+ }
46
+
47
+ public function populateStoredCreditCard($purchases) {
48
+
49
+ $unique = array();
50
+ $unique[0] = $purchases[0];
51
+ for ($y=1; $y < count($purchases); $y++){
52
+ $setter = 0;
53
+ for ($x=0; $x <= count($unique); $x++){
54
+ if (($purchases[$y]['type'] === $unique[$x]['type']) && ($purchases[$y]['last4'] === $unique[$x]['last4']))
55
+ {
56
+ $setter = 1;
57
+ }
58
+ }
59
+ if ($setter === 0)
60
+ {
61
+ array_push($unique, $purchases[$y]);
62
+ }
63
+ }
64
+ return $unique;
65
+ }
66
+ }
app/code/local/Litle/CreditCard/Model/Cctypes.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Paygate
23
+ * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Authorizenet Payment CC Types Source Model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Paygate
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Litle_CreditCard_Model_Cctypes extends Mage_Payment_Model_Source_Cctype
35
+ {
36
+ public function getAllowedTypes()
37
+ {
38
+ return array('AE','MC','DI','JCB','DC','VI');
39
+ }
40
+
41
+
42
+
43
+ }
app/code/local/Litle/CreditCard/Model/Lpayment.php ADDED
@@ -0,0 +1,452 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Litle_CreditCard_Model_Lpayment extends Mage_Sales_Model_Order_Payment
4
+ {
5
+
6
+ /**
7
+ * Cancel specified invoice: update self totals from it
8
+ *
9
+ * @param Mage_Sales_Model_Order_Invoice $invoice
10
+ * @return Mage_Sales_Model_Order_Payment
11
+ */
12
+ public function cancelInvoice($invoice)
13
+ {
14
+ $this->_updateTotals(array(
15
+ 'amount_paid' => -1 * $invoice->getGrandTotal(),
16
+ 'base_amount_paid' => -1 * $invoice->getBaseGrandTotal(),
17
+ 'shipping_captured' => -1 * $invoice->getShippingAmount(),
18
+ 'base_shipping_captured' => -1 * $invoice->getBaseShippingAmount(),
19
+ ));
20
+ Mage::dispatchEvent('sales_order_payment_cancel_invoice', array('payment' => $this, 'invoice' => $invoice));
21
+ return $this;
22
+ }
23
+
24
+ /**
25
+ * Void payment online
26
+ *
27
+ * @see self::_void()
28
+ * @param Varien_Object $document
29
+ * @return Mage_Sales_Model_Order_Payment
30
+ */
31
+ public function void(Varien_Object $document)
32
+ {
33
+ $this->_void(true);
34
+ Mage::dispatchEvent('sales_order_payment_void', array('payment' => $this, 'invoice' => $document));
35
+ return $this;
36
+ }
37
+
38
+ /**
39
+ * Cancel a creditmemo: substract its totals from the payment
40
+ *
41
+ * @param Mage_Sales_Model_Order_Creditmemo $creditmemo
42
+ * @return Mage_Sales_Model_Order_Payment
43
+ */
44
+ public function cancelCreditmemo($creditmemo)
45
+ {
46
+ $this->_updateTotals(array(
47
+ 'amount_refunded' => -1 * $creditmemo->getGrandTotal(),
48
+ 'base_amount_refunded' => -1 * $creditmemo->getBaseGrandTotal(),
49
+ 'shipping_refunded' => -1 * $creditmemo->getShippingAmount(),
50
+ 'base_shipping_refunded' => -1 * $creditmemo->getBaseShippingAmount()
51
+ ));
52
+ Mage::dispatchEvent('sales_order_payment_cancel_creditmemo',
53
+ array('payment' => $this, 'creditmemo' => $creditmemo)
54
+ );
55
+ return $this;
56
+ }
57
+
58
+ /**
59
+ * Order cancellation hook for payment method instance
60
+ * Adds void transaction if needed
61
+ * @return Mage_Sales_Model_Order_Payment
62
+ */
63
+ public function cancel()
64
+ {
65
+ $isOnline = true;
66
+ if (!$this->canVoid(new Varien_Object())) {
67
+ $isOnline = false;
68
+ }
69
+
70
+ if (!$this->hasMessage()) {
71
+ $this->setMessage($isOnline ? Mage::helper('sales')->__('Canceled order online.')
72
+ : Mage::helper('sales')->__('Canceled order offline.')
73
+ );
74
+ }
75
+
76
+ if ($isOnline) {
77
+ $this->_void($isOnline, null, 'cancel');
78
+ }
79
+
80
+ Mage::dispatchEvent('sales_order_payment_cancel', array('payment' => $this));
81
+
82
+ return $this;
83
+ }
84
+
85
+ /**
86
+ * Authorize payment either online or offline (process auth notification)
87
+ * Updates transactions hierarchy, if required
88
+ * Prevents transaction double processing
89
+ * Updates payment totals, updates order status and adds proper comments
90
+ *
91
+ * @param bool $isOnline
92
+ * @param float $amount
93
+ * @return Mage_Sales_Model_Order_Payment
94
+ */
95
+ protected function _authorize($isOnline, $amount)
96
+ {
97
+ // update totals
98
+ $amount = $this->_formatAmount($amount, true);
99
+ $this->setBaseAmountAuthorized($amount);
100
+
101
+ // do authorization
102
+ $order = $this->getOrder();
103
+ $state = Mage_Sales_Model_Order::STATE_PROCESSING;
104
+ $status = true;
105
+ if ($isOnline) {
106
+ // invoke authorization on gateway
107
+ $this->getMethodInstance()->setStore($order->getStoreId())->authorize($this, $amount);
108
+ } else {
109
+ $message = Mage::helper('sales')->__(
110
+ 'Registered notification about authorized amount of %s.',
111
+ $this->_formatPrice($amount)
112
+ );
113
+ }
114
+
115
+ // similar logic of "payment review" order as in capturing
116
+ if ($this->getIsTransactionPending()) {
117
+ $message = Mage::helper('sales')->__('Authorizing amount of %s is pending approval on gateway.', $this->_formatPrice($amount));
118
+ $state = Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW;
119
+ if ($this->getIsFraudDetected()) {
120
+ $status = Mage_Sales_Model_Order::STATUS_FRAUD;
121
+ }
122
+ } else {
123
+ $message = Mage::helper('sales')->__('Authorized amount of %s.', $this->_formatPrice($amount));
124
+ }
125
+
126
+ // update transactions, order state and add comments
127
+ $transaction = $this->_addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH);
128
+ if ($order->isNominal()) {
129
+ $message = $this->_prependMessage(Mage::helper('sales')->__('Nominal order registered.'));
130
+ } else {
131
+ $message = $this->_prependMessage($message);
132
+ $message = $this->_appendTransactionToMessage($transaction, $message);
133
+ }
134
+ $order->setState($state, $status, $message);
135
+
136
+ return $this;
137
+ }
138
+
139
+ /**
140
+ * Public access to _authorize method
141
+ * @param bool $isOnline
142
+ * @param float $amount
143
+ */
144
+ public function authorize($isOnline, $amount)
145
+ {
146
+ return $this->_authorize($isOnline, $amount);
147
+ }
148
+
149
+ /**
150
+ * Void payment either online or offline (process void notification)
151
+ * NOTE: that in some cases authorization can be voided after a capture. In such case it makes sense to use
152
+ * the amount void amount, for informational purposes.
153
+ * Updates payment totals, updates order status and adds proper comments
154
+ *
155
+ * @param bool $isOnline
156
+ * @param float $amount
157
+ * @param string $gatewayCallback
158
+ * @return Mage_Sales_Model_Order_Payment
159
+ */
160
+ protected function _void($isOnline, $amount = null, $gatewayCallback = 'void')
161
+ {
162
+ $order = $this->getOrder();
163
+ $authTransaction = $this->getAuthorizationTransaction();
164
+ $this->_generateTransactionId(Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID, $authTransaction);
165
+ $this->setShouldCloseParentTransaction(true);
166
+
167
+ // attempt to void
168
+ if ($isOnline) {
169
+ $this->getMethodInstance()->setStore($order->getStoreId())->$gatewayCallback($this);
170
+ }
171
+ if ($this->_isTransactionExists()) {
172
+ return $this;
173
+ }
174
+
175
+ // if the authorization was untouched, we may assume voided amount = order grand total
176
+ // but only if the payment auth amount equals to order grand total
177
+ if ($authTransaction && ($order->getBaseGrandTotal() == $this->getBaseAmountAuthorized())
178
+ && (0 == $this->getBaseAmountCanceled())) {
179
+ if ($authTransaction->canVoidAuthorizationCompletely()) {
180
+ $amount = (float)$order->getBaseGrandTotal();
181
+ }
182
+ }
183
+
184
+ if ($amount) {
185
+ $amount = $this->_formatAmount($amount);
186
+ }
187
+
188
+ // update transactions, order state and add comments
189
+ $transaction = $this->_addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID, null, true);
190
+ if(true) //if voided transaction was a refund
191
+ $message = $this->hasMessage() ? $this->getMessage() : Mage::helper('sales')->__('Voided refund.');
192
+ else //if voided transaction was an auth
193
+ $message = $this->hasMessage() ? $this->getMessage() : Mage::helper('sales')->__('Voided authorization.');
194
+ $message = $this->_prependMessage($message);
195
+ if ($amount) {
196
+ $message .= ' ' . Mage::helper('sales')->__('Amount: %s.', $this->_formatPrice($amount));
197
+ }
198
+ $message = $this->_appendTransactionToMessage($transaction, $message);
199
+ $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, $message);
200
+ return $this;
201
+ }
202
+
203
+ // /**
204
+ // * TODO: implement this
205
+ // * @param Mage_Sales_Model_Order_Invoice $invoice
206
+ // * @return Mage_Sales_Model_Order_Payment
207
+ // */
208
+ // public function cancelCapture($invoice = null)
209
+ // {
210
+ // }
211
+
212
+ /**
213
+ * Create transaction,
214
+ * prepare its insertion into hierarchy and add its information to payment and comments
215
+ *
216
+ * To add transactions and related information,
217
+ * the following information should be set to payment before processing:
218
+ * - transaction_id
219
+ * - is_transaction_closed (optional) - whether transaction should be closed or open (closed by default)
220
+ * - parent_transaction_id (optional)
221
+ * - should_close_parent_transaction (optional) - whether to close parent transaction (closed by default)
222
+ *
223
+ * If the sales document is specified, it will be linked to the transaction as related for future usage.
224
+ * Currently transaction ID is set into the sales object
225
+ * This method writes the added transaction ID into last_trans_id field of the payment object
226
+ *
227
+ * To make sure transaction object won't cause trouble before saving, use $failsafe = true
228
+ *
229
+ * @param string $type
230
+ * @param Mage_Sales_Model_Abstract $salesDocument
231
+ * @param bool $failsafe
232
+ * @return null|Mage_Sales_Model_Order_Payment_Transaction
233
+ */
234
+ protected function _addTransaction($type, $salesDocument = null, $failsafe = false)
235
+ {
236
+ if ($this->getSkipTransactionCreation()) {
237
+ $this->unsTransactionId();
238
+ return null;
239
+ }
240
+
241
+ // look for set transaction ids
242
+ $transactionId = $this->getTransactionId();
243
+ if (null !== $transactionId) {
244
+ // set transaction parameters
245
+ $transaction = false;
246
+ if ($this->getOrder()->getId()) {
247
+ $transaction = $this->_lookupTransaction($transactionId);
248
+ }
249
+ if (!$transaction) {
250
+ $transaction = Mage::getModel('sales/order_payment_transaction')->setTxnId($transactionId);
251
+ }
252
+ $transaction
253
+ ->setOrderPaymentObject($this)
254
+ ->setTxnType($type)
255
+ ->isFailsafe($failsafe);
256
+
257
+ if ($this->hasIsTransactionClosed()) {
258
+ $transaction->setIsClosed((int)$this->getIsTransactionClosed());
259
+ }
260
+
261
+ //set transaction addition information
262
+ if ($this->_transactionAdditionalInfo) {
263
+ foreach ($this->_transactionAdditionalInfo as $key => $value) {
264
+ $transaction->setAdditionalInformation($key, $value);
265
+ }
266
+ }
267
+
268
+ // link with sales entities
269
+ $this->setLastTransId($transactionId);
270
+ $this->setCreatedTransaction($transaction);
271
+ $this->getOrder()->addRelatedObject($transaction);
272
+ if ($salesDocument && $salesDocument instanceof Mage_Sales_Model_Abstract) {
273
+ $salesDocument->setTransactionId($transactionId);
274
+ // TODO: linking transaction with the sales document
275
+ }
276
+
277
+ // link with parent transaction
278
+ $parentTransactionId = $this->getParentTransactionId();
279
+
280
+ if ($parentTransactionId) {
281
+ $transaction->setParentTxnId($parentTransactionId);
282
+ if ($this->getShouldCloseParentTransaction()) {
283
+ $parentTransaction = $this->_lookupTransaction($parentTransactionId);
284
+ if ($parentTransaction) {
285
+ if (!$parentTransaction->getIsClosed()) {
286
+ $parentTransaction->isFailsafe($failsafe)->close(false);
287
+ }
288
+ $this->getOrder()->addRelatedObject($parentTransaction);
289
+ }
290
+ }
291
+ }
292
+ return $transaction;
293
+ }
294
+ }
295
+
296
+ /**
297
+ * Public acces to _addTransaction method
298
+ *
299
+ * @param string $type
300
+ * @param Mage_Sales_Model_Abstract $salesDocument
301
+ * @param bool $failsafe
302
+ * @param string $message
303
+ * @return null|Mage_Sales_Model_Order_Payment_Transaction
304
+ */
305
+ public function addTransaction($type, $salesDocument = null, $failsafe = false, $message = false)
306
+ {
307
+ $transaction = $this->_addTransaction($type, $salesDocument, $failsafe);
308
+
309
+ if ($message) {
310
+ $order = $this->getOrder();
311
+ $message = $this->_appendTransactionToMessage($transaction, $message);
312
+ $order->addStatusHistoryComment($message);
313
+ }
314
+
315
+ return $transaction;
316
+ }
317
+
318
+ /**
319
+ * Import details data of specified transaction
320
+ *
321
+ * @param Mage_Sales_Model_Order_Payment_Transaction $transactionTo
322
+ * @return Mage_Sales_Model_Order_Payment
323
+ */
324
+ public function importTransactionInfo(Mage_Sales_Model_Order_Payment_Transaction $transactionTo)
325
+ {
326
+ $data = $this->getMethodInstance()
327
+ ->setStore($this->getOrder()->getStoreId())
328
+ ->fetchTransactionInfo($this, $transactionTo->getTxnId());
329
+ if ($data) {
330
+ $transactionTo->setAdditionalInformation(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, $data);
331
+ }
332
+ return $this;
333
+ }
334
+
335
+
336
+ /**
337
+ * Append transaction ID (if any) message to the specified message
338
+ *
339
+ * @param Mage_Sales_Model_Order_Payment_Transaction|null $transaction
340
+ * @param string $message
341
+ * @return string
342
+ */
343
+ protected function _appendTransactionToMessage($transaction, $message)
344
+ {
345
+ if ($transaction) {
346
+ $txnId = is_object($transaction) ? $transaction->getTxnId() : $transaction;
347
+ $message .= ' ' . Mage::helper('sales')->__('Transaction ID: "%s".', $txnId);
348
+ }
349
+ return $message;
350
+ }
351
+
352
+ /**
353
+ * Lookup an authorization transaction using parent transaction id, if set
354
+ * @return Mage_Sales_Model_Order_Payment_Transaction|false
355
+ */
356
+ public function getAuthorizationTransaction()
357
+ {
358
+ if ($this->getParentTransactionId()) {
359
+ $txn = $this->_lookupTransaction($this->getParentTransactionId());
360
+ } else {
361
+ $txn = false;
362
+ }
363
+
364
+ if (!$txn) {
365
+ $txn = $this->_lookupTransaction(false, Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH);
366
+ }
367
+ return $txn;
368
+ }
369
+
370
+ /**
371
+ * Update transaction ids for further processing
372
+ * If no transactions were set before invoking, may generate an "offline" transaction id
373
+ *
374
+ * @param string $type
375
+ * @param Mage_Sales_Model_Order_Payment_Transaction $transactionBasedOn
376
+ */
377
+ protected function _generateTransactionId($type, $transactionBasedOn = false)
378
+ {
379
+ if (!$this->getParentTransactionId() && !$this->getTransactionId() && $transactionBasedOn) {
380
+ $this->setParentTransactionId($transactionBasedOn->getTxnId());
381
+ }
382
+ // generate transaction id for an offline action or payment method that didn't set it
383
+ if (($parentTxnId = $this->getParentTransactionId()) && !$this->getTransactionId()) {
384
+ $this->setTransactionId("{$parentTxnId}-{$type}");
385
+ }
386
+ }
387
+
388
+ /**
389
+ * Additionnal transaction info setter
390
+ *
391
+ * @param sting $key
392
+ * @param string $value
393
+ */
394
+ public function setTransactionAdditionalInfo($key, $value)
395
+ {
396
+ if (is_array($key)) {
397
+ $this->_transactionAdditionalInfo = $key;
398
+ } else {
399
+ $this->_transactionAdditionalInfo[$key] = $value;
400
+ }
401
+ }
402
+
403
+ /**
404
+ * Additionnal transaction info getter
405
+ *
406
+ * @param sting $key
407
+ * @return mixed
408
+ */
409
+ public function getTransactionAdditionalInfo($key = null)
410
+ {
411
+ if (is_null($key)) {
412
+ return $this->_transactionAdditionalInfo;
413
+ }
414
+ return isset($this->_transactionAdditionalInfo[$key]) ? $this->_transactionAdditionalInfo[$key] : null;
415
+ }
416
+
417
+ /**
418
+ * Reset transaction additional info property
419
+ *
420
+ * @return Mage_Sales_Model_Order_Payment
421
+ */
422
+ public function resetTransactionAdditionalInfo()
423
+ {
424
+ $this->_transactionAdditionalInfo = array();
425
+ return $this;
426
+ }
427
+
428
+ /**
429
+ * Return invoice model for transaction
430
+ *
431
+ * @param string $transactionId
432
+ * @return Mage_Sales_Model_Order_Invoice
433
+ */
434
+ protected function _getInvoiceForTransactionId($transactionId)
435
+ {
436
+ foreach ($this->getOrder()->getInvoiceCollection() as $invoice) {
437
+ if ($invoice->getTransactionId() == $transactionId) {
438
+ $invoice->load($invoice->getId()); // to make sure all data will properly load (maybe not required)
439
+ return $invoice;
440
+ }
441
+ }
442
+ foreach ($this->getOrder()->getInvoiceCollection() as $invoice) {
443
+ if ($invoice->getState() == Mage_Sales_Model_Order_Invoice::STATE_OPEN
444
+ && $invoice->load($invoice->getId())
445
+ ) {
446
+ $invoice->setTransactionId($transactionId);
447
+ return $invoice;
448
+ }
449
+ }
450
+ return false;
451
+ }
452
+ }
app/code/local/Litle/CreditCard/Model/Order/Payment.php ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Litle_CreditCard_Model_Order_Payment extends Mage_Sales_Model_Order_Payment
4
+ {
5
+ // /**
6
+ // * Cancel a creditmemo: substract its totals from the payment
7
+ // *
8
+ // * @param Mage_Sales_Model_Order_Creditmemo $creditmemo
9
+ // * @return Mage_Sales_Model_Order_Payment
10
+ // */
11
+ // public function cancelCreditmemo($creditmemo)
12
+ // {
13
+ // $this->_updateTotals(array(
14
+ // 'amount_refunded' => -1 * $creditmemo->getGrandTotal(),
15
+ // 'base_amount_refunded' => -1 * $creditmemo->getBaseGrandTotal(),
16
+ // 'shipping_refunded' => -1 * $creditmemo->getShippingAmount(),
17
+ // 'base_shipping_refunded' => -1 * $creditmemo->getBaseShippingAmount()
18
+ // ));
19
+ // Mage::dispatchEvent('sales_order_payment_cancel_creditmemo',
20
+ // array('payment' => $this, 'creditmemo' => $creditmemo)
21
+ // );
22
+ // return $this;
23
+ // }
24
+
25
+ protected function _reverseRefund($isOnline, $amount = null, $gatewayCallback = 'void')
26
+ {
27
+ $order = $this->getOrder();
28
+ // attempt to void
29
+ if ($isOnline) {
30
+ $this->getMethodInstance()->setStore($order->getStoreId())->$gatewayCallback($this);
31
+ }
32
+ if ($this->_isTransactionExists()) {
33
+ return $this;
34
+ }
35
+
36
+ foreach($order->getItemsCollection() as $item){
37
+ if ($item->getQtyRefunded() > 0)
38
+ $item->setQtyRefunded(0)->save();
39
+ }
40
+
41
+ $order
42
+ ->setBaseDiscountRefunded(0)
43
+ ->setBaseShippingRefunded(0)
44
+ ->setBaseSubtotalRefunded(0)
45
+ ->setBaseTaxRefunded(0)
46
+ ->setBaseShippingTaxRefunded(0)
47
+ ->setBaseTotalOnlineRefunded(0)
48
+ ->setBaseTotalOfflineRefunded(0)
49
+ ->setBaseTotalRefunded(0)
50
+ ->setTotalOnlineRefunded(0)
51
+ ->setTotalOfflineRefunded(0)
52
+ ->setDiscountRefunded(0)
53
+ ->setShippingRefunded(0)
54
+ ->setShippingTaxRefunded(0)
55
+ ->setSubtotalRefunded(0)
56
+ ->setTaxRefunded(0)
57
+ ->setTotalRefunded(0)->save();
58
+
59
+ // update transactions, order state and add comments
60
+ $transaction = $this->_addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID, null, true);
61
+ $message = $this->hasMessage() ? $this->getMessage() : "Voided Refund.";
62
+ $message = $this->_prependMessage($message);
63
+ $message = $this->_appendTransactionToMessage($transaction, $message);
64
+ $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, $message);
65
+ }
66
+
67
+ protected function _voidCapture($isOnline, $amount = null, $gatewayCallback = 'void')
68
+ {
69
+ $order = $this->getOrder();
70
+ // attempt to void
71
+ if ($isOnline) {
72
+ $this->getMethodInstance()->setStore($order->getStoreId())->$gatewayCallback($this);
73
+ }
74
+ if ($this->_isTransactionExists()) {
75
+ return $this;
76
+ }
77
+
78
+ foreach($order->getItemsCollection() as $orderItem){
79
+ $orderItem->setQtyInvoiced(0);
80
+ $orderItem->setTaxInvoiced(0);
81
+ $orderItem->setBaseTaxInvoiced(0);
82
+ $orderItem->setHiddenTaxInvoiced(0);
83
+ $orderItem->setBaseHiddenTaxInvoiced(0);
84
+
85
+ $orderItem->setDiscountInvoiced(0);
86
+ $orderItem->setBaseDiscountInvoiced(0);
87
+
88
+ $orderItem->setRowInvoiced(0);
89
+ $orderItem->setBaseRowInvoiced(0);
90
+ }
91
+
92
+ $order
93
+ ->setBaseDiscountInvoiced(0)
94
+ ->setBaseShippingInvoiced(0)
95
+ ->setBaseSubtotalInvoiced(0)
96
+ ->setBaseTaxInvoiced(0)
97
+ ->setBaseTotalInvoiced(0)
98
+ ->setBaseTotalInvoicedCost(0)
99
+ ->setDiscountInvoiced(0)
100
+ ->setShippingInvoiced(0)
101
+ ->setSubtotalInvoiced(0)
102
+ ->setTaxInvoiced(0)
103
+ ->setTotalInvoiced(0)
104
+ ->setHiddenTaxInvoiced(0)
105
+ ->setBaseHiddenTaxInvoiced(0)
106
+ ->setShippingTaxInvoiced(0)
107
+ ->setBaseShippingTaxInvoiced(0)
108
+ ->setTotalPaid(0)
109
+ ->setBaseTotalPaid(0);
110
+
111
+ $this->setBaseShippingCaptured(0);
112
+ $this->setShippingCaptured(0);
113
+ $this->setAmountPaid(0);
114
+ $this->setBaseAmountPaid(0);
115
+ $this->setBaseAmountPaidOnline(0);
116
+
117
+ $order->setBaseGrandTotal($order->getGrandTotal());
118
+
119
+ foreach ($order->getInvoiceCollection() as $invoice) {
120
+ $invoice->setState("3")->save(); //3 means cancelled
121
+ }
122
+
123
+
124
+
125
+ // update transactions, order state and add comments
126
+ $transaction = $this->_addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH, null, true);
127
+ $message = $this->hasMessage() ? $this->getMessage() : "Voided Capture.";
128
+ $message = $this->_prependMessage($message);
129
+ $message = $this->_appendTransactionToMessage($transaction, $message);
130
+ $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, $message);
131
+ }
132
+
133
+
134
+ /**
135
+ * Void payment either online or offline (process void notification)
136
+ * NOTE: that in some cases authorization can be voided after a capture. In such case it makes sense to use
137
+ * the amount void amount, for informational purposes.
138
+ * Updates payment totals, updates order status and adds proper comments
139
+ *
140
+ * @param bool $isOnline
141
+ * @param float $amount
142
+ * @param string $gatewayCallback
143
+ * @return Mage_Sales_Model_Order_Payment
144
+ */
145
+ protected function _void($isOnline, $amount = null, $gatewayCallback = 'void')
146
+ {
147
+ if(Mage::helper("creditcard")->isMOPLitle($this))
148
+ {
149
+ $order = $this->getOrder();
150
+ if(Mage::helper("creditcard")->isStateOfOrderEqualTo($order, Mage_Sales_Model_Order_Payment_Transaction::TYPE_REFUND))
151
+ {
152
+ $this->_reverseRefund($isOnline, $amount, $gatewayCallback);
153
+ } else if(Mage::helper("creditcard")->isStateOfOrderEqualTo($order, Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH)){
154
+ parent::_void($isOnline, $amount, $gatewayCallback);
155
+ } else if(Mage::helper("creditcard")->isStateOfOrderEqualTo($order, Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE)){
156
+ $this->_voidCapture($isOnline, $amount, $gatewayCallback);
157
+ } else {
158
+ parent::_void($isOnline, $amount, $gatewayCallback);
159
+ }
160
+ } else {
161
+ parent::_void($isOnline, $amount, $gatewayCallback);
162
+ }
163
+
164
+ return $this;
165
+ }
166
+ }
app/code/local/Litle/CreditCard/Model/PaymentLogic.php CHANGED
@@ -8,6 +8,7 @@ class Litle_CreditCard_Model_PaymentLogic extends Mage_Payment_Model_Method_Cc
8
  */
9
  protected $_code = 'creditcard';
10
 
 
11
  /**
12
  * this should probably be true if you're using this
13
  * method to take payments
@@ -61,7 +62,6 @@ class Litle_CreditCard_Model_PaymentLogic extends Mage_Payment_Model_Method_Cc
61
  */
62
  protected $_canSaveCc = false;
63
 
64
-
65
  public function getConfigData($fieldToLookFor, $store = NULL)
66
  {
67
  $returnFromThisModel = Mage::getStoreConfig('payment/CreditCard/' . $fieldToLookFor);
@@ -71,10 +71,59 @@ class Litle_CreditCard_Model_PaymentLogic extends Mage_Payment_Model_Method_Cc
71
  return $returnFromThisModel;
72
  }
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  public function getCreditCardInfo(Varien_Object $payment)
75
  {
76
  $retArray = array();
77
- $retArray["type"] = ($payment->getCcType() == "AE")? "AX" : $payment->getCcType();
78
  $retArray["number"] = $payment->getCcNumber();
79
  preg_match("/\d\d(\d\d)/", $payment->getCcExpYear(), $expYear);
80
  $retArray["expDate"] = sprintf('%02d%02d', $payment->getCcExpMonth(), $expYear[1]);
@@ -83,6 +132,52 @@ class Litle_CreditCard_Model_PaymentLogic extends Mage_Payment_Model_Method_Cc
83
  return $retArray;
84
  }
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  public function getContactInformation($contactInfo)
87
  {
88
  if(!empty($contactInfo)){
@@ -129,13 +224,38 @@ class Litle_CreditCard_Model_PaymentLogic extends Mage_Payment_Model_Method_Cc
129
  return NULL;
130
  }
131
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  public function merchantData(Varien_Object $payment)
133
  {
 
134
  $hash = array('user'=> $this->getConfigData("user"),
135
  'password'=> $this->getConfigData("password"),
136
- 'merchantId'=>$this->getConfigData("merchant_id"),
137
  'version'=>'8.10',
138
- 'reportGroup'=>$this->getConfigData("reportGroup"),
 
 
139
  'url'=>$this->getConfigData("url"),
140
  'proxy'=>$this->getConfigData("proxy"),
141
  'timeout'=>$this->getConfigData("timeout")
@@ -143,7 +263,147 @@ class Litle_CreditCard_Model_PaymentLogic extends Mage_Payment_Model_Method_Cc
143
  return $hash;
144
  }
145
 
146
- public function processResponse(Varien_Object $payment,$litleResponse){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  $message = XmlParser::getAttribute($litleResponse,'litleOnlineResponse','message');
148
  if ($message == "Valid Format"){
149
  $isSale = ($payment->getCcTransId() != NULL)? FALSE : TRUE;
@@ -152,18 +412,26 @@ public function processResponse(Varien_Object $payment,$litleResponse){
152
  $litleResponseCode = XMLParser::getNode($litleResponse,'response');
153
  if($litleResponseCode != "000")
154
  {
155
- $payment
156
- ->setStatus("Rejected")
157
- ->setCcTransId(XMLParser::getNode($litleResponse,'litleTxnId'))
158
- ->setLastTransId(XMLParser::getNode($litleResponse,'litleTxnId'))
159
- ->setTransactionId(XMLParser::getNode($litleResponse,'litleTxnId'))
160
- ->setIsTransactionClosed(0)
161
- ->setTransactionAdditionalInfo("additional_information", XMLParser::getNode($litleResponse,'message'));
162
-
163
- if($isSale)
164
- throw new Mage_Payment_Model_Info_Exception(Mage::helper('core')->__("Transaction was not approved. Contact us or try again later."));
165
  else
166
- throw new Mage_Payment_Model_Info_Exception(Mage::helper('core')->__("Transaction was not approved. Contact Litle or try again later."));
 
 
 
 
 
 
 
 
 
 
 
 
 
167
  }
168
  else
169
  {
@@ -174,13 +442,16 @@ public function processResponse(Varien_Object $payment,$litleResponse){
174
  ->setTransactionId(XMLParser::getNode($litleResponse,'litleTxnId'))
175
  ->setIsTransactionClosed(0)
176
  ->setTransactionAdditionalInfo("additional_information", XMLParser::getNode($litleResponse,'message'));
 
177
  }
178
- return $this;
179
  }
180
  }
181
  else{
182
  Mage::throwException($message);
183
  }
 
 
184
  }
185
  /**
186
  * this method is called if we are just authorising
@@ -188,24 +459,41 @@ public function processResponse(Varien_Object $payment,$litleResponse){
188
  */
189
  public function authorize(Varien_Object $payment, $amount)
190
  {
191
- $order = $payment->getOrder();
192
- $orderId = $order->getIncrementId();
193
- $amountToPass = ($amount* 100);
194
-
195
- if (!empty($order)){
196
- $hash = array(
197
- 'orderId'=> $orderId,
198
- 'amount'=> $amountToPass,
199
- 'orderSource'=> "ecommerce",
200
- 'billToAddress'=> $this->getBillToAddress($payment),
201
- 'shipToAddress'=> $this->getAddressInfo($payment),
202
- 'card'=> $this->getCreditCardInfo($payment)
203
- );
204
- $merchantData = $this->merchantData($payment);
205
- $hash_in = array_merge($hash,$merchantData);
206
- $litleRequest = new LitleOnlineRequest();
207
- $litleResponse = $litleRequest->authorizationRequest($hash_in);
208
- $this->processResponse($payment,$litleResponse);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209
  }
210
  }
211
 
@@ -215,39 +503,56 @@ public function processResponse(Varien_Object $payment,$litleResponse){
215
  */
216
  public function capture (Varien_Object $payment, $amount)
217
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
  $order = $payment->getOrder();
219
  if (!empty($order)){
220
-
221
  $orderId =$order->getIncrementId();
222
  $amountToPass = ($amount* 100);
223
  $isPartialCapture = ($amount < $order->getGrandTotal()) ? "true" : "false";
224
  $isSale = ($payment->getCcTransId() != NULL)? FALSE : TRUE;
225
-
226
  if( !$isSale )
227
  {
228
  $hash = array(
229
- 'litleTxnId' => $payment->getParentTransactionId(),//getCcTransId(),
230
  'amount' => $amountToPass,
231
  'partial' => $isPartialCapture
232
  );
233
  } else {
234
- $hash = array(
235
  'orderId'=> $orderId,
236
  'amount'=> $amountToPass,
237
  'orderSource'=> "ecommerce",
238
  'billToAddress'=> $this->getBillToAddress($payment),
239
  'shipToAddress'=> $this->getAddressInfo($payment),
240
- 'card'=> $this->getCreditCardInfo($payment)
241
  );
 
 
242
  }
243
-
244
  $merchantData = $this->merchantData($payment);
245
  $hash_in = array_merge($hash,$merchantData);
246
  $litleRequest = new LitleOnlineRequest();
247
-
248
  if( $isSale )
249
  {
250
  $litleResponse = $litleRequest->saleRequest($hash_in);
 
 
251
  } else {
252
  $litleResponse = $litleRequest->captureRequest($hash_in);
253
  }
@@ -260,19 +565,24 @@ public function processResponse(Varien_Object $payment,$litleResponse){
260
  */
261
  public function refund (Varien_Object $payment, $amount)
262
  {
 
 
263
  $order = $payment->getOrder();
264
- $amountToPass = ($amount* 100);
265
- if (!empty($order)){
266
- $hash = array(
267
- 'litleTxnId' => $payment->getCcTransId(),
268
- 'amount' => $amountToPass
269
- );
270
- $merchantData = $this->merchantData($payment);
271
- $hash_in = array_merge($hash,$merchantData);
272
- $litleRequest = new LitleOnlineRequest();
273
- $litleResponse = $litleRequest->creditRequest($hash_in);
274
- }
275
- $this->processResponse($payment,$litleResponse);
 
 
 
276
  return $this;
277
  }
278
 
@@ -281,6 +591,8 @@ public function processResponse(Varien_Object $payment,$litleResponse){
281
  */
282
  public function void (Varien_Object $payment)
283
  {
 
 
284
  $order = $payment->getOrder();
285
  if (!empty($order)){
286
  $hash = array(
@@ -289,8 +601,19 @@ public function processResponse(Varien_Object $payment,$litleResponse){
289
  $merchantData = $this->merchantData($payment);
290
  $hash_in = array_merge($hash,$merchantData);
291
  $litleRequest = new LitleOnlineRequest();
292
- $litleResponse = $litleRequest->voidRequest($hash_in);
 
 
 
 
 
293
  }
294
  $this->processResponse($payment,$litleResponse);
295
  }
 
 
 
 
 
 
296
  }
8
  */
9
  protected $_code = 'creditcard';
10
 
11
+ protected $_formBlockType = 'creditcard/form_creditCard';
12
  /**
13
  * this should probably be true if you're using this
14
  * method to take payments
62
  */
63
  protected $_canSaveCc = false;
64
 
 
65
  public function getConfigData($fieldToLookFor, $store = NULL)
66
  {
67
  $returnFromThisModel = Mage::getStoreConfig('payment/CreditCard/' . $fieldToLookFor);
71
  return $returnFromThisModel;
72
  }
73
 
74
+ public function isFromVT($payment, $txnType)
75
+ {
76
+ $parentTxnId = $payment->getParentTransactionId();
77
+ if( $parentTxnId == "Litle VT" )
78
+ {
79
+ Mage::throwException("This order was placed using Litle Virtual Terminal. Please process the $txnType by logging into Litle Virtual Terminal (https://vt.litle.com).");
80
+ }
81
+ }
82
+
83
+ public function assignData($data)
84
+ {
85
+ if( $this->getConfigData('paypage_enabled') == "1")
86
+ {
87
+ if (!($data instanceof Varien_Object)) {
88
+ $data = new Varien_Object($data);
89
+ }
90
+
91
+ $info = $this->getInfoInstance();
92
+ $info->setAdditionalInformation('paypage_enabled', $data->getPaypageEnabled());
93
+ $info->setAdditionalInformation('paypage_registration_id', $data->getPaypageRegistrationId());
94
+ $info->setAdditionalInformation('paypage_order_id', $data->getOrderId());
95
+ $info->setAdditionalInformation('cc_vaulted', $data->getCcVaulted());
96
+ }
97
+ return parent::assignData($data);
98
+ }
99
+
100
+
101
+
102
+ public function validate()
103
+ {
104
+ //no cc validation required.
105
+ return $this;
106
+ }
107
+
108
+ public function litleCcTypeEnum(Varien_Object $payment)
109
+ {
110
+ $typeEnum = "";
111
+ if ($payment->getCcType() == "AE"){
112
+ $typeEnum = "AX";
113
+ }
114
+ elseif ($payment->getCcType() == "JCB"){
115
+ $typeEnum = "JC";
116
+ }
117
+ else{
118
+ $typeEnum =$payment->getCcType();
119
+ }
120
+ return $typeEnum;
121
+ }
122
+
123
  public function getCreditCardInfo(Varien_Object $payment)
124
  {
125
  $retArray = array();
126
+ $retArray["type"] = $this->litleCcTypeEnum($payment);
127
  $retArray["number"] = $payment->getCcNumber();
128
  preg_match("/\d\d(\d\d)/", $payment->getCcExpYear(), $expYear);
129
  $retArray["expDate"] = sprintf('%02d%02d', $payment->getCcExpMonth(), $expYear[1]);
132
  return $retArray;
133
  }
134
 
135
+ public function getPaypageInfo($payment)
136
+ {
137
+ $info = $this->getInfoInstance();
138
+
139
+ $retArray = array();
140
+ $retArray["type"] = $this->litleCcTypeEnum($payment);
141
+ $retArray["paypageRegistrationId"] = $info->getAdditionalInformation('paypage_registration_id');
142
+ preg_match("/\d\d(\d\d)/", $payment->getCcExpYear(), $expYear);
143
+ $retArray["expDate"] = sprintf('%02d%02d', $payment->getCcExpMonth(), $expYear[1]);
144
+ $retArray["cardValidationNum"] = $payment->getCcCid();
145
+
146
+ return $retArray;
147
+ }
148
+
149
+ public function getTokenInfo($payment)
150
+ {
151
+ $info = $this->getInfoInstance();
152
+
153
+ $vaultIndex = $info->getAdditionalInformation('cc_vaulted');
154
+ $purchases = Mage::helper('creditcard')->uniqueCreditCard(Mage::helper('customer')->getCustomer()->getEntityId());
155
+
156
+ $retArray = array();
157
+ $retArray["type"] = $purchases[$vaultIndex - 1]['type'];
158
+ $retArray["litleToken"] = $purchases[$vaultIndex - 1]['token'];
159
+ $retArray["cardValidationNum"] = $payment->getCcCid();
160
+ $payment->setCcLast4(substr($retArray["litleToken"], -4));
161
+ $payment->setCcType($retArray["type"]);
162
+ return $retArray;
163
+ }
164
+
165
+ public function creditCardOrPaypageOrToken($payment){
166
+ $info = $this->getInfoInstance();
167
+ $vaultIndex = $info->getAdditionalInformation('cc_vaulted');
168
+ $payment_hash = array();
169
+ if ($vaultIndex > 0){
170
+ $payment_hash['token'] = $this->getTokenInfo($payment);
171
+ }
172
+ elseif ($info->getAdditionalInformation('paypage_enabled') == "1" ){
173
+ $payment_hash['paypage'] = $this->getPaypageInfo($payment);
174
+ }
175
+ else{
176
+ $payment_hash['card'] = $this->getCreditCardInfo($payment);
177
+ }
178
+ return $payment_hash;
179
+ }
180
+
181
  public function getContactInformation($contactInfo)