Litle_Payments - Version 8.13.3

Version Notes

This extension implements Litle XML

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

Download this release

Release Info

Developer Litle
Extension Litle_Payments
Version 8.13.3
Comparing to
See all releases


Code changes from version 8.13.2 to 8.13.3

Files changed (33) hide show
  1. app/code/local/Litle/CreditCard/Block/Form/CreditCard.php +203 -166
  2. app/code/local/Litle/CreditCard/Helper/Data.php +24 -33
  3. app/code/local/Litle/CreditCard/Model/Order/Payment.php +10 -10
  4. app/code/local/Litle/CreditCard/Model/PaymentLogic.php +404 -322
  5. app/code/local/Litle/CreditCard/etc/config.xml +1 -1
  6. app/code/local/Litle/CreditCard/etc/system.xml +15 -4
  7. app/code/local/Litle/LEcheck/Block/Form/LEcheck.php +2 -2
  8. app/code/local/Litle/LEcheck/etc/config.xml +1 -1
  9. app/code/local/Litle/LitleSDK/Obj2xml.php +2 -2
  10. app/code/local/Litle/Palorus/Block/Adminhtml/Customer/Edit/Tab/Vault.php +94 -0
  11. app/code/local/Litle/Palorus/Block/Vault.php +105 -0
  12. app/code/local/Litle/Palorus/Block/Vault/List.php +64 -0
  13. app/code/local/Litle/Palorus/Helper/Data.php +210 -128
  14. app/code/local/Litle/Palorus/Model/Mysql4/Vault.php +24 -7
  15. app/code/local/Litle/Palorus/Model/Mysql4/Vault/Collection.php +12 -1
  16. app/code/local/Litle/Palorus/Model/Vault.php +146 -1
  17. app/code/local/Litle/Palorus/controllers/Adminhtml/VaultController.php +59 -0
  18. app/code/local/Litle/Palorus/controllers/VaultController.php +88 -0
  19. app/code/local/Litle/Palorus/etc/config.xml +41 -8
  20. app/code/local/Litle/Palorus/sql/palorus_setup/mysql4-upgrade-8.13.2-8.13.3.php +49 -0
  21. app/design/adminhtml/default/default/layout/litle.xml +6 -2
  22. app/design/adminhtml/default/default/template/litle/customer/tab/vault.phtml +33 -0
  23. app/design/adminhtml/default/default/template/litle/form/litlecc.phtml +158 -0
  24. app/design/adminhtml/default/default/template/{payment → litle}/form/litleecheck.phtml +0 -0
  25. app/design/adminhtml/default/default/template/payment/form/litlecc.phtml +0 -138
  26. app/design/frontend/base/default/layout/litlecreditcard.xml +27 -2
  27. app/design/frontend/{default/default/template/payment → base/default/template/litle}/form/litlecc.phtml +115 -119
  28. app/design/frontend/{default/default/template/payment → base/default/template/litle}/form/litleecheck.phtml +3 -3
  29. app/design/frontend/base/default/template/{payment → litle}/form/litlejs.phtml +0 -0
  30. app/design/frontend/base/default/template/litle/vault/list.phtml +49 -0
  31. app/design/frontend/base/default/template/payment/form/litlecc.phtml +0 -254
  32. app/design/frontend/base/default/template/payment/form/litleecheck.phtml +0 -35
  33. package.xml +2 -2
app/code/local/Litle/CreditCard/Block/Form/CreditCard.php CHANGED
@@ -1,178 +1,215 @@
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
 
1
  <?php
2
+
3
  /**
4
  * Magento
 
5
  * NOTICE OF LICENSE
6
+ * This source file is subject to the Open Software License (OSL 3.0) that is
7
+ * bundled with this package in the file LICENSE.txt. It is also available
8
+ * through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php If you did not receive a copy of
10
+ * the license and are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magentocommerce.com so we can send you a copy
12
+ * immediately.
 
 
13
  * DISCLAIMER
 
14
  * Do not edit or add to this file if you wish to upgrade Magento to newer
15
+ * versions in the future. If you wish to customize Magento for your needs
16
+ * please refer to http://www.magentocommerce.com for more information.
17
  *
18
+ * @category Mage
19
+ * @package Mage_Payment
20
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
21
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License
22
+ * (OSL 3.0)
23
  */
 
 
24
  class Litle_CreditCard_Block_Form_CreditCard extends Mage_Payment_Block_Form
25
  {
26
+
27
+ /**
28
+ *
29
+ * @var array
30
+ */
31
+ protected $_storedCards = null;
32
+
33
+ protected function _construct()
34
+ {
35
+ parent::_construct();
36
+ $this->setTemplate('litle/form/litlecc.phtml');
37
+ }
38
+
39
+ /**
40
+ * Retrieve payment configuration object
41
+ *
42
+ * @return Mage_Payment_Model_Config
43
+ */
44
+ protected function _getConfig()
45
+ {
46
+ return Mage::getSingleton('payment/config');
47
+ }
48
+
49
+
50
+ public function getCurrency()
51
+ {
52
+ return Mage::app()->getStore()->getCurrentCurrencyCode();
53
+ }
54
+
55
+ public function getMerchantIdMap()
56
+ {
57
+ return Mage::getStoreConfig('payment/CreditCard/merchant_id');
58
+ }
59
+
60
+ public function getReportGroup()
61
+ {
62
+ $string2Eval = 'return array' . $this->getMerchantIdMap() . ";";
63
+ $merchant_map = eval($string2Eval);
64
+ $reportGroup = $merchant_map[$this->getCurrency()];
65
+ return $reportGroup;
66
+ }
67
+
68
+ /**
69
+ * Retrieve availables credit card types
70
+ *
71
+ * @return array
72
+ */
73
+ public function getCcAvailableTypes()
74
+ {
75
+ $types = $this->_getConfig()->getCcTypes();
76
+ if ($method = $this->getMethod()) {
77
+ $availableTypes = $method->getConfigData('cctypes');
78
+ if ($availableTypes) {
79
+ $availableTypes = explode(',', $availableTypes);
80
+ foreach ($types as $code => $name) {
81
+ if (! in_array($code, $availableTypes)) {
82
+ unset($types[$code]);
83
+ }
84
+ }
85
+ }
86
+ }
87
+ return $types;
88
+ }
89
+
90
+ /**
91
+ * Retrieve credit card expire months
92
+ *
93
+ * @return array
94
+ */
95
+ public function getCcMonths()
96
+ {
97
+ $months = $this->getData('cc_months');
98
+ if (is_null($months)) {
99
+ $months[0] = $this->__('Month');
100
+ $months = array_merge($months, $this->_getConfig()->getMonths());
101
+ $this->setData('cc_months', $months);
102
+ }
103
+ return $months;
104
+ }
105
+
106
+ /**
107
+ * Retrieve credit card expire years
108
+ *
109
+ * @return array
110
+ */
111
+ public function getCcYears()
112
+ {
113
+ $years = $this->getData('cc_years');
114
+ if (is_null($years)) {
115
+ $years = $this->_getConfig()->getYears();
116
+ $years = array(
117
+ 0 => $this->__('Year')
118
+ ) + $years;
119
+ $this->setData('cc_years', $years);
120
+ }
121
+ return $years;
122
+ }
123
+
124
+ /**
125
+ * Retrive has verification configuration
126
+ *
127
+ * @return boolean
128
+ */
129
+ public function hasVerification()
130
+ {
131
+ if ($this->getMethod()) {
132
+ $configData = $this->getMethod()->getConfigData('useccv');
133
+ if (is_null($configData)) {
134
+ return true;
135
+ }
136
+ return (bool) $configData;
137
+ }
138
+ return true;
139
+ }
140
+
141
+ /* Whether switch/solo card type available */
142
+ public function hasSsCardType()
143
+ {
144
+ $availableTypes = explode(',', $this->getMethod()->getConfigData('cctypes'));
145
+ $ssPresenations = array_intersect(array(
146
+ 'SS',
147
+ 'SM',
148
+ 'SO'
149
+ ), $availableTypes);
150
+ if ($availableTypes && count($ssPresenations) > 0) {
151
+ return true;
152
+ }
153
+ return false;
154
+ }
155
+
156
+ /* solo/switch card start year @return array */
157
+ public function getSsStartYears()
158
+ {
159
+ $years = array();
160
+ $first = date("Y");
161
+
162
+ for ($index = 5; $index >= 0; $index --) {
163
+ $year = $first - $index;
164
+ $years[$year] = $year;
165
+ }
166
+ $years = array(
167
+ 0 => $this->__('Year')
168
+ ) + $years;
169
+ return $years;
170
+ }
171
+
172
+ public function getPaypageEnabled()
173
+ {
174
+ return Mage::getStoreConfig('payment/CreditCard/paypage_enable');
175
+ }
176
+
177
+ public function getVaultEnabled()
178
+ {
179
+ return Mage::helper('palorus')->isVaultEnabled();
180
+ }
181
+
182
+ /**
183
+ *
184
+ * @return Litle_Palorus_Model_Mysql4_Vault_Collection
185
+ */
186
+ public function getStoredCards()
187
+ {
188
+ if (is_null($this->_storedCards)) {
189
+ $this->_storedCards = Mage::getModel('palorus/vault')->getCollection()->addCustomerFilter(Mage::helper('palorus')->getCustomer());
190
+ }
191
+ return $this->_storedCards;
192
+ }
193
+
194
+ public function hasStoredCards()
195
+ {
196
+ if (count($this->getStoredCards())) {
197
+ return true;
198
+ }
199
+ return false;
200
+ }
201
+
202
+ /**
203
+ * Render block HTML
204
+ *
205
+ * @return string
206
+ */
207
+ protected function _toHtml()
208
+ {
209
+ Mage::dispatchEvent('payment_form_block_to_html_before', array(
210
+ 'block' => $this
211
+ ));
212
+ return parent::_toHtml();
213
+ }
214
  }
215
 
app/code/local/Litle/CreditCard/Helper/Data.php CHANGED
@@ -27,40 +27,31 @@ class Litle_CreditCard_Helper_Data extends Mage_Core_Helper_Abstract
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
  }
27
  return ($this->isMOPLitleCC($mop) || $this->isMOPLitleECheck($mop));
28
  }
29
 
30
+ // This method converts dollars to cents, and takes care of trailing decimals if any.
31
+ public function formatAmount($amountInDecimal, $roundUp) {
32
+ if( empty($amountInDecimal) || $amountInDecimal === "" )
33
+ return $amountInDecimal;
34
+
35
+ $amountInCents = ((double)$amountInDecimal) * 100;
36
+ $amountToReturn = (int)$amountInCents;
37
+
38
+ // check to see if we have left over decimals -- i.e. the incoming amount had more than 2 decimals
39
+ if( $amountInCents != (double)$amountToReturn)
40
+ {
41
+ // yes, more decimals than needed indeed!
42
+ $amountToReturn = ($roundUp) ? ($amountToReturn + 1) : ($amountToReturn);
43
  }
44
+ return $amountToReturn;
 
45
  }
46
+
47
+ /**
48
+ * Are we using the sandbox?
49
+ *
50
+ * @return boolean
51
+ */
52
+ public function isSandbox()
53
+ {
54
+ $url = Mage::getStoreConfig('payment/CreditCard/url');
55
+ return (stristr($url, '.testlitle.com/sandbox') !== false);
 
 
 
 
 
 
 
 
 
56
  }
57
  }
app/code/local/Litle/CreditCard/Model/Order/Payment.php CHANGED
@@ -32,12 +32,12 @@ class Litle_CreditCard_Model_Order_Payment extends Mage_Sales_Model_Order_Paymen
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)
@@ -55,7 +55,7 @@ class Litle_CreditCard_Model_Order_Payment extends Mage_Sales_Model_Order_Paymen
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.";
@@ -88,7 +88,7 @@ class Litle_CreditCard_Model_Order_Payment extends Mage_Sales_Model_Order_Paymen
88
  $orderItem->setRowInvoiced(0);
89
  $orderItem->setBaseRowInvoiced(0);
90
  }
91
-
92
  $order
93
  ->setBaseDiscountInvoiced(0)
94
  ->setBaseShippingInvoiced(0)
@@ -107,19 +107,19 @@ class Litle_CreditCard_Model_Order_Payment extends Mage_Sales_Model_Order_Paymen
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
@@ -129,7 +129,7 @@ class Litle_CreditCard_Model_Order_Payment extends Mage_Sales_Model_Order_Paymen
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)
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)
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.";
88
  $orderItem->setRowInvoiced(0);
89
  $orderItem->setBaseRowInvoiced(0);
90
  }
91
+
92
  $order
93
  ->setBaseDiscountInvoiced(0)
94
  ->setBaseShippingInvoiced(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(Mage_Sales_Model_Order_Invoice::STATE_CANCELED)->save();
121
  }
122
+
123
 
124
 
125
  // update transactions, order state and add comments
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)
app/code/local/Litle/CreditCard/Model/PaymentLogic.php CHANGED
@@ -1,72 +1,74 @@
1
  <?php
2
- require_once('Litle/LitleSDK/LitleOnline.php');
3
 
4
  class Litle_CreditCard_Model_PaymentLogic extends Mage_Payment_Model_Method_Cc
5
  {
 
6
  /**
7
  * unique internal payment method identifier
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
15
  */
16
- protected $_isGateway = true;
17
 
18
  /**
19
  * can this method authorise?
20
  */
21
- protected $_canAuthorize = true;
22
 
23
  /**
24
  * can this method capture funds?
25
  */
26
- protected $_canCapture = true;
27
 
28
  /**
29
  * can we capture only partial amounts?
30
  */
31
- protected $_canCapturePartial = true;
32
 
33
  /**
34
  * can this method refund?
35
  */
36
- protected $_canRefund = true;
37
 
38
- protected $_canRefundInvoicePartial = true;
39
 
40
  /**
41
  * can this method void transactions?
42
  */
43
- protected $_canVoid = true;
44
 
45
  /**
46
  * can admins use this payment method?
47
  */
48
- protected $_canUseInternal = true;
49
 
50
  /**
51
  * show this method on the checkout page
52
  */
53
- protected $_canUseCheckout = true;
54
 
55
  /**
56
  * available for multi shipping checkouts?
57
  */
58
- protected $_canUseForMultishipping = true;
59
 
60
  /**
61
  * can this method save cc info for later use?
62
  */
63
  protected $_canSaveCc = false;
64
 
65
- public function getConfigData($fieldToLookFor, $store = NULL)
66
  {
67
  $returnFromThisModel = Mage::getStoreConfig('payment/CreditCard/' . $fieldToLookFor);
68
- if( $returnFromThisModel == NULL )
69
- $returnFromThisModel = parent::getConfigData($fieldToLookFor, $store);
 
70
 
71
  return $returnFromThisModel;
72
  }
@@ -74,48 +76,50 @@ class Litle_CreditCard_Model_PaymentLogic extends Mage_Payment_Model_Method_Cc
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
  }
@@ -123,56 +127,67 @@ class Litle_CreditCard_Model_PaymentLogic extends Mage_Payment_Model_Method_Cc
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]);
130
- $retArray["cardValidationNum"] = $payment->getCcCid();
131
 
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;
@@ -180,184 +195,187 @@ class Litle_CreditCard_Model_PaymentLogic extends Mage_Payment_Model_Method_Cc
180
 
181
  public function getContactInformation($contactInfo)
182
  {
183
- if(!empty($contactInfo)){
184
  $retArray = array();
185
- $retArray["firstName"] =$contactInfo->getFirstname();
186
- $retArray["lastName"] = $contactInfo->getLastname();
187
- $retArray["companyName"] = $contactInfo->getCompany();
188
- $retArray["addressLine1"] = $contactInfo->getStreet(1);
189
- $retArray["addressLine2"] = $contactInfo->getStreet(2);
190
- $retArray["addressLine3"] = $contactInfo->getStreet(3);
191
- $retArray["city"] = $contactInfo->getCity();
192
- $retArray["state"] = $contactInfo->getRegion();
193
- $retArray["zip"] = $contactInfo->getPostcode();
194
- $retArray["country"] = $contactInfo->getCountry();
195
- $retArray["email"] = $contactInfo->getCustomerEmail();
196
- $retArray["phone"] = $contactInfo->getTelephone();
197
  return $retArray;
198
  }
199
- return NULL;
200
  }
201
 
202
-
203
  public function getBillToAddress(Varien_Object $payment)
204
  {
205
  $order = $payment->getOrder();
206
- if(!empty($order)){
207
- $billing = $order ->getBillingAddress();
208
- if(!empty($billing)){
209
  return $this->getContactInformation($billing);
210
  }
211
  }
212
- return NULL;
213
  }
214
 
215
  public function getShipToAddress(Varien_Object $payment)
216
  {
217
  $order = $payment->getOrder();
218
- if(!empty($order)){
219
  $shipping = $order->getShippingAddress();
220
- if(!empty($shipping)){
221
  return $this->getContactInformation($shipping);
222
  }
223
  }
224
- return NULL;
225
  }
226
 
227
-
228
  public function getIpAddress(Varien_Object $payment)
229
  {
230
  $order = $payment->getOrder();
231
- if(!empty($order)){
232
  return $order->getRemoteIp();
233
  }
234
- return NULL;
235
  }
236
 
237
-
238
-
239
- public function getMerchantId(Varien_Object $payment){
240
  $order = $payment->getOrder();
241
  $currency = $order->getOrderCurrencyCode();
242
- $string2Eval = 'return array' . $this->getConfigData("merchant_id") . ';';
243
  $merchant_map = eval($string2Eval);
244
  $merchantId = $merchant_map[$currency];
245
  return $merchantId;
246
  }
247
 
248
-
249
  public function merchantData(Varien_Object $payment)
250
  {
251
  $order = $payment->getOrder();
252
- $hash = array('user'=> $this->getConfigData("user"),
253
- 'password'=> $this->getConfigData("password"),
254
- 'merchantId'=> $this->getMerchantId($payment),
255
- 'version'=>'8.10',
256
- 'merchantSdk'=>'Magento;8.13.2',
257
- 'reportGroup'=>$this->getMerchantId($payment),
258
- 'customerId'=> $order->getCustomerEmail(),
259
- 'url'=>$this->getConfigData("url"),
260
- 'proxy'=>$this->getConfigData("proxy"),
261
- 'timeout'=>$this->getConfigData("timeout")
 
262
  );
263
  return $hash;
264
  }
265
 
266
-
267
- public function getCustomBilling($url){
268
  $retArray = array();
269
 
270
- if (strlen($url)>13){
271
- $url = str_replace('http://','',$url);
272
- $url = str_replace('https://','',$url);
273
- $url_temp = explode('/',$url);
274
  $url = $url_temp['0'];
275
- if (strlen($url)>13){
276
- $url = str_replace('www.','',$url);
277
- if (strlen($url)>13){
278
- $url_temp2 = explode('.',$url);
279
  $count = count($url_temp2);
280
- }if($count < 3){
281
- if (strlen($url_temp2['0'] . '.' . $url_temp2['1']) > 13){
 
282
  $url = $url_temp2['0'];
283
- }else{
284
  $url = $url_temp2['0'] . '.' . $url_temp2['1'];
285
  }
286
  }
287
  }
288
  }
289
-
290
- $url = substr($url,0,13);
291
- if(substr($url,12) === '.'){
292
- $url = substr($url,0,12);
293
- }
294
- elseif (substr($url,0) === '.'){
295
- $url = substr($url,1,12);
296
  }
297
  $retArray['url'] = $url;
298
 
299
  return $retArray;
300
  }
301
 
302
- public function getOrderDate(Varien_Object $payment){
 
303
  $order = $payment->getOrder();
304
  $date = $order->getCreatedAtFormated(short);
305
- $date_temp = explode('/',$date);
306
  $month = $date_temp['0'];
307
- if ((int)$month < 10){
308
  $month = '0' . $month;
309
  }
310
- $day=$date_temp['1'];
311
- if ((int)$day < 10){
312
  $day = '0' . $day;
313
  }
314
- $year_temp = explode(' ',$date_temp['2']);
315
  $year = '20' . $year_temp['0'];
316
  return $year . '-' . $month . '-' . $day;
317
  }
318
 
319
- public function getLineItemData(Varien_Object $payment){
 
320
  $order = $payment->getOrder();
321
  $items = $order->getAllItems();
322
  $i = 0;
323
  $lineItemArray = array();
324
- foreach ($items as $itemId => $item)
325
- {
326
  $name = $item->getName();
327
- $unitPrice=$item->getPrice();
328
- $sku=$item->getSku();
329
- $ids=$item->getProductId();
330
- $qty=$item->getQtyToInvoice();
331
-
332
- if( strlen($name) > 26 )
333
- $name = substr($name,0,26);
334
-
335
  $lineItemArray[$i] = array(
336
- 'itemSequenceNumber'=>($i+1),
337
- 'itemDescription'=>$name,
338
- 'productCode'=>$ids,
339
- 'quantity'=>$qty,
340
- 'lineItemTotal'=>(($unitPrice*$qty)*100),
341
- 'unitCost'=>($unitPrice * 100));
342
- $i++;
 
343
  }
344
  return $lineItemArray;
345
  }
346
 
347
-
348
  public function getEnhancedData(Varien_Object $payment)
349
  {
350
  $order = $payment->getOrder();
351
  $billing = $order->getBillingAddress();
352
- $i = 0;
353
- $hash = array('salesTax'=> $order->getTaxAmount()*100,
354
- 'discountAmount'=>$order->getDiscountAmount()*100,
355
- 'shippingAmount'=>$order->getShippingAmount()*100,
356
- 'destinationPostalCode'=>$billing->getPostcode(),
357
- 'destinationCountryCode'=>$billing->getCountry(),
358
- 'orderDate'=>$this->getOrderDate($payment),
359
- 'detailTax'=>array(array('taxAmount'=>$order->getTaxAmount()*100)),
360
- 'lineItemData' => $this->getLineItemData($payment)
 
 
 
 
 
361
  );
362
  return $hash;
363
  }
@@ -365,255 +383,319 @@ class Litle_CreditCard_Model_PaymentLogic extends Mage_Payment_Model_Method_Cc
365
  public function getFraudCheck(Varien_Object $payment)
366
  {
367
  $order = $payment->getOrder();
368
- $hash = array('customerIpAddress'=> $order->getRemoteIp()
 
369
  );
370
  return $hash;
371
  }
372
-
373
- public function getUpdater($litleResponse, $parentNode, $childNode=NULL){
374
-
375
- if($childNode === NULL){
 
 
 
 
 
 
 
 
376
  $new = $litleResponse->getElementsByTagName($parentNode)->item(0);
 
 
 
 
 
377
  }
378
- else{
379
- $new = $litleResponse->getElementsByTagName($parentNode)->item(0)->getElementsByTagName($childNode)->item(0)->nodeValue;
380
- }
381
-
382
  return $new;
383
  }
384
-
385
- public function accountUpdater(Varien_Object $payment,$litleResponse){
386
-
387
- if($this->getUpdater($litleResponse, 'newCardInfo') !== NULL){
388
-
389
- $payment->setCcLast4(substr($this->getUpdater($litleResponse, 'newCardInfo', 'number'), -4));
390
- $payment->setCcType($this->getUpdater($litleResponse, 'newCardInfo','type'));
391
- $payment->setCcExpDate($this->getUpdater($litleResponse, 'newCardInfo','expDate'));
392
-
393
- }
394
- elseif($this->getUpdater($litleResponse, 'newCardTokenInfo') !== NULL){
395
-
396
- $payment->setCcNumber($this->getUpdater($litleResponse, 'newCardTokenInfo','litleToken'));
397
- $payment->setCcLast4(substr($this->getUpdater($litleResponse, 'newCardTokenInfo', 'litleToken'), -4));
398
- $payment->setCcType($this->getUpdater($litleResponse, 'newCardTokenInfo','type'));
399
- $payment->setCcExpDate($this->getUpdater($litleResponse, 'newCardTokenInfo','expDate'));
400
- }
401
-
 
 
 
402
  }
403
-
404
-
405
- public function processResponse(Varien_Object $payment,$litleResponse){
406
- $this->accountUpdater($payment,$litleResponse);
407
- $message = XmlParser::getAttribute($litleResponse,'litleOnlineResponse','message');
408
- if ($message == "Valid Format"){
409
- $isSale = ($payment->getCcTransId() != NULL)? FALSE : TRUE;
410
- if( isset($litleResponse))
411
- {
412
- $litleResponseCode = XMLParser::getNode($litleResponse,'response');
413
- if($litleResponseCode != "000")
414
- {
415
- //Mage::throwException('response code is: ' . $litleResponseCode . 'txn type is: ');
416
- if(($litleResponseCode === "362") && Mage::helper("creditcard")->isStateOfOrderEqualTo($payment->getOrder(), Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE))
417
- {
418
- Mage::throwException("The void did not go through. Do a refund instead.");
419
- }
420
- else
421
- {
422
- $payment
423
- ->setStatus("Rejected")
424
- ->setCcTransId(XMLParser::getNode($litleResponse,'litleTxnId'))
425
- ->setLastTransId(XMLParser::getNode($litleResponse,'litleTxnId'))
426
- ->setTransactionId(XMLParser::getNode($litleResponse,'litleTxnId'))
427
- ->setIsTransactionClosed(0)
428
- ->setTransactionAdditionalInfo("additional_information", XMLParser::getNode($litleResponse,'message'));
429
-
430
- if($isSale)
431
- throw new Mage_Payment_Model_Info_Exception(Mage::helper('core')->__("Transaction was not approved. Contact us or try again later."));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
432
  else
433
- throw new Mage_Payment_Model_Info_Exception(Mage::helper('core')->__("Transaction was not approved. Contact Litle or try again later."));
 
 
434
  }
435
- }
436
- else
437
- {
438
- $payment
439
- ->setStatus("Approved")
440
- ->setCcTransId(XMLParser::getNode($litleResponse,'litleTxnId'))
441
- ->setLastTransId(XMLParser::getNode($litleResponse,'litleTxnId'))
442
- ->setTransactionId(XMLParser::getNode($litleResponse,'litleTxnId'))
443
- ->setIsTransactionClosed(0)
444
- ->setTransactionAdditionalInfo("additional_information", XMLParser::getNode($litleResponse,'message'));
445
-
446
  }
447
  return true;
448
  }
449
- }
450
- else{
451
  Mage::throwException($message);
452
  }
453
-
454
-
455
  }
 
456
  /**
457
- * this method is called if we are just authorising
458
- * a transaction
459
  */
460
  public function authorize(Varien_Object $payment, $amount)
461
  {
462
- if (preg_match("/sales_order_create/i", $_SERVER['REQUEST_URI']) && ($this->getConfigData('paypage_enable') == "1") )
463
- {
464
- $payment
465
- ->setStatus("N/A")
466
- ->setCcTransId("Litle VT")
467
- ->setLastTransId("Litle VT")
468
- ->setTransactionId("Litle VT")
469
- ->setIsTransactionClosed(0)
470
- ->setCcType("Litle VT");
471
- }
472
- else{
473
  $order = $payment->getOrder();
474
- $orderId = $order->getIncrementId();
475
- $amountToPass = ($amount* 100);
476
- if (!empty($order)){
 
 
 
 
 
 
477
  $hash = array(
478
- 'orderId'=> $orderId,
479
- 'amount'=> $amountToPass,
480
- 'orderSource'=> "ecommerce",
481
- 'billToAddress'=> $this->getBillToAddress($payment),
482
- 'shipToAddress'=> $this->getAddressInfo($payment),
483
- 'cardholderAuthentication'=> $this->getFraudCheck($payment),
484
- 'enhancedData'=>$this->getEnhancedData($payment),
485
- 'customBilling'=>$this->getCustomBilling(Mage::app()->getStore()-> getBaseUrl())
 
 
486
  );
 
 
 
487
  $payment_hash = $this->creditCardOrPaypageOrToken($payment);
488
- $hash_temp = array_merge($hash,$payment_hash);
489
  $merchantData = $this->merchantData($payment);
490
- $hash_in = array_merge($hash_temp,$merchantData);
 
491
  $litleRequest = new LitleOnlineRequest();
492
  $litleResponse = $litleRequest->authorizationRequest($hash_in);
493
- $this->processResponse($payment,$litleResponse);
494
- Mage::helper("palorus")->saveCustomerInsight($payment, $litleResponse);
495
- Mage::helper("palorus")->saveVault($payment, $litleResponse);
 
 
 
496
  }
497
  }
 
 
498
  }
499
 
500
  /**
501
- * this method is called if we are authorising AND
502
- * capturing a transaction
503
  */
504
- public function capture (Varien_Object $payment, $amount)
505
  {
506
- if (preg_match("/sales_order_create/i", $_SERVER['REQUEST_URI']) && ($this->getConfigData('paypage_enable') == "1") )
507
- {
508
- $payment
509
- ->setStatus("N/A")
510
- ->setCcTransId("Litle VT")
511
- ->setLastTransId("Litle VT")
512
- ->setTransactionId("Litle VT")
513
- ->setIsTransactionClosed(0)
514
- ->setCcType("Litle VT");
515
 
516
  return;
517
  }
518
 
519
- $this->isFromVT($payment, "capture");
520
 
521
  $order = $payment->getOrder();
522
- if (!empty($order)){
 
 
 
 
523
 
524
- $orderId =$order->getIncrementId();
525
- $amountToPass = ($amount* 100);
526
- $isPartialCapture = ($amount < $order->getGrandTotal()) ? "true" : "false";
527
- $isSale = ($payment->getCcTransId() != NULL)? FALSE : TRUE;
528
 
529
- if( !$isSale )
530
- {
531
  $hash = array(
532
- 'litleTxnId' => $payment->getParentTransactionId(),
533
- 'amount' => $amountToPass,
534
- 'partial' => $isPartialCapture
535
  );
536
  } else {
537
  $hash_temp = array(
538
- 'orderId'=> $orderId,
539
- 'amount'=> $amountToPass,
540
- 'orderSource'=> "ecommerce",
541
- 'billToAddress'=> $this->getBillToAddress($payment),
542
- 'shipToAddress'=> $this->getAddressInfo($payment),
 
543
  );
544
  $payment_hash = $this->creditCardOrPaypageOrToken($payment);
545
- $hash = array_merge($hash_temp,$payment_hash);
546
  }
547
  $merchantData = $this->merchantData($payment);
548
- $hash_in = array_merge($hash,$merchantData);
549
  $litleRequest = new LitleOnlineRequest();
550
 
551
- if( $isSale )
552
- {
553
  $litleResponse = $litleRequest->saleRequest($hash_in);
554
- Mage::helper("palorus")->saveCustomerInsight($payment, $litleResponse);
555
- Mage::helper("palorus")->saveVault($payment, $litleResponse);
556
  } else {
557
  $litleResponse = $litleRequest->captureRequest($hash_in);
558
  }
 
 
 
 
559
  }
560
- $this->processResponse($payment,$litleResponse);
 
 
561
  }
562
 
563
  /**
564
  * called if refunding
565
  */
566
- public function refund (Varien_Object $payment, $amount)
567
  {
568
- $this->isFromVT($payment, "refund");
569
-
570
  $order = $payment->getOrder();
571
  $isPartialRefund = ($amount < $order->getGrandTotal()) ? true : false;
572
-
573
- $amountToPass = ($amount* 100);
574
- if (!empty($order)){
575
- $hash = array(
576
- 'litleTxnId' => $payment->getCcTransId(),
577
- 'amount' => $amountToPass
578
- );
579
- $merchantData = $this->merchantData($payment);
580
- $hash_in = array_merge($hash,$merchantData);
581
- $litleRequest = new LitleOnlineRequest();
582
- $litleResponse = $litleRequest->creditRequest($hash_in);
583
- }
584
- $this->processResponse($payment,$litleResponse);
585
-
586
  return $this;
587
  }
588
 
589
  /**
590
  * called if voiding a payment
591
  */
592
- public function void (Varien_Object $payment)
593
  {
594
- $this->isFromVT($payment, "void");
595
 
596
  $order = $payment->getOrder();
597
- if (!empty($order)){
598
  $hash = array(
599
- 'litleTxnId' => $payment->getCcTransId()
600
  );
601
  $merchantData = $this->merchantData($payment);
602
- $hash_in = array_merge($hash,$merchantData);
603
  $litleRequest = new LitleOnlineRequest();
604
-
605
- if(Mage::helper("creditcard")->isStateOfOrderEqualTo($order, Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH)){
 
606
  $litleResponse = $litleRequest->authReversalRequest($hash_in);
607
- } else {
608
- $litleResponse = $litleRequest->voidRequest($hash_in);
609
- }
610
  }
611
- $this->processResponse($payment,$litleResponse);
 
 
612
  }
613
-
614
  public function cancel(Varien_Object $payment)
615
  {
616
  $this->void($payment);
617
- }
618
 
 
 
 
619
  }
1
  <?php
2
+ require_once ('Litle/LitleSDK/LitleOnline.php');
3
 
4
  class Litle_CreditCard_Model_PaymentLogic extends Mage_Payment_Model_Method_Cc
5
  {
6
+
7
  /**
8
  * unique internal payment method identifier
9
  */
10
  protected $_code = 'creditcard';
11
 
12
  protected $_formBlockType = 'creditcard/form_creditCard';
13
+
14
  /**
15
+ * this should probably be true if you're using this method to take payments
 
16
  */
17
+ protected $_isGateway = true;
18
 
19
  /**
20
  * can this method authorise?
21
  */
22
+ protected $_canAuthorize = true;
23
 
24
  /**
25
  * can this method capture funds?
26
  */
27
+ protected $_canCapture = true;
28
 
29
  /**
30
  * can we capture only partial amounts?
31
  */
32
+ protected $_canCapturePartial = true;
33
 
34
  /**
35
  * can this method refund?
36
  */
37
+ protected $_canRefund = true;
38
 
39
+ protected $_canRefundInvoicePartial = true;
40
 
41
  /**
42
  * can this method void transactions?
43
  */
44
+ protected $_canVoid = true;
45
 
46
  /**
47
  * can admins use this payment method?
48
  */
49
+ protected $_canUseInternal = true;
50
 
51
  /**
52
  * show this method on the checkout page
53
  */
54
+ protected $_canUseCheckout = true;
55
 
56
  /**
57
  * available for multi shipping checkouts?
58
  */
59
+ protected $_canUseForMultishipping = true;
60
 
61
  /**
62
  * can this method save cc info for later use?
63
  */
64
  protected $_canSaveCc = false;
65
 
66
+ public function getConfigData($fieldToLookFor, $store = null)
67
  {
68
  $returnFromThisModel = Mage::getStoreConfig('payment/CreditCard/' . $fieldToLookFor);
69
+ if (is_null($returnFromThisModel)) {
70
+ $returnFromThisModel = parent::getConfigData($fieldToLookFor, $store);
71
+ }
72
 
73
  return $returnFromThisModel;
74
  }
76
  public function isFromVT($payment, $txnType)
77
  {
78
  $parentTxnId = $payment->getParentTransactionId();
79
+ if ($parentTxnId == 'Litle VT') {
80
+ Mage::throwException(
81
+ "This order was placed using Litle Virtual Terminal. Please process the $txnType by logging into Litle Virtual Terminal (https://vt.litle.com).");
82
  }
83
  }
84
 
85
  public function assignData($data)
86
  {
87
+ if (! ($data instanceof Varien_Object)) {
88
+ $data = new Varien_Object($data);
89
+ }
 
 
90
 
91
+ if ($this->getConfigData('paypage_enabled')) {
92
  $info = $this->getInfoInstance();
93
  $info->setAdditionalInformation('paypage_enabled', $data->getPaypageEnabled());
94
  $info->setAdditionalInformation('paypage_registration_id', $data->getPaypageRegistrationId());
95
  $info->setAdditionalInformation('paypage_order_id', $data->getOrderId());
96
  $info->setAdditionalInformation('cc_vaulted', $data->getCcVaulted());
97
+ $info->setAdditionalInformation('cc_should_save', $data->getCcShouldSave());
98
  }
 
 
99
 
100
+ if ($this->getConfigData('vault_enable')) {
101
+ $info->setAdditionalInformation('cc_vaulted', $data->getCcVaulted());
102
+ $info->setAdditionalInformation('cc_should_save', $data->getCcShouldSave());
103
+ }
104
 
105
+ return parent::assignData($data);
106
+ }
107
 
108
  public function validate()
109
  {
110
+ // no cc validation required.
111
  return $this;
112
  }
113
 
114
  public function litleCcTypeEnum(Varien_Object $payment)
115
  {
116
+ $typeEnum = '';
117
+ if ($payment->getCcType() == 'AE') {
118
+ $typeEnum = 'AX';
119
+ } elseif ($payment->getCcType() == 'JCB') {
120
+ $typeEnum = 'JC';
121
+ } else {
122
+ $typeEnum = $payment->getCcType();
 
 
123
  }
124
  return $typeEnum;
125
  }
127
  public function getCreditCardInfo(Varien_Object $payment)
128
  {
129
  $retArray = array();
130
+ $retArray['type'] = $this->litleCcTypeEnum($payment);
131
+ $retArray['number'] = $payment->getCcNumber();
132
+ preg_match('/\d\d(\d\d)/', $payment->getCcExpYear(), $expYear);
133
+ $retArray['expDate'] = sprintf('%02d%02d', $payment->getCcExpMonth(), $expYear[1]);
134
+ $retArray['cardValidationNum'] = $payment->getCcCid();
135
 
136
  return $retArray;
137
  }
138
 
139
+ /**
140
+ * Return the last 4 digits of the card number.
141
+ *
142
+ * @param Varien_Object $payment
143
+ * @return string
144
+ */
145
+ public function getCcLast4($payment)
146
+ {
147
+ $numbersOnly = preg_replace('/[^0-9]*/', '', $payment->getCcNumber());
148
+ return substr($numbersOnly, - 4, 4);
149
+ }
150
+
151
  public function getPaypageInfo($payment)
152
  {
153
  $info = $this->getInfoInstance();
154
 
155
  $retArray = array();
156
+ $retArray['type'] = $this->litleCcTypeEnum($payment);
157
+ $retArray['paypageRegistrationId'] = $info->getAdditionalInformation('paypage_registration_id');
158
+ preg_match('/\d\d(\d\d)/', $payment->getCcExpYear(), $expYear);
159
+ $retArray['expDate'] = sprintf('%02d%02d', $payment->getCcExpMonth(), $expYear[1]);
160
+ $retArray['cardValidationNum'] = $payment->getCcCid();
161
 
162
  return $retArray;
163
  }
164
 
165
  public function getTokenInfo($payment)
166
  {
167
+ $vaultIndex = $this->getInfoInstance()->getAdditionalInformation('cc_vaulted');
168
+ $vaultCard = Mage::getModel('palorus/vault')->load($vaultIndex);
 
 
169
 
170
  $retArray = array();
171
+ $retArray['type'] = $vaultCard->getType();
172
+ $retArray['litleToken'] = $vaultCard->getToken();
173
+ $retArray['cardValidationNum'] = $payment->getCcCid();
174
+
175
+ $payment->setCcLast4($vaultCard->getLast4());
176
+ $payment->setCcType($vaultCard->getType());
177
+
178
  return $retArray;
179
  }
180
+
181
+ public function creditCardOrPaypageOrToken($payment)
182
+ {
183
  $info = $this->getInfoInstance();
184
  $vaultIndex = $info->getAdditionalInformation('cc_vaulted');
185
  $payment_hash = array();
186
+ if ($vaultIndex > 0) {
187
  $payment_hash['token'] = $this->getTokenInfo($payment);
188
+ } elseif ($info->getAdditionalInformation('paypage_enabled') == '1') {
 
189
  $payment_hash['paypage'] = $this->getPaypageInfo($payment);
190
+ } else {
 
191
  $payment_hash['card'] = $this->getCreditCardInfo($payment);
192
  }
193
  return $payment_hash;
195
 
196
  public function getContactInformation($contactInfo)
197
  {
198
+ if (! empty($contactInfo)) {
199
  $retArray = array();
200
+ $retArray['firstName'] = $contactInfo->getFirstname();
201
+ $retArray['lastName'] = $contactInfo->getLastname();
202
+ $retArray['companyName'] = $contactInfo->getCompany();
203
+ $retArray['addressLine1'] = $contactInfo->getStreet(1);
204
+ $retArray['addressLine2'] = $contactInfo->getStreet(2);
205
+ $retArray['addressLine3'] = $contactInfo->getStreet(3);
206
+ $retArray['city'] = $contactInfo->getCity();
207
+ $retArray['state'] = $contactInfo->getRegion();
208
+ $retArray['zip'] = $contactInfo->getPostcode();
209
+ $retArray['country'] = $contactInfo->getCountry();
210
+ $retArray['email'] = $contactInfo->getCustomerEmail();
211
+ $retArray['phone'] = $contactInfo->getTelephone();
212
  return $retArray;
213
  }
214
+ return null;
215
  }
216
 
 
217
  public function getBillToAddress(Varien_Object $payment)
218
  {
219
  $order = $payment->getOrder();
220
+ if (! empty($order)) {
221
+ $billing = $order->getBillingAddress();
222
+ if (! empty($billing)) {
223
  return $this->getContactInformation($billing);
224
  }
225
  }
226
+ return null;
227
  }
228
 
229
  public function getShipToAddress(Varien_Object $payment)
230
  {
231
  $order = $payment->getOrder();
232
+ if (! empty($order)) {
233
  $shipping = $order->getShippingAddress();
234
+ if (! empty($shipping)) {
235
  return $this->getContactInformation($shipping);
236
  }
237
  }
238
+ return null;
239
  }
240
 
 
241
  public function getIpAddress(Varien_Object $payment)
242
  {
243
  $order = $payment->getOrder();
244
+ if (! empty($order)) {
245
  return $order->getRemoteIp();
246
  }
247
+ return null;
248
  }
249
 
250
+ public function getMerchantId(Varien_Object $payment)
251
+ {
 
252
  $order = $payment->getOrder();
253
  $currency = $order->getOrderCurrencyCode();
254
+ $string2Eval = 'return array' . $this->getConfigData('merchant_id') . ';';
255
  $merchant_map = eval($string2Eval);
256
  $merchantId = $merchant_map[$currency];
257
  return $merchantId;
258
  }
259
 
 
260
  public function merchantData(Varien_Object $payment)
261
  {
262
  $order = $payment->getOrder();
263
+ $hash = array(
264
+ 'user' => $this->getConfigData('user'),
265
+ 'password' => $this->getConfigData('password'),
266
+ 'merchantId' => $this->getMerchantId($payment),
267
+ 'version' => '8.10',
268
+ 'merchantSdk' => 'Magento;8.13.2',
269
+ 'reportGroup' => $this->getMerchantId($payment),
270
+ 'customerId' => $order->getCustomerEmail(),
271
+ 'url' => $this->getConfigData('url'),
272
+ 'proxy' => $this->getConfigData('proxy'),
273
+ 'timeout' => $this->getConfigData('timeout')
274
  );
275
  return $hash;
276
  }
277
 
278
+ public function getCustomBilling($url)
279
+ {
280
  $retArray = array();
281
 
282
+ if (strlen($url) > 13) {
283
+ $url = str_replace('http://', '', $url);
284
+ $url = str_replace('https://', '', $url);
285
+ $url_temp = explode('/', $url);
286
  $url = $url_temp['0'];
287
+ if (strlen($url) > 13) {
288
+ $url = str_replace('www.', '', $url);
289
+ if (strlen($url) > 13) {
290
+ $url_temp2 = explode('.', $url);
291
  $count = count($url_temp2);
292
+ }
293
+ if ($count < 3) {
294
+ if (strlen($url_temp2['0'] . '.' . $url_temp2['1']) > 13) {
295
  $url = $url_temp2['0'];
296
+ } else {
297
  $url = $url_temp2['0'] . '.' . $url_temp2['1'];
298
  }
299
  }
300
  }
301
  }
302
+
303
+ $url = substr($url, 0, 13);
304
+ if (substr($url, 12) === '.') {
305
+ $url = substr($url, 0, 12);
306
+ } elseif (substr($url, 0) === '.') {
307
+ $url = substr($url, 1, 12);
 
308
  }
309
  $retArray['url'] = $url;
310
 
311
  return $retArray;
312
  }
313
 
314
+ public function getOrderDate(Varien_Object $payment)
315
+ {
316
  $order = $payment->getOrder();
317
  $date = $order->getCreatedAtFormated(short);
318
+ $date_temp = explode('/', $date);
319
  $month = $date_temp['0'];
320
+ if ((int) $month < 10) {
321
  $month = '0' . $month;
322
  }
323
+ $day = $date_temp['1'];
324
+ if ((int) $day < 10) {
325
  $day = '0' . $day;
326
  }
327
+ $year_temp = explode(' ', $date_temp['2']);
328
  $year = '20' . $year_temp['0'];
329
  return $year . '-' . $month . '-' . $day;
330
  }
331
 
332
+ public function getLineItemData(Varien_Object $payment)
333
+ {
334
  $order = $payment->getOrder();
335
  $items = $order->getAllItems();
336
  $i = 0;
337
  $lineItemArray = array();
338
+ foreach ($items as $itemId => $item) {
 
339
  $name = $item->getName();
340
+ $unitPrice = $item->getPrice();
341
+ $sku = $item->getSku();
342
+ $ids = $item->getProductId();
343
+ $qty = $item->getQtyToInvoice();
344
+
345
+ if (strlen($name) > 26)
346
+ $name = substr($name, 0, 26);
347
+
348
  $lineItemArray[$i] = array(
349
+ 'itemSequenceNumber' => ($i + 1),
350
+ 'itemDescription' => $name,
351
+ 'productCode' => $ids,
352
+ 'quantity' => $qty,
353
+ 'lineItemTotal' => Mage::helper('creditcard')->formatAmount(($unitPrice * $qty), true),
354
+ 'unitCost' => Mage::helper('creditcard')->formatAmount(($unitPrice), true)
355
+ );
356
+ $i ++;
357
  }
358
  return $lineItemArray;
359
  }
360
 
 
361
  public function getEnhancedData(Varien_Object $payment)
362
  {
363
  $order = $payment->getOrder();
364
  $billing = $order->getBillingAddress();
365
+
366
+ $hash = array(
367
+ 'salesTax' => Mage::helper('creditcard')->formatAmount($order->getTaxAmount(), true),
368
+ 'discountAmount' => Mage::helper('creditcard')->formatAmount($order->getDiscountAmount(), true),
369
+ 'shippingAmount' => Mage::helper('creditcard')->formatAmount($order->getShippingAmount(), true),
370
+ 'destinationPostalCode' => $billing->getPostcode(),
371
+ 'destinationCountryCode' => $billing->getCountry(),
372
+ 'orderDate' => $this->getOrderDate($payment),
373
+ 'detailTax' => array(
374
+ array(
375
+ 'taxAmount' => Mage::helper('creditcard')->formatAmount($order->getTaxAmount(), true)
376
+ )
377
+ ),
378
+ 'lineItemData' => $this->getLineItemData($payment)
379
  );
380
  return $hash;
381
  }
383
  public function getFraudCheck(Varien_Object $payment)
384
  {
385
  $order = $payment->getOrder();
386
+ $hash = array(
387
+ 'customerIpAddress' => $order->getRemoteIp()
388
  );
389
  return $hash;
390
  }
391
+
392
+ /**
393
+ * Parses Litle response to obtain update customer information.
394
+ *
395
+ * @param DOMDocument $litleResponse
396
+ * @param string $parentNode
397
+ * @param string $childNode
398
+ * @return DOMNode
399
+ */
400
+ public function getUpdater($litleResponse, $parentNode, $childNode = null)
401
+ {
402
+ if (is_null($childNode)) {
403
  $new = $litleResponse->getElementsByTagName($parentNode)->item(0);
404
+ } else {
405
+ $new = $litleResponse->getElementsByTagName($parentNode)
406
+ ->item(0)
407
+ ->getElementsByTagName($childNode)
408
+ ->item(0)->nodeValue;
409
  }
410
+
 
 
 
411
  return $new;
412
  }
413
+
414
+ /**
415
+ * Updates customer account information with most current from Litle.
416
+ *
417
+ * @param Varien_Object $payment
418
+ * @param DOMDocument $litleResponse
419
+ */
420
+ public function accountUpdater(Varien_Object $payment, $litleResponse)
421
+ {
422
+ if ($this->getUpdater($litleResponse, 'newCardInfo') !== null) {
423
+ $payment->setCcLast4(
424
+ substr($this->getUpdater($litleResponse, 'newCardInfo', 'number'), - 4));
425
+ $payment->setCcType($this->getUpdater($litleResponse, 'newCardInfo', 'type'));
426
+ $payment->setCcExpDate($this->getUpdater($litleResponse, 'newCardInfo', 'expDate'));
427
+ } elseif ($this->getUpdater($litleResponse, 'newCardTokenInfo') !== null) {
428
+ $payment->setCcNumber($this->getUpdater($litleResponse, 'newCardTokenInfo', 'litleToken'));
429
+ $payment->setCcLast4(
430
+ substr($this->getUpdater($litleResponse, 'newCardTokenInfo', 'litleToken'), - 4));
431
+ $payment->setCcType($this->getUpdater($litleResponse, 'newCardTokenInfo', 'type'));
432
+ $payment->setCcExpDate($this->getUpdater($litleResponse, 'newCardTokenInfo', 'expDate'));
433
+ }
434
  }
435
+
436
+ /**
437
+ * Update Vaulted card information.
438
+ *
439
+ * @param Varien_Object $payment
440
+ * @param DOMDocument $litleResponse
441
+ */
442
+ protected function _saveToken(Varien_Object $payment, DOMDocument $litleResponse)
443
+ {
444
+ if (!is_null($this->getUpdater($litleResponse, 'tokenResponse')) &&
445
+ !is_null($this->getUpdater($litleResponse, 'tokenResponse', 'litleToken'))) {
446
+
447
+ $vault = Mage::getModel('palorus/vault')->setTokenFromPayment(
448
+ $payment,
449
+ $this->getUpdater($litleResponse, 'tokenResponse', 'litleToken'),
450
+ $this->getUpdater($litleResponse, 'tokenResponse', 'bin'));
451
+
452
+ $this->getInfoInstance()->setAdditionalInformation('vault_id', $vault->getId());
453
+ }
454
+ }
455
+
456
+ /**
457
+ *
458
+ * @param Varien_Object $payment
459
+ * @param DOMDocument $litleResponse
460
+ * @throws Mage_Payment_Model_Info_Exception
461
+ * @return boolean
462
+ */
463
+ public function processResponse(Varien_Object $payment, $litleResponse)
464
+ {
465
+ $this->accountUpdater($payment, $litleResponse);
466
+
467
+ $message = XmlParser::getAttribute($litleResponse, 'litleOnlineResponse', 'message');
468
+ if ($message == 'Valid Format') {
469
+ $isSale = ($payment->getCcTransId() != null) ? false : true;
470
+ if (isset($litleResponse)) {
471
+ $litleResponseCode = XMLParser::getNode($litleResponse, 'response');
472
+ if ($litleResponseCode != '000') {
473
+ // Mage::throwException('response code is: ' .
474
+ // $litleResponseCode . 'txn type is: ');
475
+ if (($litleResponseCode === '362') && Mage::helper('creditcard')->isStateOfOrderEqualTo(
476
+ $payment->getOrder(), Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE)) {
477
+ Mage::throwException('The void did not go through. Do a refund instead.');
478
+ } else {
479
+ $payment->setStatus('Rejected')
480
+ ->setCcTransId(XMLParser::getNode($litleResponse, 'litleTxnId'))
481
+ ->setLastTransId(XMLParser::getNode($litleResponse, 'litleTxnId'))
482
+ ->setTransactionId(XMLParser::getNode($litleResponse, 'litleTxnId'))
483
+ ->setIsTransactionClosed(0)
484
+ ->setTransactionAdditionalInfo('additional_information',
485
+ XMLParser::getNode($litleResponse, 'message'));
486
+
487
+ if ($isSale)
488
+ throw new Mage_Payment_Model_Info_Exception(
489
+ Mage::helper('core')->__(
490
+ 'Transaction was not approved. Contact us or try again later.'));
491
  else
492
+ throw new Mage_Payment_Model_Info_Exception(
493
+ Mage::helper('core')->__(
494
+ 'Transaction was not approved. Contact Litle or try again later.'));
495
  }
496
+ } else {
497
+ $payment->setStatus('Approved')
498
+ ->setCcTransId(XMLParser::getNode($litleResponse, 'litleTxnId'))
499
+ ->setLastTransId(XMLParser::getNode($litleResponse, 'litleTxnId'))
500
+ ->setTransactionId(XMLParser::getNode($litleResponse, 'litleTxnId'))
501
+ ->setIsTransactionClosed(0)
502
+ ->setTransactionAdditionalInfo('additional_information',
503
+ XMLParser::getNode($litleResponse, 'message'));
 
 
 
504
  }
505
  return true;
506
  }
507
+ } else {
 
508
  Mage::throwException($message);
509
  }
 
 
510
  }
511
+
512
  /**
513
+ * this method is called if we are just authorising a transaction
 
514
  */
515
  public function authorize(Varien_Object $payment, $amount)
516
  {
517
+ // @TODO This is the wrong way to do this.
518
+ if (preg_match('/sales_order_create/i', $_SERVER['REQUEST_URI']) &&
519
+ ($this->getConfigData('paypage_enable') == '1')) {
520
+ $payment->setStatus('N/A')
521
+ ->setCcTransId('Litle VT')
522
+ ->setLastTransId('Litle VT')
523
+ ->setTransactionId('Litle VT')
524
+ ->setIsTransactionClosed(0)
525
+ ->setCcType('Litle VT');
526
+ } else {
 
527
  $order = $payment->getOrder();
528
+ $orderId = $order->getIncrementId();
529
+ $amountToPass = Mage::helper('creditcard')->formatAmount($amount, true);
530
+
531
+ if (! empty($order)) {
532
+ $info = $this->getInfoInstance();
533
+ if (!$info->getAdditionalInformation('orderSource')) {
534
+ $info->setAdditionalInformation('orderSource', 'ecommerce');
535
+ }
536
+
537
  $hash = array(
538
+ 'orderId' => $orderId,
539
+ 'amount' => $amountToPass,
540
+ 'orderSource' => $info->getAdditionalInformation('orderSource'),
541
+ 'billToAddress' => $this->getBillToAddress($payment),
542
+ 'shipToAddress' => $this->getAddressInfo($payment),
543
+ 'cardholderAuthentication' => $this->getFraudCheck($payment),
544
+ 'enhancedData' => $this->getEnhancedData($payment),
545
+ 'customBilling' => $this->getCustomBilling(
546
+ Mage::app()->getStore()
547
+ ->getBaseUrl())
548
  );
549
+
550
+
551
+
552
  $payment_hash = $this->creditCardOrPaypageOrToken($payment);
553
+ $hash_temp = array_merge($hash, $payment_hash);
554
  $merchantData = $this->merchantData($payment);
555
+ $hash_in = array_merge($hash_temp, $merchantData);
556
+
557
  $litleRequest = new LitleOnlineRequest();
558
  $litleResponse = $litleRequest->authorizationRequest($hash_in);
559
+ $this->processResponse($payment, $litleResponse);
560
+
561
+ Mage::helper('palorus')->saveCustomerInsight($payment, $litleResponse);
562
+ if (!is_null($info->getAdditionalInformation('cc_should_save'))) {
563
+ $this->_saveToken($payment, $litleResponse);
564
+ }
565
  }
566
  }
567
+
568
+ return $this;
569
  }
570
 
571
  /**
572
+ * this method is called if we are authorising AND capturing a transaction
 
573
  */
574
+ public function capture(Varien_Object $payment, $amount)
575
  {
576
+ if (preg_match('/sales_order_create/i', $_SERVER['REQUEST_URI']) &&
577
+ ($this->getConfigData('paypage_enable') == '1')) {
578
+ $payment->setStatus('N/A')
579
+ ->setCcTransId('Litle VT')
580
+ ->setLastTransId('Litle VT')
581
+ ->setTransactionId('Litle VT')
582
+ ->setIsTransactionClosed(0)
583
+ ->setCcType('Litle VT');
 
584
 
585
  return;
586
  }
587
 
588
+ $this->isFromVT($payment, 'capture');
589
 
590
  $order = $payment->getOrder();
591
+ if (! empty($order)) {
592
+ $info = $this->getInfoInstance();
593
+ if (!$info->getAdditionalInformation('orderSource')) {
594
+ $info->setAdditionalInformation('orderSource', 'ecommerce');
595
+ }
596
 
597
+ $orderId = $order->getIncrementId();
598
+ $amountToPass = Mage::helper('creditcard')->formatAmount($amount, true);
599
+ $isPartialCapture = ($amount < $order->getGrandTotal()) ? 'true' : 'false';
600
+ $isSale = ($payment->getCcTransId() != null) ? false : true;
601
 
602
+ if (! $isSale) {
 
603
  $hash = array(
604
+ 'litleTxnId' => $payment->getParentTransactionId(),
605
+ 'amount' => $amountToPass,
606
+ 'partial' => $isPartialCapture
607
  );
608
  } else {
609
  $hash_temp = array(
610
+ 'orderId' => $orderId,
611
+ 'amount' => $amountToPass,
612
+ 'orderSource' => $info->getAdditionalInformation('orderSource'),
613
+ 'billToAddress' => $this->getBillToAddress($payment),
614
+ 'shipToAddress' => $this->getAddressInfo($payment),
615
+ 'enhancedData' => $this->getEnhancedData($payment)
616
  );
617
  $payment_hash = $this->creditCardOrPaypageOrToken($payment);
618
+ $hash = array_merge($hash_temp, $payment_hash);
619
  }
620
  $merchantData = $this->merchantData($payment);
621
+ $hash_in = array_merge($hash, $merchantData);
622
  $litleRequest = new LitleOnlineRequest();
623
 
624
+ if ($isSale) {
 
625
  $litleResponse = $litleRequest->saleRequest($hash_in);
626
+ Mage::helper('palorus')->saveCustomerInsight($payment, $litleResponse);
 
627
  } else {
628
  $litleResponse = $litleRequest->captureRequest($hash_in);
629
  }
630
+
631
+ if (! is_null($info->getAdditionalInformation('cc_should_save'))) {
632
+ $this->_saveToken($payment, $litleResponse);
633
+ }
634
  }
635
+ $this->processResponse($payment, $litleResponse);
636
+
637
+ return $this;
638
  }
639
 
640
  /**
641
  * called if refunding
642
  */
643
+ public function refund(Varien_Object $payment, $amount)
644
  {
645
+ $this->isFromVT($payment, 'refund');
646
+
647
  $order = $payment->getOrder();
648
  $isPartialRefund = ($amount < $order->getGrandTotal()) ? true : false;
649
+
650
+ $amountToPass = Mage::helper('creditcard')->formatAmount($amount, true);
651
+ if (! empty($order)) {
652
+ $hash = array(
653
+ 'litleTxnId' => $payment->getCcTransId(),
654
+ 'amount' => $amountToPass
655
+ );
656
+ $merchantData = $this->merchantData($payment);
657
+ $hash_in = array_merge($hash, $merchantData);
658
+ $litleRequest = new LitleOnlineRequest();
659
+ $litleResponse = $litleRequest->creditRequest($hash_in);
660
+ }
661
+ $this->processResponse($payment, $litleResponse);
662
+
663
  return $this;
664
  }
665
 
666
  /**
667
  * called if voiding a payment
668
  */
669
+ public function void(Varien_Object $payment)
670
  {
671
+ $this->isFromVT($payment, 'void');
672
 
673
  $order = $payment->getOrder();
674
+ if (! empty($order)) {
675
  $hash = array(
676
+ 'litleTxnId' => $payment->getCcTransId()
677
  );
678
  $merchantData = $this->merchantData($payment);
679
+ $hash_in = array_merge($hash, $merchantData);
680
  $litleRequest = new LitleOnlineRequest();
681
+
682
+ if (Mage::helper('creditcard')->isStateOfOrderEqualTo($order,
683
+ Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH)) {
684
  $litleResponse = $litleRequest->authReversalRequest($hash_in);
685
+ } else {
686
+ $litleResponse = $litleRequest->voidRequest($hash_in);
687
+ }
688
  }
689
+ $this->processResponse($payment, $litleResponse);
690
+
691
+ return $this;
692
  }
693
+
694
  public function cancel(Varien_Object $payment)
695
  {
696
  $this->void($payment);
 
697
 
698
+
699
+ return $this;
700
+ }
701
  }
app/code/local/Litle/CreditCard/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Litle_CreditCard>
5
- <version>8.13.2</version>
6
  </Litle_CreditCard>
7
  </modules>
8
  <global>
2
  <config>
3
  <modules>
4
  <Litle_CreditCard>
5
+ <version>8.13.3</version>
6
  </Litle_CreditCard>
7
  </modules>
8
  <global>
app/code/local/Litle/CreditCard/etc/system.xml CHANGED
@@ -111,31 +111,42 @@
111
  <paypage_id translate="label">
112
  <label>Paypage Id</label>
113
  <frontend_type>text</frontend_type>
114
- <sort_order>10</sort_order>
115
  <show_in_default>1</show_in_default>
116
  <show_in_website>1</show_in_website>
117
  <show_in_store>0</show_in_store>
 
118
  </paypage_id>
119
  <paypage_url translate="label">
120
  <label>Paypage Merchant URL</label>
121
  <frontend_type>text</frontend_type>
122
- <sort_order>10</sort_order>
123
  <show_in_default>1</show_in_default>
124
  <show_in_website>1</show_in_website>
125
  <show_in_store>0</show_in_store>
 
126
  </paypage_url>
127
  <paypage_enable translate="label">
128
  <label>Paypage Enabled</label>
129
  <frontend_type>select</frontend_type>
130
  <source_model>adminhtml/system_config_source_yesno</source_model>
131
- <sort_order>10</sort_order>
132
  <show_in_default>1</show_in_default>
133
  <show_in_website>1</show_in_website>
134
  <show_in_store>0</show_in_store>
135
  </paypage_enable>
 
 
 
 
 
 
 
 
 
136
  </fields>
137
  </CreditCard>
138
  </groups>
139
  </payment>
140
  </sections>
141
- </config>
111
  <paypage_id translate="label">
112
  <label>Paypage Id</label>
113
  <frontend_type>text</frontend_type>
114
+ <sort_order>101</sort_order>
115
  <show_in_default>1</show_in_default>
116
  <show_in_website>1</show_in_website>
117
  <show_in_store>0</show_in_store>
118
+ <depends><paypage_enable>1</paypage_enable></depends>
119
  </paypage_id>
120
  <paypage_url translate="label">
121
  <label>Paypage Merchant URL</label>
122
  <frontend_type>text</frontend_type>
123
+ <sort_order>101</sort_order>
124
  <show_in_default>1</show_in_default>
125
  <show_in_website>1</show_in_website>
126
  <show_in_store>0</show_in_store>
127
+ <depends><paypage_enable>1</paypage_enable></depends>
128
  </paypage_url>
129
  <paypage_enable translate="label">
130
  <label>Paypage Enabled</label>
131
  <frontend_type>select</frontend_type>
132
  <source_model>adminhtml/system_config_source_yesno</source_model>
133
+ <sort_order>100</sort_order>
134
  <show_in_default>1</show_in_default>
135
  <show_in_website>1</show_in_website>
136
  <show_in_store>0</show_in_store>
137
  </paypage_enable>
138
+ <vault_enable translate="label">
139
+ <label>Vault Enabled</label>
140
+ <frontend_type>select</frontend_type>
141
+ <source_model>adminhtml/system_config_source_yesno</source_model>
142
+ <sort_order>110</sort_order>
143
+ <show_in_default>1</show_in_default>
144
+ <show_in_website>1</show_in_website>
145
+ <show_in_store>0</show_in_store>
146
+ </vault_enable>
147
  </fields>
148
  </CreditCard>
149
  </groups>
150
  </payment>
151
  </sections>
152
+ </config>
app/code/local/Litle/LEcheck/Block/Form/LEcheck.php CHANGED
@@ -4,7 +4,7 @@ class Litle_LEcheck_Block_Form_LEcheck extends Mage_Payment_Block_Form
4
  protected function _construct()
5
  {
6
  parent::_construct();
7
- $this->setTemplate('payment/form/litleecheck.phtml');
8
  }
9
 
10
  public function getAccountAvailableTypes()
@@ -23,4 +23,4 @@ class Litle_LEcheck_Block_Form_LEcheck extends Mage_Payment_Block_Form
23
  }
24
  return $types;
25
  }
26
- }
4
  protected function _construct()
5
  {
6
  parent::_construct();
7
+ $this->setTemplate('litle/form/litleecheck.phtml');
8
  }
9
 
10
  public function getAccountAvailableTypes()
23
  }
24
  return $types;
25
  }
26
+ }
app/code/local/Litle/LEcheck/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Litle_LEcheck>
5
- <version>8.13.2</version>
6
  </Litle_LEcheck>
7
  </modules>
8
  <global>
2
  <config>
3
  <modules>
4
  <Litle_LEcheck>
5
+ <version>8.13.3</version>
6
  </Litle_LEcheck>
7
  </modules>
8
  <global>
app/code/local/Litle/LitleSDK/Obj2xml.php CHANGED
@@ -62,14 +62,14 @@ class Obj2xml {
62
  {
63
  if ($value === "REQUIRED"){
64
  throw new InvalidArgumentException("Missing Required Field: /$key/");
65
- }elseif (substr($key,0,-1) == 'lineItemData'){
66
  $temp_node = $transacType->addChild('lineItemData');
67
  Obj2xml::iterateChildren($value,$temp_node);
68
  }elseif (substr($key,0,-1) == 'detailTax'){
69
  $temp_node = $transacType->addChild('detailTax');
70
  Obj2xml::iterateChildren($value,$temp_node);
71
  }elseif (((is_string($value)) || is_numeric($value))) {
72
- $transacType->addChild($key,$value);
73
  }elseif(is_array($value))
74
  {
75
  $node = $transacType->addChild($key);
62
  {
63
  if ($value === "REQUIRED"){
64
  throw new InvalidArgumentException("Missing Required Field: /$key/");
65
+ }elseif (substr($key, 0, 12) === 'lineItemData'){
66
  $temp_node = $transacType->addChild('lineItemData');
67
  Obj2xml::iterateChildren($value,$temp_node);
68
  }elseif (substr($key,0,-1) == 'detailTax'){
69
  $temp_node = $transacType->addChild('detailTax');
70
  Obj2xml::iterateChildren($value,$temp_node);
71
  }elseif (((is_string($value)) || is_numeric($value))) {
72
+ $transacType->addChild($key,str_replace('&','&amp;',$value));
73
  }elseif(is_array($value))
74
  {
75
  $node = $transacType->addChild($key);
app/code/local/Litle/Palorus/Block/Adminhtml/Customer/Edit/Tab/Vault.php ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Litle Vault Info block
5
+ *
6
+ * @author jholden
7
+ */
8
+ class Litle_Palorus_Block_Adminhtml_Customer_Edit_Tab_Vault
9
+ extends Mage_Adminhtml_Block_Template
10
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
11
+ {
12
+
13
+ protected function _construct()
14
+ {
15
+ parent::_construct();
16
+ $this->setTemplate('litle/customer/tab/vault.phtml');
17
+ }
18
+
19
+ /**
20
+ * Returns the registry customer.
21
+ *
22
+ * @return Mage_Customer_Model_Customer
23
+ */
24
+ public function getCustomer()
25
+ {
26
+ return Mage::registry('current_customer');
27
+ }
28
+
29
+ /**
30
+ * Returns a collection of vaulted cards for the registry customer.
31
+ *
32
+ * @return Litle_Palorus_Model_Mysql4_Vault_Collection
33
+ */
34
+ public function getStoredCards()
35
+ {
36
+ return Mage::getModel('palorus/vault')->getCollection()->addCustomerFilter($this->getCustomer());
37
+ }
38
+
39
+ /**
40
+ * URL to delete a stored card.
41
+ *
42
+ * @param Litle_Palorus_Model_Vault $card
43
+ * @return string
44
+ */
45
+ public function getCardDeleteUrl(Litle_Palorus_Model_Vault $card)
46
+ {
47
+ $params = array(
48
+ 'customer_id' => $this->getCustomer()->getId(),
49
+ 'vault_id' => $card->getId()
50
+ );
51
+ return $this->getUrl('palorus/adminhtml_vault/deleteCard', $params);
52
+ }
53
+
54
+ /**
55
+ * Retrieve the label used for the tab relating to this block
56
+ *
57
+ * @return string
58
+ */
59
+ public function getTabLabel()
60
+ {
61
+ return $this->__('Litle Stored Cards');
62
+ }
63
+
64
+ /**
65
+ * Retrieve the title used by this tab
66
+ *
67
+ * @return string
68
+ */
69
+ public function getTabTitle()
70
+ {
71
+ return $this->__('Click here to view stored cards for this customer');
72
+ }
73
+
74
+ /**
75
+ * Determines whether to display the tab
76
+ * Add logic here to decide whether you want the tab to display
77
+ *
78
+ * @return bool
79
+ */
80
+ public function canShowTab()
81
+ {
82
+ return true;
83
+ }
84
+
85
+ /**
86
+ * Stops the tab being hidden
87
+ *
88
+ * @return bool
89
+ */
90
+ public function isHidden()
91
+ {
92
+ return false;
93
+ }
94
+ }
app/code/local/Litle/Palorus/Block/Vault.php ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Stored card rendering block
4
+ */
5
+ class Litle_Palorus_Block_Vault extends Mage_Core_Block_Abstract
6
+ {
7
+ /**
8
+ * @var array
9
+ */
10
+ protected $_params = array();
11
+
12
+ /**
13
+ * Renders the block.
14
+ *
15
+ * @return string
16
+ */
17
+ protected function _toHtml ()
18
+ {
19
+ if ($this->getPaymentProfile() && $this->getType()) {
20
+ switch ($this->getType()) {
21
+ case 'oneline':
22
+ return $this->_getOneline();
23
+ case 'json':
24
+ return $this->_getJson();
25
+ case 'html':
26
+ return $this->_getHtml();
27
+ }
28
+ }
29
+ return '';
30
+ }
31
+
32
+ /**
33
+ * Sets rendering params.
34
+ *
35
+ * Supported params:
36
+ * show_exp_date
37
+ * container_tag
38
+ *
39
+ * @param array $params
40
+ * @return Litle_Palorus_Block_Vault
41
+ */
42
+ public function setParams (array $params)
43
+ {
44
+ $this->_params = $params;
45
+ return $this;
46
+ }
47
+
48
+ /**
49
+ * Param getter.
50
+ *
51
+ * @param string $param
52
+ * @return mixed
53
+ */
54
+ public function getParam ($param)
55
+ {
56
+ return isset($this->_params[$param]) ? $this->_params[$param] : false;
57
+ }
58
+
59
+ /**
60
+ * @return string
61
+ */
62
+ protected function _getOneline ()
63
+ {
64
+ $profile = $this->getPaymentProfile();
65
+ $str = Mage::helper('palorus')->__(
66
+ 'Card Type: %s, xxxx-%s, Exp: %s/%s',
67
+ $profile->getType(),
68
+ $profile->getLast4(),
69
+ $profile->getExpirationMonth(),
70
+ $profile->getExpirationYear()
71
+ );
72
+ return $str;
73
+ }
74
+
75
+ /**
76
+ * @return string
77
+ */
78
+ protected function _getJson ()
79
+ {
80
+ $profile = $this->getPaymentProfile();
81
+ return Mage::helper('core')->jsonEncode($profile->getData());
82
+ }
83
+
84
+ /**
85
+ * @return string
86
+ */
87
+ protected function _getHtml ()
88
+ {
89
+ $profile = $this->getPaymentProfile();
90
+ $tag = $this->getParam('container_tag') ? $this->getParam('container_tag') : 'address';
91
+
92
+ $str = '<' . $tag . '>';
93
+ if ($profile->getCardType()) {
94
+ $str .= Mage::helper('palorus')->__('Card Type: %s<br />', $profile->getType());
95
+ }
96
+ $str .= Mage::helper('palorus')->__('Card Number: XXXX-%s<br />', $profile->getLast4());
97
+
98
+ if ($this->getParam('show_exp_date')) {
99
+ $str .= Mage::helper('palorus')->__('Expiration: %s/%s<br />', $profile->getExpirationMonth(), $profile->getExpirationYear());
100
+ }
101
+ $str = $str . '</' . $tag . '>';
102
+
103
+ return $str;
104
+ }
105
+ }
app/code/local/Litle/Palorus/Block/Vault/List.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Litle_Palorus_Block_Vault_List extends Mage_Core_Block_Template
4
+ {
5
+
6
+ /**
7
+ * Retrieve customer model
8
+ *
9
+ * @return Mage_Customer_Model_Customer
10
+ */
11
+ public function getCustomer()
12
+ {
13
+ return Mage::getSingleton('customer/session')->getCustomer();
14
+ }
15
+
16
+ /**
17
+ * Returns an array of stored cards.
18
+ *
19
+ * @return array
20
+ */
21
+ public function getStoredCards()
22
+ {
23
+ if (!$this->hasData('stored_cards')) {
24
+ $cards = Mage::getModel('palorus/vault')->visibleStoredCards($this->getCustomer()
25
+ ->getId());
26
+
27
+ $this->setStoredCards($cards);
28
+ }
29
+ return $this->getData('stored_cards');
30
+ }
31
+
32
+ /**
33
+ *
34
+ * @return string
35
+ */
36
+ public function getDeleteUrl()
37
+ {
38
+ return $this->getUrl('*/*/delete');
39
+ }
40
+
41
+ /**
42
+ *
43
+ * @todo New card url
44
+ * @return string
45
+ */
46
+ // public function getAddUrl()
47
+ // {
48
+ // return $this->getUrl('*/*/new');
49
+ // }
50
+
51
+ /**
52
+ *
53
+ * @todo Edit card url
54
+ * @param OnePica_AuthnetCim_Model_PaymentProfile $profile
55
+ * @return string
56
+ */
57
+ // public function getEditUrl(OnePica_AuthnetCim_Model_PaymentProfile
58
+ // $profile)
59
+ // {
60
+ // return $this->getUrl('*/*/edit', array(
61
+ // 'profile_id' => $profile->getId()
62
+ // ));
63
+ // }
64
+ }
app/code/local/Litle/Palorus/Helper/Data.php CHANGED
@@ -1,128 +1,210 @@
1
- <?php
2
-
3
-
4
- class Litle_Palorus_Helper_Data extends Mage_Core_Helper_Abstract
5
- {
6
-
7
- public function saveCustomerInsight($payment, $litleResponse) {