MindArc_FatZebra - Version 2.1.1

Version Notes

This release fixed issues with floating point conversions and client side issues around validation requirements for checkboxes.

In addition to this support for GoMage Lightcheckout has also been added.

Download this release

Release Info

Developer Matthew Savage
Extension MindArc_FatZebra
Version 2.1.1
Comparing to
See all releases


Version 2.1.1

Files changed (40) hide show
  1. app/code/community/MindArc/FatZebra/Block/Adminhtml/Sales/Order/Grid.php +79 -0
  2. app/code/community/MindArc/FatZebra/Block/Adminhtml/Sales/Order/View/Tab/Fraud.php +60 -0
  3. app/code/community/MindArc/FatZebra/Block/Adminhtml/Widget/Grid/Column/Renderer/Fraudresult.php +10 -0
  4. app/code/community/MindArc/FatZebra/Block/Form.php +70 -0
  5. app/code/community/MindArc/FatZebra/Block/Jsinit.php +32 -0
  6. app/code/community/MindArc/FatZebra/Helper/Data.php +5 -0
  7. app/code/community/MindArc/FatZebra/Model/Adminhtml/Comment.php +9 -0
  8. app/code/community/MindArc/FatZebra/Model/Adminhtml/Shipping/Enabledmethods.php +63 -0
  9. app/code/community/MindArc/FatZebra/Model/Cardtypes.php +12 -0
  10. app/code/community/MindArc/FatZebra/Model/Customer.php +60 -0
  11. app/code/community/MindArc/FatZebra/Model/Entity/Setup.php +3 -0
  12. app/code/community/MindArc/FatZebra/Model/Filterfraud.php +20 -0
  13. app/code/community/MindArc/FatZebra/Model/Fraud.php +13 -0
  14. app/code/community/MindArc/FatZebra/Model/Mysql4/Fraud.php +10 -0
  15. app/code/community/MindArc/FatZebra/Model/Observer.php +27 -0
  16. app/code/community/MindArc/FatZebra/Model/Payment.php +584 -0
  17. app/code/community/MindArc/FatZebra/Model/Source/Action.php +14 -0
  18. app/code/community/MindArc/FatZebra/controllers/IndexController.php +21 -0
  19. app/code/community/MindArc/FatZebra/etc/config.xml +154 -0
  20. app/code/community/MindArc/FatZebra/etc/system.xml +222 -0
  21. app/code/community/MindArc/FatZebra/sql/fatzebra_setup/mysql4-install-0.1.1-2.0.5.php +20 -0
  22. app/code/community/MindArc/FatZebra/sql/fatzebra_setup/mysql4-upgrade-2.0.5-2.0.6.php +33 -0
  23. app/design/adminhtml/default/default/layout/fatzebra.xml +16 -0
  24. app/design/adminhtml/default/default/template/fatzebra/jsinit.phtml +12 -0
  25. app/design/adminhtml/default/default/template/fatzebra/tab.phtml +44 -0
  26. app/design/frontend/base/default/layout/fatzebra.xml +33 -0
  27. app/design/frontend/base/default/template/mindarc/fatzebra/empty.phtml +8 -0
  28. app/design/frontend/base/default/template/mindarc/fatzebra/form.phtml +135 -0
  29. app/design/frontend/base/default/template/mindarc/fatzebra/info.phtml +8 -0
  30. app/etc/modules/MindArc_Fatzebra.xml +12 -0
  31. js/fatzebra/fatzebra.js +351 -0
  32. media/payments/AE.png +0 -0
  33. media/payments/DI.png +0 -0
  34. media/payments/DIS.png +0 -0
  35. media/payments/Fat-Zebra-Certified-small.png +0 -0
  36. media/payments/JCB.png +0 -0
  37. media/payments/MC.png +0 -0
  38. media/payments/VI.png +0 -0
  39. media/payments/mindarc.png +0 -0
  40. package.xml +23 -0
app/code/community/MindArc/FatZebra/Block/Adminhtml/Sales/Order/Grid.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class MindArc_FatZebra_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid {
4
+
5
+
6
+ public function addAfterColumn($columnId, $column, $indexColumn) {
7
+ $columns = array();
8
+ foreach ($this->_columns as $gridColumnKey => $gridColumn) {
9
+ $columns[$gridColumnKey] = $gridColumn;
10
+ if ($gridColumnKey == $indexColumn) {
11
+ $columns[$columnId] = $this->getLayout()->createBlock('adminhtml/widget_grid_column')
12
+ ->setData($column)
13
+ ->setGrid($this);
14
+ $columns[$columnId]->setId($columnId);
15
+ }
16
+ }
17
+ $this->_columns = $columns;
18
+ return $this;
19
+ }
20
+
21
+ protected function _prepareColumns() {
22
+ $return = parent::_prepareColumns();
23
+
24
+ $this->addAfterColumn('fraud_result', array(
25
+ 'header' => Mage::helper('sales')->__('Fraud Detected'),
26
+ 'width' => '15px',
27
+ 'type' => 'options',
28
+ 'index' => 'fraud_result',
29
+ 'filter_condition_callback' => array($this, '_filterFraudResult'),
30
+ 'align' => 'center',
31
+ 'filter' => 'adminhtml/widget_grid_column_filter_select',
32
+ 'options' => Mage::getSingleton('fatzebra/filterfraud')->getFilter(),
33
+ 'renderer' => 'MindArc_FatZebra_Block_Adminhtml_Widget_Grid_Column_Renderer_Fraudresult',
34
+ ), 'status');
35
+
36
+ return $return;
37
+ }
38
+
39
+ public function setCollection($collection) {
40
+
41
+ // 1.6.1
42
+ if ($collection instanceof Mage_Sales_Model_Resource_Order_Grid_Collection) {
43
+
44
+ $collection->getSelect()
45
+ ->joinLeft(array('fatzebrafraud_data' => $collection->getTable('fatzebra/fraud')), 'fatzebrafraud_data.order_id=main_table.entity_id', 'fraud_result');
46
+ } else if ($collection instanceof Mage_Core_Model_Mysql4_Collection_Abstract) { // 1.4.1
47
+
48
+ $collection->getSelect()
49
+ ->joinLeft(array('fatzebrafraud_data' => $collection->getTable('fatzebra/fraud')), 'fatzebrafraud_data.order_id=main_table.entity_id', 'fraud_result');
50
+ } else if ($collection instanceof Mage_Eav_Model_Entity_Collection_Abstract) {
51
+
52
+ $collection->joinTable('fatzebra/fraud', 'order_id=entity_id', array("fraud_result" => "fraud_result"), null, "left");
53
+ }
54
+
55
+ return parent::setCollection($collection);
56
+ }
57
+
58
+ protected function _filterFraudResult($collection, $column) {
59
+
60
+
61
+ // 1.6.1
62
+ if ($collection instanceof Mage_Sales_Model_Resource_Order_Grid_Collection) {
63
+
64
+ // we have to change this so the join doesn't get reset
65
+ $collection->addFieldToFilter('`fatzebrafraud_data`.fraud_result', $column->getFilter()->getCondition());
66
+ // 1.4.1
67
+ } else if ($collection instanceof Mage_Core_Model_Mysql4_Collection_Abstract) {
68
+
69
+
70
+ // we have to change this so the join doesn't get reset
71
+ $collection->addFieldToFilter('`fatzebrafraud_data`.fraud_result', $column->getFilter()->getCondition());
72
+ } else {
73
+
74
+
75
+ $collection->addFieldToFilter($column->getIndex(), $column->getFilter()->getCondition());
76
+ }
77
+ }
78
+
79
+ }
app/code/community/MindArc/FatZebra/Block/Adminhtml/Sales/Order/View/Tab/Fraud.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class MindArc_FatZebra_Block_Adminhtml_Sales_Order_View_Tab_Fraud
4
+ extends Mage_Adminhtml_Block_Sales_Order_Abstract
5
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
6
+ {
7
+
8
+ protected function _construct()
9
+ {
10
+ parent::_construct();
11
+ $this->setTemplate('fatzebra/tab.phtml');
12
+ }
13
+
14
+ /**
15
+ * Retrieve order model instance
16
+ *
17
+ * @return Mage_Sales_Model_Order
18
+ */
19
+ public function getOrder()
20
+ {
21
+ return Mage::registry('current_order');
22
+ }
23
+
24
+ public function getFraudResult()
25
+ {
26
+ $order = $this->getOrder();
27
+ $result = Mage::getModel('frauddetection/result')->loadByOrderId($order->getId());
28
+ $res = @unserialize(utf8_decode($result->getFraudData()));
29
+ return $res;
30
+ }
31
+
32
+ public function getCustomer()
33
+ {
34
+ $customer = Mage::getModel('customer/customer')->load($this->getOrder()->getCustomerId());
35
+ return $customer;
36
+ }
37
+
38
+ /**
39
+ * ######################## TAB settings #################################
40
+ */
41
+ public function getTabLabel()
42
+ {
43
+ return Mage::helper('sales')->__('Retail Decisions Fraud Detected');
44
+ }
45
+
46
+ public function getTabTitle()
47
+ {
48
+ return Mage::helper('sales')->__('Retail Decisions Fraud Detected');
49
+ }
50
+
51
+ public function canShowTab()
52
+ {
53
+ return true;
54
+ }
55
+
56
+ public function isHidden()
57
+ {
58
+ return false;
59
+ }
60
+ }
app/code/community/MindArc/FatZebra/Block/Adminhtml/Widget/Grid/Column/Renderer/Fraudresult.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class MindArc_FatZebra_Block_Adminhtml_Widget_Grid_Column_Renderer_Fraudresult extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {
4
+
5
+ public function render(Varien_Object $row) {
6
+ return $row->getFraudResult()!=""?$row->getFraudResult():"";
7
+
8
+ }
9
+
10
+ }
app/code/community/MindArc/FatZebra/Block/Form.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class MindArc_FatZebra_Block_Form extends Mage_Payment_Block_Form_Cc
3
+ {
4
+ protected function _construct()
5
+ {
6
+ parent::_construct();
7
+ $this->setTemplate('mindarc/fatzebra/form.phtml');
8
+ }
9
+
10
+ public function canSave() {
11
+ $cansave = Mage::getStoreConfig('payment/fatzebra/can_save');
12
+ $isLoggedIn = Mage::getSingleton('customer/session')->isLoggedIn();
13
+ $isRegister= Mage::getSingleton('checkout/type_onepage')->getCheckoutMethod() == "register";
14
+
15
+
16
+ return ($cansave && ($isLoggedIn || $isRegister));
17
+ }
18
+ public function hasCustomerToken(){
19
+ $fatzebraCustomer = Mage::getModel('fatzebra/customer');
20
+ return $fatzebraCustomer->getCustomerToken();
21
+ }
22
+ public function getMaskedCardNumber() {
23
+ $fatzebraCustomer = Mage::getModel('fatzebra/customer');
24
+ return $fatzebraCustomer->getMaskedCardNumber();
25
+ }
26
+
27
+ public function getSavedCardExpiryDate() {
28
+ $fatzebraCustomer = Mage::getModel('fatzebra/customer');
29
+ return date_parse($fatzebraCustomer->getSavedCardExpiryDate());
30
+ }
31
+
32
+ public function getSavedCardNotExpired() {
33
+ $fatzebraCustomer = Mage::getModel('fatzebra/customer');
34
+ $date = date_parse($fatzebraCustomer->getSavedCardExpiryDate());
35
+ return ($date['year'] > date('Y')) || (
36
+ $date['year'] == date('Y') && $date['month'] >= date('m')
37
+ );
38
+ }
39
+
40
+ public function getStoredCardType() {
41
+ $number = $this->getMaskedCardNumber();
42
+
43
+ $prefix = substr($number, 0, 2);
44
+ switch(substr($prefix, 0, 1)) {
45
+ case '4':
46
+ return 'VI';
47
+ break;
48
+ case '5':
49
+ return 'MC';
50
+ break;
51
+ case '6':
52
+ return 'DI';
53
+ break;
54
+ case '3':
55
+ switch(substr($prefix, 1, 1)) {
56
+ case '4':
57
+ case '7':
58
+ return 'AE';
59
+ break;
60
+ case '6':
61
+ return 'DIC';
62
+ break;
63
+ case '5':
64
+ return 'JCB';
65
+ break;
66
+ }
67
+ break;
68
+ }
69
+ }
70
+ }
app/code/community/MindArc/FatZebra/Block/Jsinit.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class MindArc_FatZebra_Block_Jsinit extends Mage_Adminhtml_Block_Template
4
+ {
5
+ /**
6
+ * Include JS in head if section is fatzebra
7
+ */
8
+ protected function _prepareLayout()
9
+ {
10
+ $section = $this->getAction()->getRequest()->getParam('section', false);
11
+ if ($section == 'payment') {
12
+ $this->getLayout()
13
+ ->getBlock('head')
14
+ ->addJs('fatzebra/fatzebra.js');
15
+ }
16
+ parent::_prepareLayout();
17
+ }
18
+
19
+ /**
20
+ * Print init JS script into body
21
+ * @return string
22
+ */
23
+ protected function _toHtml()
24
+ {
25
+ $section = $this->getAction()->getRequest()->getParam('section', false);
26
+ if ($section == 'payment') {
27
+ return parent::_toHtml();
28
+ } else {
29
+ return '';
30
+ }
31
+ }
32
+ }
app/code/community/MindArc/FatZebra/Helper/Data.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ class MindArc_FatZebra_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+
5
+ }
app/code/community/MindArc/FatZebra/Model/Adminhtml/Comment.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class MindArc_FatZebra_Model_Adminhtml_Comment
3
+ {
4
+
5
+ public function getCommentText(){ //this method must exits. It returns the text for the comment
6
+ return "Some text here";
7
+ }
8
+ }
9
+ ?>
app/code/community/MindArc/FatZebra/Model/Adminhtml/Shipping/Enabledmethods.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Adminhtml
23
+ * @copyright Copyright (c) 2014 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
+ class MindArc_FatZebra_Model_Adminhtml_Shipping_Enabledmethods // extends Mage_Adminhtml_Model_System_Config_Source_Shipping_Allmethods
28
+ {
29
+ /**
30
+ * Return array of carriers.
31
+ * If $isActiveOnlyFlag is set to true, will return only active carriers
32
+ *
33
+ * @param bool $isActiveOnlyFlag
34
+ * @return array
35
+ */
36
+ public function toOptionArray($isActiveOnlyFlag = true)
37
+ {
38
+ $methods = array(array('value'=>'', 'label'=>''));
39
+ $carriers = Mage::getSingleton('shipping/config')->getAllCarriers();
40
+ foreach ($carriers as $carrierCode=>$carrierModel) {
41
+ if (!$carrierModel->isActive()) {
42
+ continue;
43
+ }
44
+ $carrierMethods = $carrierModel->getAllowedMethods();
45
+ if (!$carrierMethods) {
46
+ continue;
47
+ }
48
+ $carrierTitle = Mage::getStoreConfig('carriers/'.$carrierCode.'/title');
49
+ $methods[$carrierCode] = array(
50
+ 'label' => $carrierTitle,
51
+ 'value' => array(),
52
+ );
53
+ foreach ($carrierMethods as $methodCode=>$methodTitle) {
54
+ $methods[$carrierCode]['value'][] = array(
55
+ 'value' => $carrierCode.'_'.$methodCode,
56
+ 'label' => '['.$carrierCode.'] '.$methodTitle,
57
+ );
58
+ }
59
+ }
60
+
61
+ return $methods;
62
+ }
63
+ }
app/code/community/MindArc/FatZebra/Model/Cardtypes.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class MindArc_FatZebra_Model_CardTypes
3
+ {
4
+ public function toOptionArray() {
5
+ return array(
6
+ array("value" => "VI", "label" => "VISA"),
7
+ array("value" => "MC", "label" => "MasterCard"),
8
+ array("value" => "AE", "label" => "American Express"),
9
+ array("value" => "JCB", "label" => "JCB")
10
+ );
11
+ }
12
+ }
app/code/community/MindArc/FatZebra/Model/Customer.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Customer model
5
+ *
6
+ * @category MindArc
7
+ * @package MindArc_Fatzebra
8
+ * @author (mindarc.com.au)
9
+ *
10
+ */
11
+ class MindArc_FatZebra_Model_Customer extends Mage_Core_Model_Abstract
12
+ {
13
+ protected $_customer = null;
14
+ public function __construct() {
15
+ parent::__construct();
16
+ $customerId = Mage::getSingleton('customer/session')->getId();
17
+ $customer = Mage::getModel('customer/customer')->load($customerId);
18
+ if (is_object($customer) || $customer->getId()) {
19
+ $this->_customer = $customer;
20
+ }
21
+ }
22
+ public function saveData($result)
23
+ {
24
+ try {
25
+ if (!is_null($this->_customer)) {
26
+
27
+ $this->_customer->setData('fatzebra_token', $result->response->card_token);
28
+ $this->_customer->setData('fatzebra_masked_card_number', $result->response->card_number);
29
+ $this->_customer->setData('fatzebra_expiry_date', $result->response->card_expiry);
30
+
31
+ $this->_customer->save();
32
+ }
33
+ }
34
+ catch (Exception $e) {
35
+ Mage::throwException($e->getMessage());
36
+
37
+ }
38
+
39
+ }
40
+ public function getCustomerToken() {
41
+ if (!is_null($this->_customer)) {
42
+ return $this->_customer->getData('fatzebra_token');
43
+ }
44
+ return false;
45
+ }
46
+
47
+ public function getMaskedCardNumber() {
48
+ if (!is_null($this->_customer)) {
49
+ return $this->_customer->getData('fatzebra_masked_card_number');
50
+ }
51
+ return false;
52
+ }
53
+
54
+ public function getSavedCardExpiryDate() {
55
+ if (!is_null($this->_customer)) {
56
+ return $this->_customer->getData('fatzebra_expiry_date');
57
+ }
58
+ return false;
59
+ }
60
+ }
app/code/community/MindArc/FatZebra/Model/Entity/Setup.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+
3
+ class MindArc_FatZebra_Model_Entity_Setup extends Mage_Customer_Model_Entity_Setup {}
app/code/community/MindArc/FatZebra/Model/Filterfraud.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class MindArc_FatZebra_Model_Filterfraud extends Mage_Core_Model_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ }
9
+ public function getFilter()
10
+ {
11
+ $resource = Mage::getSingleton('core/resource');
12
+ $readConnection = $resource->getConnection('core_read');
13
+ $query = "SELECT `fraud_result` FROM `fatzebrafraud_data` GROUP BY `fraud_result` ";
14
+ $results = $readConnection->fetchAll($query);
15
+ $options = array();
16
+ foreach($results as $status)
17
+ $options[$status['fraud_result']]=$status['fraud_result'];
18
+ return $options;
19
+ }
20
+ }
app/code/community/MindArc/FatZebra/Model/Fraud.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class MindArc_FatZebra_Model_Fraud extends Mage_Core_Model_Abstract
3
+ {
4
+ public function _construct()
5
+ {
6
+ $this->_init('fatzebra/fraud');
7
+ }
8
+ function loadByOrderId($orderId)
9
+ {
10
+ $this->load($orderId, 'order_id');
11
+ return $this;
12
+ }
13
+ }
app/code/community/MindArc/FatZebra/Model/Mysql4/Fraud.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class MindArc_FatZebra_Model_Mysql4_Fraud extends Mage_Core_Model_Mysql4_Abstract
5
+ {
6
+ protected function _construct()
7
+ {
8
+ $this->_init('fatzebra/fraud', 'entity_id');
9
+ }
10
+ }
app/code/community/MindArc/FatZebra/Model/Observer.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class MindArc_FatZebra_Model_Observer
3
+ {
4
+ public function paymentMethodIsActive(Varien_Event_Observer $observer) {
5
+ $event = $observer->getEvent();
6
+ $method = $event->getMethodInstance();
7
+ $result = $event->getResult();
8
+ $fatzebraCustomer = Mage::getModel('fatzebra/customer');
9
+ if($result->isAvailable)
10
+ {
11
+ if(!$fatzebraCustomer->getCustomerToken()&&$method->getCode()=="fatzebra_saved_cc"){
12
+ $result->isAvailable = false;
13
+ }
14
+ }
15
+
16
+ }
17
+
18
+ public function handleSuccessAction(Varien_Event_Observer $observer)
19
+ {
20
+ if(Mage::getSingleton('core/session')->getFatZebraCcSave()==1){
21
+ $fatzebraCustomerModel = Mage::getModel('fatzebra/customer');
22
+ $fatzebraCustomerModel->saveData(Mage::getSingleton('core/session')->getFatZebraResult());
23
+ }
24
+ Mage::getSingleton('core/session')->unsFatZebraCcSave();
25
+ Mage::getSingleton('core/session')->unsFatZebraResult();
26
+ }
27
+ }
app/code/community/MindArc/FatZebra/Model/Payment.php ADDED
@@ -0,0 +1,584 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class MindArc_FatZebra_Model_Payment extends Mage_Payment_Model_Method_Cc
4
+ {
5
+
6
+ const VERSION = "2.1.1";
7
+
8
+ // Fraud Check Data Scrubbing...
9
+ const RE_ANS = "/[^A-Z\d\-_',\.;:\s]*/i";
10
+ const RE_AN = "/[^A-Z\d]/i";
11
+ const RE_NUMBER = "/[^\d]/";
12
+
13
+ protected $_code = 'fatzebra';
14
+ protected $_isGateway = true;
15
+ protected $_canAuthorize = true;
16
+ protected $_canCapture = true;
17
+ protected $_canCapturePartial = true;
18
+ protected $_canRefund = true;
19
+ protected $_canVoid = false;
20
+ protected $_canUseInternal = true;
21
+ protected $_canUseCheckout = true;
22
+ protected $_canUseForMultishipping = true;
23
+ protected $_canReviewPayment = true;
24
+ protected $_canSaveCc = false;
25
+ protected $_formBlockType = 'fatzebra/form';
26
+
27
+ /**
28
+ * Assign data to info model instance
29
+ *
30
+ * @param mixed $data
31
+ * @return MindArc_FatZebra_Model_Payment
32
+ */
33
+ public function assignData($data)
34
+ {
35
+ parent::assignData($data);
36
+
37
+ if (!($data instanceof Varien_Object)) {
38
+ $data = new Varien_Object($data);
39
+ }
40
+ $info = $this->getInfoInstance();
41
+ $info->setCcNumber($data->getCcNumber());
42
+ $post = Mage::app()->getFrontController()->getRequest()->getPost();
43
+ if (isset($post['payment']['cc_save'])) {
44
+ Mage::getSingleton('core/session')->setFatZebraCcSave($post['payment']['cc_save']);
45
+ }
46
+
47
+ return $this;
48
+ }
49
+
50
+ /**
51
+ * Performs a capture (full purchase transaction)
52
+ * @param $payment the payment object to process
53
+ * @param $amount the amount to be charged, as a decimal
54
+ *
55
+ * @return MindArc_FatZebra_Model_Payment
56
+ */
57
+ public function CardType($number)
58
+ {
59
+ if(preg_match("/^4/", $number))
60
+ return "VI";
61
+ if(preg_match("/^5/", $number))
62
+ return "MC";
63
+ if(preg_match("/^(34|37)/", $number))
64
+ return "AE";
65
+ if(preg_match("/^(36)/", $number))
66
+ return "DIC";
67
+ if(preg_match("/^(35)/", $number))
68
+ return "JCB";
69
+ if(preg_match("/^(65)/", $number))
70
+ return "DI";
71
+ }
72
+ public function capture(Varien_Object $payment, $amount)
73
+ {
74
+ $this->setAmount($amount)->setPayment($payment);
75
+ $info = $this->getInfoInstance();
76
+
77
+ $result = $this->process_payment($payment);
78
+ if (isset($result->successful) && $result->successful) {
79
+ if ($result->response->successful) {
80
+ if (isset($_POST['use_saved_card']) && $_POST['use_saved_card'] == 1) {
81
+ $this->getInfoInstance()->setCcOwner($result->response->card_holder)
82
+ ->setCcLast4(substr($result->response->card_number, 12))
83
+ ->setCcExpMonth(substr($result->response->card_expiry, -5, 2))
84
+ ->setCcExpYear(substr($result->response->card_expiry, 0, 4))
85
+ ->setCcType($this->CardType($result->response->card_number));
86
+
87
+ }
88
+ $order = $payment->getOrder();
89
+ if(Mage::getSingleton('core/session')->getFatZebraCcSave()==1){
90
+ Mage::getSingleton('core/session')->setFatZebraResult($result);
91
+ }
92
+ // TODO: This should set the order/payment result to 'FRAUD', whereas currently it sets the order to Processing
93
+ // However, the code below, setting to status_fraud etc doesn't seem to do anything...
94
+ // Make sure we have a fraud_result - if ReD is disabled by FZ (e.g. ReD unavailable etc) this will not be present
95
+ if (property_exists($result->response, 'fraud_result') && ($result->response->fraud_result && $result->response->fraud_result == 'Challenge')) {
96
+ //$payment->setStatus(Mage_Sales_Model_Order::STATUS_FRAUD);
97
+
98
+ $payment->setLastTransId($result->response->id);
99
+ $payment->setTransactionId($result->response->id);
100
+ $payment->registerCaptureNotification($amount, false);
101
+ $payment->setIsTransactionPending(true)
102
+ ->setIsFraudDetected(true)
103
+ ->setSkipTransactionCreation(true)
104
+ ->setIsTransactionClosed('');
105
+
106
+
107
+ } else {
108
+ //$payment->setStatus(Mage_Sales_Model_Order::STATUS_APPROVED);
109
+ $payment->setLastTransId($result->response->id);
110
+ $payment->setTransactionId($result->response->id);
111
+ $invoice = $order->getInvoiceCollection()->getFirstItem();
112
+ if ($invoice && !$invoice->getEmailSent()) {
113
+ $invoice->pay(); // Mark the invoice as paid
114
+ $invoice->addComment("Payment made by Credit Card. Reference " . $result->response->id . ", Masked number: " . $result->response->card_number, false, true);
115
+ $invoice->sendEmail();
116
+ $invoice->save();
117
+ }
118
+ }
119
+ } else {
120
+ Mage::throwException(Mage::helper('fatzebra')->__("Unable to process payment: %s", $result->response->message));
121
+ }
122
+ } else {
123
+ $message = Mage::helper('fatzebra')->__('There has been an error processing your payment. %s', implode(", ", $result->errors));
124
+ Mage::throwException($message);
125
+ }
126
+ return $this;
127
+ }
128
+
129
+ /**
130
+ * Refunds a payment
131
+ *
132
+ * @param $payment the payment object
133
+ * @param $amount the amount to be refunded, as a decimal
134
+ *
135
+ * @return MindArc_FatZebra_Model_Payment
136
+ */
137
+ public function refund(Varien_Object $payment, $amount)
138
+ {
139
+ $result = $this->process_refund($payment, $amount);
140
+
141
+ if (isset($result->successful) && $result->successful) {
142
+ if ($result->response->successful) {
143
+ $payment->setStatus(self::STATUS_SUCCESS);
144
+ return $this;
145
+ } else {
146
+ Mage::throwException(Mage::helper('fatzebra')->__("Error processing refund: %s", $result->response->message));
147
+ }
148
+ }
149
+ Mage::throwException(Mage::helper('fatzebra')->__("Error processing refund: %s", implode(", ", $result->errors)));
150
+ }
151
+
152
+ /**
153
+ * Builds the refund payload and submits
154
+ *
155
+ * @param $payment the object to reference
156
+ * @param $amount the refund amount, as a decimal
157
+ *
158
+ * @return StdObject response
159
+ */
160
+ private function process_refund($payment, $amount)
161
+ {
162
+ $amt = round($amount * 100, 2);
163
+ $amt = (int)$amt;
164
+ $payload = array("transaction_id" => $payment->getLastTransId(),
165
+ "amount" => (int)$amt,
166
+ "reference" => $payment->getRefundTransactionId());
167
+
168
+ return $this->_post("refunds", $payload);
169
+ }
170
+
171
+ /**
172
+ * Builds the refund payload and submits
173
+ *
174
+ * @param $payment the object to reference
175
+ *
176
+ * @return StdObject response
177
+ */
178
+ private function process_payment($payment)
179
+ {
180
+ $amt = round($this->amount * 100, 2);
181
+ $amt = (int)$amt;
182
+
183
+ $info = $this->getInfoInstance();
184
+ $order = $payment->getOrder();
185
+ $billing_addr = $order->getBillingAddress();
186
+ $shipping_addr = $order->getShippingAddress();
187
+ $reference = $order->getIncrementId();
188
+ $customer_ip = null;
189
+ if (!is_null($_SERVER['REMOTE_ADDR'])) {
190
+ $ips_ = explode(',', $_SERVER['REMOTE_ADDR']);
191
+ $customer_ip = isset($ips_[0]) && $ips_[0] != '' ? $ips_[0] : null;
192
+ }
193
+
194
+ $forwarded_for = null;
195
+ if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
196
+ $ips_ = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
197
+ $forwarded_for = isset($ips_[0]) && $ips_[0] != '' ? $ips_[0] : null;
198
+ }
199
+
200
+ $fraud_detected = (boolean)Mage::getStoreConfig('payment/fatzebra/fraud_detected');
201
+ if (isset($_POST['use_saved_card']) && $_POST['use_saved_card'] == 1) {
202
+ $fatzebraCustomer = Mage::getModel('fatzebra/customer');
203
+ $payload = array(
204
+ "amount" => $amt,
205
+ "currency" => Mage::app()->getStore()->getBaseCurrencyCode(),
206
+ "reference" => $order->getIncrementId(),
207
+ "card_token" => $fatzebraCustomer->getCustomerToken(),
208
+ "customer_ip" => empty($forwarded_for) ? $customer_ip : $forwarded_for
209
+ );
210
+ } else {
211
+ $payload = array(
212
+ "amount" => $amt,
213
+ "currency" => Mage::app()->getStore()->getBaseCurrencyCode(),
214
+ "reference" => $order->getIncrementId(),
215
+ "card_holder" => str_replace('&', '&amp;', $info->getCcOwner()),
216
+ "card_number" => $info->getCcNumber(),
217
+ "card_expiry" => $info->getCcExpMonth() . "/" . $info->getCcExpYear(),
218
+ "cvv" => $info->getCcCid(),
219
+ "customer_ip" => empty($forwarded_for) ? $customer_ip : $forwarded_for
220
+ );
221
+ }
222
+ // If a token is being used replace the card details (which will be masked) with the token
223
+ if (isset($_POST['payment']['cc_token']) && !empty($_POST['payment']['cc_token'])) {
224
+ $payload['card_token'] = $_POST['payment']['cc_token'];
225
+ unset($payload['card_number']);
226
+ unset($payload['card_holder']);
227
+ unset($payload['card_expiry']);
228
+
229
+ // Keep the CVV if present.
230
+ if(empty($payload['cvv'])) {
231
+ unset($payload['cvv']);
232
+ }
233
+ }
234
+
235
+ if ($order->getCustomerIsGuest() == 0) {
236
+ $existing_customer = 'true';
237
+ $customer_id = $order->getCustomerId();
238
+ $customer = Mage::getModel('customer/customer')->load($customer_id);
239
+ $customer_created_at = date('c', strtotime($customer->getCreatedAt()));
240
+
241
+ if ($customer->getDob() != '') {
242
+ $customer_dob = date('c', strtotime($customer->getDob()));
243
+ } else {
244
+ $customer_dob = '';
245
+ }
246
+ } else {
247
+ $existing_customer = 'false';
248
+ $customer_id = '';
249
+ $customer_created_at = '';
250
+ $customer_dob = '';
251
+ }
252
+
253
+ if ($fraud_detected) {
254
+ $ordered_items = $order->getAllItems();
255
+ foreach ($ordered_items as $item) {
256
+ $item_name = $item->getName();
257
+ $item_id = $item->getProductId();
258
+ $_newProduct = Mage::getModel('catalog/product')->load($item_id);
259
+ $item_sku = $_newProduct->getSku();
260
+
261
+ $order_items[] = array("cost" => (float)$item->getPrice(),
262
+ "description" => $this->cleanForFraud($item_name, self::RE_ANS, 26),
263
+ "line_total" => (float)$item->getRowTotalInclTax(),
264
+ "product_code" => $this->cleanForFraud($item_id, self::RE_ANS, 12, 'left'),
265
+ "qty" => (int)$item->getQtyOrdered(),
266
+ "sku" => $this->cleanForFraud($item_sku, self::RE_ANS, 12, 'left'));
267
+ }
268
+
269
+ $billingaddress = $order->getBillingAddress();
270
+ $shippingaddress = $order->getShippingAddress();
271
+ $payload["fraud"] = array(
272
+ "customer" =>
273
+ array(
274
+ "address_1" => $this->cleanForFraud($billing_addr->getStreetFull(), self::RE_ANS, 30),
275
+ "city" => $this->cleanForFraud($billing_addr->getCity(), self::RE_ANS, 20),
276
+ "country" => $this->cleanForFraud(Mage::getModel('directory/country')->load($billing_addr->getCountry())->getIso3Code(), self::RE_AN, 3),
277
+ "created_at" => $customer_created_at,
278
+ "date_of_birth" => $customer_dob,
279
+ "email" => $order->getCustomerEmail(),
280
+ "existing_customer" => $existing_customer,
281
+ "first_name" => $this->cleanForFraud($order->getCustomerFirstname(), self::RE_ANS, 30),
282
+ "home_phone" => $this->cleanForFraud($billingaddress->getTelephone(), self::RE_NUMBER, 19),
283
+ "id" => $this->cleanForFraud($customer_id, self::RE_ANS, 16),
284
+ "last_name" => $this->cleanForFraud($order->getCustomerLastname(), self::RE_ANS, 30),
285
+ "post_code" => $this->cleanForFraud($billing_addr->getPostcode(), self::RE_AN, 9)
286
+ ),
287
+ "device_id" => isset($_POST['payment']['io_bb']) ? $_POST['payment']['io_bb'] : '',
288
+ "items" => $order_items,
289
+ "recipients" => array(
290
+ array("address_1" => $this->cleanForFraud($billingaddress->getStreetFull(), self::RE_ANS, 30),
291
+ "city" => $this->cleanForFraud($billingaddress->getCity(), self::RE_ANS, 20),
292
+ "country" => $this->cleanForFraud(Mage::getModel('directory/country')->load($billingaddress->getCountryId())->getIso3Code(), self::RE_AN, 3),
293
+ "email" => $billingaddress->getEmail(),
294
+ "first_name" => $this->cleanForFraud($billingaddress->getFirstname(), self::RE_ANS, 30),
295
+ "last_name" => $this->cleanForFraud($billingaddress->getLastname(), self::RE_ANS, 30),
296
+ "phone_number" => $this->cleanForFraud($billingaddress->getTelephone(), self::RE_NUMBER, 19),
297
+ "post_code" => $this->cleanForFraud($billingaddress->getPostcode(), self::RE_AN, 9),
298
+ "state" => $this->stateMap($billingaddress->getRegion())
299
+ )
300
+ ),
301
+ "shipping_address" => array(
302
+ "address_1" => $this->cleanForFraud($shippingaddress->getStreetFull(), self::RE_ANS, 30),
303
+ "city" => $this->cleanForFraud($shippingaddress->getCity(), self::RE_ANS, 20),
304
+ "country" => $this->cleanForFraud(Mage::getModel('directory/country')->load($shippingaddress->getCountryId())->getIso3Code(), self::RE_AN, 3),
305
+ "email" => $shippingaddress->getEmail(),
306
+ "first_name" => $this->cleanForFraud($shippingaddress->getFirstname(), self::RE_ANS, 30),
307
+ "last_name" => $this->cleanForFraud($shippingaddress->getLastname(), self::RE_ANS, 30),
308
+ "home_phone" => $this->cleanForFraud($shippingaddress->getTelephone(), self::RE_NUMBER, 19),
309
+ "post_code" => $this->cleanForFraud($shippingaddress->getPostcode(), self::RE_AN, 9),
310
+ "shipping_method" => $this->getFraudShippingMethod($order)
311
+ ),
312
+ "custom" => array("3" => "Facebook"),
313
+ "website" => Mage::getBaseUrl()
314
+ );
315
+ }
316
+ if ($existing_customer == 'false') {
317
+ unset($payload["fraud"]['customer']['created_at']);
318
+ unset($payload["fraud"]['customer']['date_of_birth']);
319
+ } else if ($customer_dob == '') {
320
+ unset($payload["fraud"]['customer']['date_of_birth']);
321
+ }
322
+
323
+ try {
324
+ $this->fzlog("{$reference}: Submitting payment for {$payload["reference"]}.");
325
+
326
+ $response = $this->_post("purchases", $payload);
327
+ } catch (Exception $e) {
328
+ $exMessage = $e->getMessage();
329
+ $this->fzlog("{$reference}: Payment request failed ({$exMessage}) - querying payment from Fat Zebra", Zend_Log::WARN);
330
+ try {
331
+ $response = $this->_fetch("purchases", $reference);
332
+ } catch (Exception $e) {
333
+ $exMessage = $e->getMessage();
334
+ $this->fzlog("{$reference}: Payment request failed after query ({$exMessage}).", Zend_Log::ERR);
335
+ }
336
+
337
+ return false;
338
+ }
339
+
340
+ if ($response->successful) {
341
+ $success = (bool)$response->successful && (bool)$response->response->successful;
342
+ $txn_result = $response->response->message;
343
+ $fz_id = $response->response->id;
344
+ $reference = $response->response->reference;
345
+ $order_id = Mage::getModel('sales/order')->loadByIncrementId($reference)->getId();
346
+ $model = Mage::getModel('fatzebra/fraud')->loadByOrderId($order_id);
347
+ if (!$model->getId()) {
348
+ // Make sure we have a fraud_result - if ReD is disabled by FZ (e.g. ReD unavailable etc) this will not be present
349
+ if (property_exists($response->response, 'fraud_result')) {
350
+ $fraud_result = $response->response->fraud_result;
351
+ $fraud_fraud_messages = $response->response->fraud_messages;
352
+ $model->setCreatedAt(now());
353
+ $model->setOrderId($order_id);
354
+ $model->setFraudResult($fraud_result);
355
+ $model->setFraudMessagesTitle(isset($fraud_fraud_messages[0]) ? $fraud_fraud_messages[0] : "");
356
+ $model->setFraudMessagesDetail(isset($fraud_fraud_messages[1]) ? $fraud_fraud_messages[1] : "");
357
+ $model->save();
358
+ }
359
+ }
360
+
361
+ $this->fzlog("{$reference}: Payment outcome: Successful, Result - {$txn_result}, Fat Zebra ID - {$fz_id}.");
362
+ }
363
+
364
+ if (!empty($response->errors)) {
365
+ foreach ($response->errors as $err) {
366
+ $this->fzlog("{$reference}: Error - {$err}", Zend_Log::ERR);
367
+ }
368
+ }
369
+ return $response;
370
+ }
371
+
372
+ /**
373
+ * Fetch the URL from the Fat Zebra Gateway
374
+ * @param $path the URI to fetch the data from (e.g. purchases, refunds etc)
375
+ * @param $payload string ID for the transaction
376
+ *
377
+ * @return StdObject response
378
+ */
379
+ private function _fetch($path, $id)
380
+ {
381
+ $path = $path . "/" . urlencode($id);
382
+ return $this->_request($path, Zend_Http_Client::GET);
383
+ }
384
+
385
+ /**
386
+ * Posts the request to the Fat Zebra gateway
387
+ * @param $path the URI to post the data to (e.g. purchases, refunds etc)
388
+ * @param $payload assoc. array for the payload
389
+ *
390
+ * @return StdObject response
391
+ */
392
+ private function _post($path, $payload)
393
+ {
394
+ return $this->_request($path, Zend_Http_Client::POST, $payload);
395
+ }
396
+
397
+ private function _request($path, $method = Zend_Http_Client::GET, $payload = null)
398
+ {
399
+ $username = Mage::getStoreConfig('payment/fatzebra/username');
400
+ $token = Mage::getStoreConfig('payment/fatzebra/token');
401
+ $sandbox = (boolean)Mage::getStoreConfig('payment/fatzebra/sandbox');
402
+ $testmode = (boolean)Mage::getStoreConfig('payment/fatzebra/testmode');
403
+
404
+ $url = $sandbox ? "https://gateway.sandbox.fatzebra.com.au" : "https://gateway.fatzebra.com.au";
405
+
406
+ if ($testmode)
407
+ $payload["test"] = true;
408
+ $uri = $url . "/v1.0/" . $path;
409
+
410
+ $client = new Varien_Http_Client();
411
+ $client->setUri($uri);
412
+ $client->setAuth($username, $token);
413
+ $client->setMethod($method);
414
+ if ($method == Zend_Http_Client::POST) {
415
+ $client->setRawData(json_encode($payload));
416
+ }
417
+ $client->setConfig(array('maxredirects' => 0,
418
+ 'timeout' => 30,
419
+ 'useragent' => 'User-Agent: Fat Zebra Magento Library ' . self::VERSION
420
+ ));
421
+
422
+ try {
423
+ $response = $client->request();
424
+ } catch (Exception $e) {
425
+ $exMessage = $e->getMessage();
426
+ $this->fzlog("{$path}: Fetching purchase failed: {$exMessage}", Zend_Log::ERR);
427
+ Mage::logException($e);
428
+ Mage::throwException(Mage::helper('fatzebra')->__("Gateway Error: %s", $e->getMessage()));
429
+ }
430
+
431
+ $responseBody = $response->getRawBody();
432
+ $response = json_decode($responseBody);
433
+ if (is_null($response)) {
434
+ $response = array("successful" => false,
435
+ "result" => null);
436
+ $err = json_last_error();
437
+ if ($err == JSON_ERROR_SYNTAX) {
438
+ $result["errors"] = array("JSON Syntax error. JSON attempted to parse: " . $data);
439
+ } elseif ($err == JSON_ERROR_UTF8) {
440
+ $result["errors"] = array("JSON Data invalid - Malformed UTF-8 characters. Data: " . $data);
441
+ } else {
442
+ $result["errors"] = array("JSON parse failed. Unknown error. Data:" . $data);
443
+ }
444
+ }
445
+ return $response;
446
+ }
447
+
448
+ /**
449
+ *
450
+ * Log a message to the gateway log
451
+ * @param $message string the message to be logged
452
+ * @param $level int the log level, from Zend_Log::* (http://framework.zend.com/manual/1.12/en/zend.log.overview.html#zend.log.overview.builtin-priorities)
453
+ */
454
+ function fzlog($message, $level = Zend_Log::INFO)
455
+ {
456
+ Mage::log($message, $level, "FatZebra_gateway.log");
457
+ }
458
+
459
+ /** Cleans the data for fraud check which has some data restrictions
460
+ * @param $data string the input data
461
+ * @param $pattern string the regex pattern to use for scrubbing
462
+ * @param $maxlen int the maximum length of tha data (to truncate)
463
+ * @param $trimDirection string the direction of truncation - right (default) or left (trim from the start).
464
+ */
465
+ function cleanForFraud($data, $pattern, $maxlen, $trimDirection = 'right')
466
+ {
467
+ $data = preg_replace($pattern, '', $this->toASCII($data));
468
+ $data = preg_replace('/[\r\n]/', ' ', $data);
469
+ if (strlen($data) > $maxlen) {
470
+ if ($trimDirection == 'right') {
471
+ return substr($data, 0, $maxlen);
472
+ } else {
473
+ return substr($data, -1, $maxlen);
474
+ }
475
+ } else {
476
+ return $data;
477
+ }
478
+ }
479
+
480
+ // Borrowed from http://stackoverflow.com/questions/3542717/how-to-remove-accents-and-turn-letters-into-plain-ascii-characters
481
+ /** Translates accented characters, ligatures etc to the latin equivalent.
482
+ * @param $str string the input to be translated
483
+ * @return string output once translated
484
+ */
485
+ function toASCII( $str )
486
+ {
487
+ return strtr(utf8_decode($str),
488
+ utf8_decode(
489
+ 'ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ'),
490
+ 'SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy');
491
+ }
492
+
493
+ /**
494
+ * Validate payment method information object
495
+ *
496
+ * @param Mage_Payment_Model_Info $info
497
+ * @return Mage_Payment_Model_Abstract
498
+ */
499
+ public function validate()
500
+ {
501
+ if (isset($_POST['use_saved_card'])) {
502
+ return $this;
503
+ }
504
+ if (isset($_POST['payment']['cc_token']) && !empty($_POST['payment']['cc_token'])) {
505
+ // Bypass if we are tokenized...
506
+ return $this;
507
+ }
508
+
509
+ return parent::validate();
510
+ }
511
+
512
+ public function acceptPayment(Mage_Payment_Model_Info $payment)
513
+ {
514
+ Mage::log("acceptPayment");
515
+ parent::acceptPayment($payment);
516
+ return true;
517
+ }
518
+
519
+ public function denyPayment(Mage_Payment_Model_Info $payment) {
520
+ Mage::log("denyPayment");
521
+ parent::denyPayment($payment);
522
+ return true;
523
+ }
524
+
525
+ public function getFraudShippingMethod(Mage_Sales_Model_Order $order) {
526
+ // Load Configs
527
+ // See which method is mapped to which code
528
+ // Return code or 'other'
529
+
530
+ $shipping = $order->getShippingMethod();
531
+
532
+ $method_lowcost = explode(',', Mage::getStoreConfig('payment/fatzebra/fraud_ship_lowcost'));
533
+ $method_overnight = explode(',', Mage::getStoreConfig('payment/fatzebra/fraud_ship_overnight'));
534
+ $method_sameday = explode(',', Mage::getStoreConfig('payment/fatzebra/fraud_ship_sameday'));
535
+ $method_pickup = explode(',', Mage::getStoreConfig('payment/fatzebra/fraud_ship_pickup'));
536
+ $method_express = explode(',', Mage::getStoreConfig('payment/fatzebra/fraud_ship_express'));
537
+ $method_international = explode(',', Mage::getStoreConfig('payment/fatzebra/fraud_ship_international'));
538
+
539
+ if (in_array($shipping, $method_lowcost)) {
540
+ return 'low_cost';
541
+ }
542
+
543
+ if (in_array($shipping, $method_overnight)) {
544
+ return 'overnight';
545
+ }
546
+
547
+ if (in_array($shipping, $method_sameday)) {
548
+ return 'same_day';
549
+ }
550
+
551
+ if (in_array($shipping, $method_pickup)) {
552
+ return 'pickup';
553
+ }
554
+
555
+ if (in_array($shipping, $method_express)) {
556
+ return 'express';
557
+ }
558
+
559
+ if (in_array($shipping, $method_international)) {
560
+ return 'international';
561
+ }
562
+
563
+ return 'other';
564
+ }
565
+
566
+ // Maps AU States to the codes... otherwise return the state scrubbed for fraud....
567
+ public function stateMap($stateName) {
568
+ $states = array('Australia Capital Territory' => 'ACT',
569
+ 'New South Wales' => 'NSW',
570
+ 'Northern Territory' => 'NT',
571
+ 'Queensland' => 'QLD',
572
+ 'South Australia' => 'SA',
573
+ 'Tasmania' => 'TAS',
574
+ 'Victoria' => 'VIC',
575
+ 'Western Australia' => 'WA');
576
+
577
+ if (array_key_exists($stateName, $states)) {
578
+ return $states[$stateName];
579
+ } else {
580
+ return $this->cleanForFraud($stateName, self::RE_AN, 10);
581
+ }
582
+ }
583
+
584
+ }
app/code/community/MindArc/FatZebra/Model/Source/Action.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class MindArc_FatZebra_Model_Source_Action {
4
+
5
+ public function toOptionArray() {
6
+ return array(
7
+ array(
8
+ 'value' => Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE,
9
+ 'label' => Mage::helper('core')->__('Authorise & Capture')
10
+ )
11
+ );
12
+ }
13
+
14
+ }
app/code/community/MindArc/FatZebra/controllers/IndexController.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * To change this license header, choose License Headers in Project Properties.
5
+ * To change this template file, choose Tools | Templates
6
+ * and open the template in the editor.
7
+ */
8
+
9
+ class MindArc_FatZebra_IndexController extends Mage_Core_Controller_Front_Action {
10
+
11
+ public function indexAction() {
12
+ $session = $this->getRequest()->getParam('io_bb');
13
+ if($session!=null && $session!="")
14
+ Mage::getSingleton('core/session')->setFatzebraFraud($session);
15
+ $this->loadLayout();
16
+ $this->renderLayout();
17
+ }
18
+ public function sessionAction(){
19
+ echo Mage::getSingleton('core/session')->getFatzebraFraud();
20
+ }
21
+ }
app/code/community/MindArc/FatZebra/etc/config.xml ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <MindArc_FatZebra>
5
+ <version>2.1.1</version>
6
+ <depends>
7
+ <Mage_Sales />
8
+ </depends>
9
+ </MindArc_FatZebra>
10
+ </modules>
11
+ <global>
12
+ <models>
13
+ <fatzebra>
14
+ <class>MindArc_FatZebra_Model</class>
15
+ <resourceModel>fatzebra_mysql4</resourceModel>
16
+ </fatzebra>
17
+ <fatzebra_mysql4>
18
+ <class>MindArc_FatZebra_Model_Mysql4</class>
19
+ <entities>
20
+ <fraud>
21
+ <table>fatzebrafraud_data</table>
22
+ </fraud>
23
+ </entities>
24
+ </fatzebra_mysql4>
25
+ <fatzebra_adminhtml>
26
+ <class>MindArc_FatZebra_Model_Adminhtml</class>
27
+ </fatzebra_adminhtml>
28
+ </models>
29
+ <helpers>
30
+ <fatzebra>
31
+ <class>MindArc_FatZebra_Helper</class>
32
+ </fatzebra>
33
+ </helpers>
34
+ <blocks>
35
+ <adminhtml>
36
+ <rewrite>
37
+ <sales_order_grid>MindArc_FatZebra_Block_Adminhtml_Sales_Order_Grid</sales_order_grid>
38
+ </rewrite>
39
+ </adminhtml>
40
+ <fatzebra>
41
+ <class>MindArc_FatZebra_Block</class>
42
+ </fatzebra>
43
+ </blocks>
44
+ <resources>
45
+ <fatzebra_setup>
46
+ <setup>
47
+ <module>MindArc_FatZebra</module>
48
+ <class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
49
+ </setup>
50
+ <connection>
51
+ <use>core_setup</use>
52
+ </connection>
53
+ </fatzebra_setup>
54
+ <fatzebra_write>
55
+ <connection>
56
+ <use>core_write</use>
57
+ </connection>
58
+ </fatzebra_write>
59
+ <fatzebra_read>
60
+ <connection>
61
+ <use>core_read</use>
62
+ </connection>
63
+ </fatzebra_read>
64
+ </resources>
65
+ <events>
66
+ <payment_method_is_active>
67
+ <observers>
68
+ <fatzebra_payment_method_is_active>
69
+ <type>singleton</type>
70
+ <class>fatzebra/observer</class>
71
+ <method>paymentMethodIsActive</method>
72
+ </fatzebra_payment_method_is_active>
73
+ </observers>
74
+ </payment_method_is_active>
75
+ <checkout_onepage_controller_success_action>
76
+ <observers>
77
+ <fatzebra_success_action>
78
+ <type>singleton</type>
79
+ <class>fatzebra/observer</class>
80
+ <method>handleSuccessAction</method>
81
+ </fatzebra_success_action>
82
+ </observers>
83
+ </checkout_onepage_controller_success_action>
84
+ </events>
85
+ </global>
86
+ <default>
87
+ <payment>
88
+ <fatzebra>
89
+ <active>1</active>
90
+ <model>fatzebra/payment</model>
91
+ <order_status>pending</order_status>
92
+ <title>Fat Zebra</title>
93
+ <username>TEST</username>
94
+ <token>TEST</token>
95
+ <shared_secret>033bd94b11</shared_secret>
96
+ <cctypes>AE,VI,MC,JCB</cctypes>
97
+ <show_logo>1</show_logo>
98
+ <fraud_detected>0</fraud_detected>
99
+ <direct_post>1</direct_post>
100
+ <can_save>1</can_save>
101
+ <payment_action>authorize_capture</payment_action>
102
+ <order_status>processing</order_status>
103
+ <allowspecific>0</allowspecific>
104
+ </fatzebra>
105
+ </payment>
106
+ </default>
107
+ <frontend>
108
+ <routers>
109
+ <fatzebra>
110
+ <use>standard</use>
111
+ <args>
112
+ <module>MindArc_FatZebra</module>
113
+ <frontName>fatzebra</frontName>
114
+ </args>
115
+ </fatzebra>
116
+ </routers>
117
+ <layout>
118
+ <updates>
119
+ <fatzebra>
120
+ <file>fatzebra.xml</file>
121
+ </fatzebra>
122
+ </updates>
123
+ </layout>
124
+ </frontend>
125
+ <adminhtml>
126
+
127
+ <layout>
128
+ <updates>
129
+ <fatzebra>
130
+ <file>fatzebra.xml</file>
131
+ </fatzebra>
132
+ </updates>
133
+ </layout>
134
+ <acl>
135
+ <resources>
136
+ <admin>
137
+ <children>
138
+ <system>
139
+ <children>
140
+ <config>
141
+ <children>
142
+ <fatzebra>
143
+ <title>Fraud Detection</title>
144
+ </fatzebra>
145
+ </children>
146
+ </config>
147
+ </children>
148
+ </system>
149
+ </children>
150
+ </admin>
151
+ </resources>
152
+ </acl>
153
+ </adminhtml>
154
+ </config>
app/code/community/MindArc/FatZebra/etc/system.xml ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <payment>
5
+ <groups>
6
+ <fatzebra translate="label" module="paygate">
7
+ <label>Fat Zebra</label>
8
+ <sort_order>670</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>1</show_in_website>
11
+ <show_in_store>1</show_in_store>
12
+
13
+ <fields>
14
+ <active translate="label">
15
+ <label>Enabled</label>
16
+ <frontend_type>select</frontend_type>
17
+ <source_model>adminhtml/system_config_source_yesno</source_model>
18
+ <sort_order>1</sort_order>
19
+ <show_in_default>1</show_in_default>
20
+ <show_in_website>1</show_in_website>
21
+ <show_in_store>1</show_in_store>
22
+ </active>
23
+
24
+ <sandbox translate="label">
25
+ <label>Sandbox Mode</label>
26
+ <frontend_type>select</frontend_type>
27
+ <source_model>adminhtml/system_config_source_yesno</source_model>
28
+ <sort_order>2</sort_order>
29
+ <show_in_default>1</show_in_default>
30
+ <show_in_website>1</show_in_website>
31
+ <show_in_store>1</show_in_store>
32
+ </sandbox>
33
+ <payment_action translate="label comment">
34
+ <label>Payment Action</label>
35
+ <comment>
36
+ <![CDATA[
37
+ If Authorise & Capture, invoice created automatically.
38
+ ]]>
39
+ </comment>
40
+ <frontend_type>select</frontend_type>
41
+ <source_model>fatzebra/source_action</source_model>
42
+ <sort_order>2</sort_order>
43
+ <show_in_default>1</show_in_default>
44
+ <show_in_website>1</show_in_website>
45
+ <show_in_store>1</show_in_store>
46
+ </payment_action>
47
+ <testmode translate="label">
48
+ <label>Test Mode</label>
49
+ <comment>For testing in a non-sandbox environment</comment>
50
+ <frontend_type>select</frontend_type>
51
+ <source_model>adminhtml/system_config_source_yesno</source_model>
52
+ <sort_order>2</sort_order>
53
+ <show_in_default>1</show_in_default>
54
+ <show_in_website>1</show_in_website>
55
+ <show_in_store>1</show_in_store>
56
+ </testmode>
57
+ <show_logo translate="label">
58
+ <label>Show Fat Zebra Logo</label>
59
+ <comment>Optional, but we will love you forever if you do</comment>
60
+ <frontend_type>select</frontend_type>
61
+ <source_model>adminhtml/system_config_source_yesno</source_model>
62
+ <sort_order>3</sort_order>
63
+ <show_in_default>1</show_in_default>
64
+ <show_in_website>1</show_in_website>
65
+ <show_in_store>1</show_in_store>
66
+ </show_logo>
67
+
68
+ <cctypes translate="label">
69
+ <label>Show Card Logos</label>
70
+ <comment>Select which card types you wish to display</comment>
71
+ <frontend_type>multiselect</frontend_type>
72
+ <source_model>adminhtml/system_config_source_payment_cctype</source_model>
73
+ <sort_order>4</sort_order>
74
+ <show_in_default>1</show_in_default>
75
+ <show_in_website>1</show_in_website>
76
+ <show_in_store>1</show_in_store>
77
+ </cctypes>
78
+
79
+ <username translate="label">
80
+ <label>Username</label>
81
+ <frontend_type>text</frontend_type>
82
+ <sort_order>10</sort_order>
83
+ <show_in_default>1</show_in_default>
84
+ <show_in_website>1</show_in_website>
85
+ <show_in_store>1</show_in_store>
86
+ </username>
87
+
88
+ <token translate="label">
89
+ <label>Token</label>
90
+ <frontend_type>text</frontend_type>
91
+ <sort_order>20</sort_order>
92
+ <show_in_default>1</show_in_default>
93
+ <show_in_website>1</show_in_website>
94
+ <show_in_store>1</show_in_store>
95
+ </token>
96
+
97
+ <direct_post translate="label">
98
+ <label>Direct Post Tokenization</label>
99
+ <comment>Enable this to transmit the credit card data directly from the customer's browser to the Gateway. This helps reduce the PCI-DSS scope for your website.</comment>
100
+ <frontend_type>select</frontend_type>
101
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
102
+ <sort_order>4</sort_order>
103
+ <show_in_default>1</show_in_default>
104
+ <show_in_website>1</show_in_website>
105
+ <show_in_store>1</show_in_store>
106
+ </direct_post>
107
+ <can_save translate="label">
108
+ <label>Customer can save Credit Card</label>
109
+ <comment>Requires Direct post to be enabled</comment>
110
+ <frontend_type>select</frontend_type>
111
+ <source_model>adminhtml/system_config_source_yesno</source_model>
112
+ <sort_order>5</sort_order>
113
+ <show_in_default>1</show_in_default>
114
+ <show_in_website>1</show_in_website>
115
+ <show_in_store>0</show_in_store>
116
+ <depends><direct_post>1</direct_post></depends>
117
+ </can_save>
118
+ <shared_secret translate="label">
119
+ <label>Shared Secret</label>
120
+ <comment>Required for Direct Post Tokenization</comment>
121
+ <sort_order>30</sort_order>
122
+ <show_in_default>1</show_in_default>
123
+ <show_in_website>1</show_in_website>
124
+ <show_in_store>1</show_in_store>
125
+ <depends><direct_post>1</direct_post></depends>
126
+ </shared_secret>
127
+
128
+ <order_status translate="label">
129
+ <label>New order status</label>
130
+ <frontend_type>select</frontend_type>
131
+ <source_model>adminhtml/system_config_source_order_status_processing</source_model>
132
+ <sort_order>40</sort_order>
133
+ <show_in_default>1</show_in_default>
134
+ <show_in_website>1</show_in_website>
135
+ <show_in_store>1</show_in_store>
136
+ </order_status>
137
+
138
+ <title translate="label">
139
+ <label>Title</label>
140
+ <frontend_type>text</frontend_type>
141
+ <sort_order>50</sort_order>
142
+ <show_in_default>1</show_in_default>
143
+ <show_in_website>1</show_in_website>
144
+ <show_in_store>1</show_in_store>
145
+ </title>
146
+
147
+ <fraud_detected translate="label">
148
+ <label>Retail Decisions Fraud Detection</label>
149
+ <frontend_type>select</frontend_type>
150
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
151
+ <sort_order>98</sort_order>
152
+ <show_in_default>1</show_in_default>
153
+ <show_in_website>1</show_in_website>
154
+ <show_in_store>1</show_in_store>
155
+ </fraud_detected>
156
+
157
+ <fraud_ship_lowcost translate="label">
158
+ <label>Fraud Shipping Map - Low Cost</label>
159
+ <frontend_type>multiselect</frontend_type>
160
+ <source_model>fatzebra/adminhtml_shipping_enabledmethods</source_model>
161
+ <sort_order>99</sort_order>
162
+ <show_in_default>1</show_in_default>
163
+ <show_in_website>1</show_in_website>
164
+ <show_in_store>1</show_in_store>
165
+ <depends><fraud_detected>1</fraud_detected></depends>
166
+ </fraud_ship_lowcost>
167
+ <fraud_ship_sameday translate="label">
168
+ <label>Fraud Shipping Map - Same Day</label>
169
+ <frontend_type>multiselect</frontend_type>
170
+ <source_model>fatzebra/adminhtml_shipping_enabledmethods</source_model>
171
+ <sort_order>99</sort_order>
172
+ <show_in_default>1</show_in_default>
173
+ <show_in_website>1</show_in_website>
174
+ <show_in_store>1</show_in_store>
175
+ <depends><fraud_detected>1</fraud_detected></depends>
176
+ </fraud_ship_sameday>
177
+ <fraud_ship_overnight translate="label">
178
+ <label>Fraud Shipping Map - Overnight</label>
179
+ <frontend_type>multiselect</frontend_type>
180
+ <source_model>fatzebra/adminhtml_shipping_enabledmethods</source_model>
181
+ <sort_order>99</sort_order>
182
+ <show_in_default>1</show_in_default>
183
+ <show_in_website>1</show_in_website>
184
+ <show_in_store>1</show_in_store>
185
+ <depends><fraud_detected>1</fraud_detected></depends>
186
+ </fraud_ship_overnight>
187
+ <fraud_ship_express translate="label">
188
+ <label>Fraud Shipping Map - Express</label>
189
+ <frontend_type>multiselect</frontend_type>
190
+ <source_model>fatzebra/adminhtml_shipping_enabledmethods</source_model>
191
+ <sort_order>99</sort_order>
192
+ <show_in_default>1</show_in_default>
193
+ <show_in_website>1</show_in_website>
194
+ <show_in_store>1</show_in_store>
195
+ <depends><fraud_detected>1</fraud_detected></depends>
196
+ </fraud_ship_express>
197
+ <fraud_ship_international translate="label">
198
+ <label>Fraud Shipping Map - International</label>
199
+ <frontend_type>multiselect</frontend_type>
200
+ <source_model>fatzebra/adminhtml_shipping_enabledmethods</source_model>
201
+ <sort_order>99</sort_order>
202
+ <show_in_default>1</show_in_default>
203
+ <show_in_website>1</show_in_website>
204
+ <show_in_store>1</show_in_store>
205
+ <depends><fraud_detected>1</fraud_detected></depends>
206
+ </fraud_ship_international>
207
+ <fraud_ship_pickup translate="label">
208
+ <label>Fraud Shipping Map - Pickup</label>
209
+ <frontend_type>multiselect</frontend_type>
210
+ <source_model>fatzebra/adminhtml_shipping_enabledmethods</source_model>
211
+ <sort_order>99</sort_order>
212
+ <show_in_default>1</show_in_default>
213
+ <show_in_website>1</show_in_website>
214
+ <show_in_store>1</show_in_store>
215
+ <depends><fraud_detected>1</fraud_detected></depends>
216
+ </fraud_ship_pickup>
217
+ </fields>
218
+ </fatzebra>
219
+ </groups>
220
+ </payment>
221
+ </sections>
222
+ </config>
app/code/community/MindArc/FatZebra/sql/fatzebra_setup/mysql4-install-0.1.1-2.0.5.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+ $installer->run("
7
+ DROP TABLE IF EXISTS {$this->getTable('fatzebrafraud_data')};
8
+ CREATE TABLE {$this->getTable('fatzebrafraud_data')} (
9
+ `entity_id` int(10) NOT NULL auto_increment,
10
+ `order_id` int(10) NOT NULL,
11
+ `fraud_result` text NULL,
12
+ `fraud_messages_title` text NULL,
13
+ `fraud_messages_detail` text NULL,
14
+ `created_at` timestamp NULL DEFAULT NULL,
15
+ PRIMARY KEY (`entity_id`),
16
+ KEY `order_id_idx` (`order_id`)
17
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
18
+ ");
19
+
20
+ $installer->endSetup();
app/code/community/MindArc/FatZebra/sql/fatzebra_setup/mysql4-upgrade-2.0.5-2.0.6.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+ $installer->startSetup();
4
+
5
+ $installer->addAttribute('customer', 'fatzebra_token', array(
6
+ 'label' => 'Fat Zebra Token',
7
+ 'visible' => 1,
8
+ 'required' => 0,
9
+ 'position' => 1,
10
+ 'sort_order' => 82
11
+ ));
12
+ $installer->addAttribute('customer', 'fatzebra_masked_card_number', array(
13
+ 'label' => 'Fat Zebra Masked Card Number',
14
+ 'visible' => 1,
15
+ 'required' => 0,
16
+ 'position' => 1,
17
+ 'sort_order' => 83
18
+ ));
19
+ $installer->addAttribute('customer', 'fatzebra_expiry_date', array(
20
+ 'label' => 'Fat Zebra Expriy Date',
21
+ 'visible' => 1,
22
+ 'required' => 0,
23
+ 'position' => 1,
24
+ 'sort_order' => 84
25
+ ));
26
+
27
+ $customerattrubute = Mage::getModel('customer/attribute')->loadByCode('customer', 'fatzebra_masked_card_number');
28
+ $forms=array('adminhtml_customer');
29
+ $customerattrubute->setData('used_in_forms', $forms);
30
+ $customerattrubute->save();
31
+
32
+ $installer->endSetup();
33
+
app/design/adminhtml/default/default/layout/fatzebra.xml ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <layout>
2
+ <adminhtml_sales_order_view>
3
+ <reference name="sales_order_tabs">
4
+ <action method="addTab">
5
+ <name>tab_fatzebrafraud</name>
6
+ <block>fatzebra/adminhtml_sales_order_view_tab_fraud</block>
7
+ </action>
8
+ </reference>
9
+ </adminhtml_sales_order_view>
10
+ <adminhtml_system_config_edit>
11
+ <reference name="content">
12
+ <block type="fatzebra/jsinit" name="fatzebra_jsinit" template="fatzebra/jsinit.phtml"></block>
13
+ </reference>
14
+ </adminhtml_system_config_edit>
15
+
16
+ </layout>
app/design/adminhtml/default/default/template/fatzebra/jsinit.phtml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ <script type="text/javascript">
3
+ //<![CDATA[
4
+ function initFatZebra() {
5
+ // if (!document.getElementById("row_payment_fatzebra_title")) {
6
+ // Don't perform for website and store view
7
+ // return;
8
+ //}
9
+ $('payment_fatzebra').insert('<span style="display: block; line-height: 103px; background: #EAF0EE; border: 1px solid #CCCCCC; margin-bottom: 10px; padding: 0px 0 0 10px; margin-top: 10px;"><img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);?>/payments/mindarc.png" border="0" style="float: left; margin: 10px 20px 0 10px;"/> Built by <a href="http://www.mindarc.com.au" target="_blank">www.mindarc.com.au</a></span>');
10
+ }
11
+ //]]>
12
+ </script>
app/design/adminhtml/default/default/template/fatzebra/tab.phtml ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // $res = $this->getFraudResult();
3
+ // $customer = $this->getCustomer();
4
+ ?>
5
+ <div class="entry-edit">
6
+ <div class="entry-edit-head">
7
+ <h4 class="icon-head head-products">Retail Decisions Fraud Detected</h4>
8
+ </div>
9
+ </div>
10
+ <div class="fieldset">
11
+ <?php
12
+ $order = $this->getOrder();
13
+ $model = Mage::getModel('fatzebra/fraud')->loadByOrderId($order->getId());
14
+ if (!$model->getId()) {
15
+ $fraud_time_detected = "---";
16
+ $fraud_result = "---";
17
+ $fraud_message_title = "---";
18
+ $fraud_message_detail = "";
19
+ } else {
20
+ $fraud_time_detected = Mage::helper('core')->formatTime($model->getCreatedAt(), $format = 'medium', $showDate = true);
21
+ $fraud_result = $model->getFraudResult();
22
+ $fraud_message_title = $model->getFraudMessagesTitle();
23
+ $fraud_message_detail = $model->getFraudMessagesDetail();
24
+ }
25
+
26
+ ?>
27
+ <table cellspacing="0" class="form-list">
28
+ <tbody>
29
+ <tr>
30
+ <td class="label"><label>Fraud Detected Date:</label></td>
31
+ <td class="value"><strong><?php echo $fraud_time_detected; ?></strong></td>
32
+ </tr>
33
+ <tr>
34
+ <td class="label"><label>Fraud Result:</label></td>
35
+ <td class="value"><strong><?php echo $fraud_result; ?></strong></td>
36
+ </tr>
37
+ <tr>
38
+ <td class="label"><label>Fraud Message:</label></td>
39
+ <td class="value"><strong><?php echo $fraud_message_title; ?></strong><br><?php echo $fraud_message_detail; ?></td>
40
+ </tr>
41
+ </tbody>
42
+
43
+ </table>
44
+ </div>
app/design/frontend/base/default/layout/fatzebra.xml ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <onestepcheckout_index_index>
4
+ <reference name="head">
5
+ <action method="addJs"><file>fatzebra/fatzebra.js</file></action>
6
+ </reference>
7
+ </onestepcheckout_index_index>
8
+ <checkout_onepage_index>
9
+ <reference name="head">
10
+ <action method="addJs"><file>fatzebra/fatzebra.js</file></action>
11
+ </reference>
12
+ </checkout_onepage_index>
13
+ <checkout_multishipping_billing>
14
+ <reference name="head">
15
+ <action method="addJs"><file>fatzebra/fatzebra.js</file></action>
16
+ </reference>
17
+ </checkout_multishipping_billing>
18
+ <checkout_cart_index>
19
+ <reference name="head">
20
+ <action method="addJs"><file>fatzebra/fatzebra.js</file></action>
21
+ </reference>
22
+ </checkout_cart_index>
23
+ <fatzebra_index_index>
24
+ <reference name="root">
25
+ <action method="addJs"><file>fatzebra/fatzebra.js</file></action>
26
+ </reference>
27
+ </fatzebra_index_index>
28
+ <gomage_checkout_onepage_index>
29
+ <reference name="head">
30
+ <action method="addJs"><file>fatzebra/fatzebra.js</file></action>
31
+ </reference>
32
+ </gomage_checkout_onepage_index>
33
+ </layout>
app/design/frontend/base/default/template/mindarc/fatzebra/empty.phtml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * To change this license header, choose License Headers in Project Properties.
5
+ * To change this template file, choose Tools | Templates
6
+ * and open the template in the editor.
7
+ */
8
+
app/design/frontend/base/default/template/mindarc/fatzebra/form.phtml ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $_code=$this->getMethodCode() ?>
2
+ <div id="payment_form_<?php echo $_code ?>" style="display:none;">
3
+ <input type="hidden" name="<?php echo $_code ?>_cc_type" />
4
+ <?php
5
+ $fraud_detection = (boolean) Mage::getStoreConfig('payment/fatzebra/fraud_detected');
6
+ $direct_post = (boolean) Mage::getStoreConfig('payment/fatzebra/direct_post');
7
+ ?>
8
+ <?php if ($fraud_detection): ?>
9
+ <input name="payment[io_bb]" id="fatzebra_io_bb" type="hidden" />
10
+ <?php endif; ?>
11
+ <?php if ($direct_post): ?>
12
+ <?php
13
+ $nonce = uniqid("fzdirect-");
14
+ $shared_secret = Mage::getStoreConfig('payment/fatzebra/shared_secret');
15
+ $verification = hash_hmac('md5', $nonce, $shared_secret);
16
+ $fz_mode = Mage::getStoreConfig('payment/fatzebra/sandbox');
17
+ $fz_username = Mage::getStoreConfig('payment/fatzebra/username');
18
+ $fz_url = $fz_mode ? 'https://gateway.sandbox.fatzebra.com.au/v2/credit_cards/direct/' . $fz_username : 'https://gateway.fatzebra.com.au/v2/credit_cards/direct/' . $fz_username;
19
+ ?>
20
+ <input type="hidden" id="fz_directpost_enabled" value="true" />
21
+ <input type="hidden" id="fz_directpost_nonce" value="<?php echo $nonce; ?>" />
22
+ <input type="hidden" id="fz_directpost_verification" value="<?php echo $verification; ?>" />
23
+ <input type="hidden" id="fz_directpost_url" value="<?php echo $fz_url; ?>" />
24
+ <?php endif; ?>
25
+ <?php if ($this->canSave() && $this->hasCustomerToken()): ?>
26
+ <label for="<?php echo $_code ?>_cc_token">
27
+ <?php if ($this->getSavedCardNotExpired()): ?>
28
+ <input name="use_saved_card" type="radio" title="<?php echo $this->__('Use Saved Card') ?>" class="input-radio" value="1" checked />
29
+ <?php else: ?>
30
+ &mdash;&nbsp;
31
+ <?php endif; ?>
32
+ <?php echo $this->__('Use Saved Card') ?>
33
+ </label>
34
+ <ul class="form-list">
35
+ <li id="<?php echo $_code ?>_cc_type_cvv_div">
36
+ <div class="input-box">
37
+ <div id="<?php echo $_code ?>_saved_card_details">
38
+ <span id="<?php echo $_code ?>_cc_display_number">
39
+ <?php $cardTypeCode = $this->getStoredCardType();
40
+ $cardTypeCode = strtolower($cardTypeCode);
41
+ $expiry = $this->getSavedCardExpiryDate();
42
+ ?>
43
+ <img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . "/payments/" . $cardTypeCode . ".png"; ?>" class="card-logo" style="margin-top: -5px; opacity: 0.5; display: initial; vertical-align: top;" />
44
+ <span <?php if (!$this->getSavedCardNotExpired()) { echo "style='text-decoration: line-through;'";} ?>><?php echo $this->getMaskedCardNumber(); ?> <?php echo $expiry['month']; ?>/<?php echo $expiry['year']; ?></span>
45
+ <?php if (!$this->getSavedCardNotExpired()) { ?>
46
+ <br /><small><strong>Expired - please update your card details below.</strong></small>
47
+ <?php } ?>
48
+ <span>
49
+ </div>
50
+ </div>
51
+ </li>
52
+ </ul>
53
+ <label for="<?php echo $_code ?>_cc_token">
54
+ <?php if ($this->getSavedCardNotExpired()): ?>
55
+ <input name="use_saved_card" type="radio" title="<?php echo $this->__('Enter New Card') ?>" class="input-radio" value="0" />
56
+ <?php else: ?>
57
+ <input name="use_saved_card" type="radio" title="<?php echo $this->__('Enter New Card') ?>" class="input-radio" value="0" checked />
58
+ <?php endif; ?>
59
+ <?php echo $this->__('Enter New Card') ?>
60
+ </label>
61
+ <?php endif; ?>
62
+
63
+ <ul class="form-list" id="payment_form_<?php echo $_code ?>_entry">
64
+ <?php if((boolean)Mage::getStoreConfig('payment/fatzebra/show_logo')): ?>
65
+ <a href="https://www.fatzebra.com.au/?rel=logo" title="Fat Zebra Certified" style="float: right;"><img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . "/payments/Fat-Zebra-Certified-small.png"; ?>" alt="Fat Zebra Certified" border="0" /></a>
66
+ <?php endif; ?>
67
+ <li>
68
+ <div class="input-box">
69
+ <span class="required"><label for="<?php echo $_code ?>_cc_owner"><?php echo Mage::helper('payment')->__('Name on Card') ?></span></label><br/>
70
+ <input type="text" title="<?php echo Mage::helper('payment')->__('Name on Card') ?>" class="required-entry input-text" id="<?php echo $_code ?>_cc_owner" name="payment[cc_owner]" value="<?php echo $this->getInfoData('cc_owner') ?>"/>
71
+ </div>
72
+ </li>
73
+ <input type="hidden" name="payment[cc_type]" id="<?php echo $_code ?>_cc_type" />
74
+ <li>
75
+ <div class="input-box">
76
+ <span class="required"><label for="<?php echo $_code ?>_cc_number"><?php echo Mage::helper('payment')->__('Credit Card Number') ?></span></label><br/>
77
+ <input type="text" id="<?php echo $_code ?>_cc_number" name="payment[cc_number]" title="<?php echo Mage::helper('payment')->__('Credit Card Number') ?>" class="required-entry input-text validate-cc-number" value="<?php echo $this->getInfoData('cc_number')?>"/>
78
+ <?php foreach($this->getCcAvailableTypes() as $typeCode => $typeName): ?>
79
+ <img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . "/payments/" . $typeCode . ".png"; ?>" alt="<?php echo $typeName; ?>" class="card-logo" id="card-<?php echo strtolower($typeCode); ?>" style="margin-top: -5px; opacity: 0.5; display: initial; vertical-align: top;" />
80
+ <?php endforeach; ?>
81
+ </div>
82
+ </li>
83
+ <li>
84
+ <div class="input-box">
85
+ <span class="required"><label for="<?php echo $_code ?>_expiration"><?php echo Mage::helper('payment')->__('Expiration Date') ?></span></label><br/>
86
+ <select id="<?php echo $_code ?>_expiration" style="width:140px;" name="payment[cc_exp_month]" class="required-entry">
87
+ <?php $_ccExpMonth = $this->getInfoData('cc_exp_month'); ?>
88
+ <?php foreach ($this->getCcMonths() as $k=>$v): ?>
89
+ <option value="<?php echo $k ?>" <?php if($k==$_ccExpMonth): ?>selected="selected"<?php endif ?>><?php echo $v ?></option>
90
+ <?php endforeach; ?>
91
+ </select>
92
+ <?php $_ccExpYear = $this->getInfoData('cc_exp_year'); ?>
93
+ <select id="<?php echo $_code ?>_expiration_yr" style="width:103px;" name="payment[cc_exp_year]" class="required-entry">
94
+ <?php foreach ($this->getCcYears() as $k=>$v): ?>
95
+ <option value="<?php echo $k ? $k : '' ?>" <?php if($k==$_ccExpYear): ?>selected="selected"<?php endif ?>><?php echo $v ?></option>
96
+ <?php endforeach; ?>
97
+ </select>
98
+ </div>
99
+ </li>
100
+ <?php if($this->hasVerification()): ?>
101
+ <li>
102
+ <div class="input-box">
103
+ <span class="required"><label for="<?php echo $_code ?>_cc_cid"><?php echo Mage::helper('payment')->__('Card Verification Number') ?></span></label><br/>
104
+ <input type="text" title="<?php echo Mage::helper('payment')->__('Card Verification Number') ?>" class="required-entry input-text validate-cc-cvn" id="<?php echo $_code ?>_cc_cid" name="payment[cc_cid]" style="width:3em;" value="<?php echo $this->getInfoData('cc_cid')?>"/>
105
+ </div>
106
+ </li>
107
+ <?php endif; ?>
108
+
109
+ <?php if ($this->canSave()): ?>
110
+ <li id="<?php echo $_code ?>_cc_type_cvv_div">
111
+ <label for="<?php echo $_code ?>_cc_save">
112
+ <?php $saveText = ($this->hasCustomerToken() ? 'Update Saved Card?' : 'Save Card?'); ?>
113
+ <input type="checkbox" title="<?php echo $this->__($saveText) ?>" class="input-radio" id="<?php echo $_code ?>_cc_save" name="payment[cc_save]" value="1" />
114
+ <?php echo $this->__($saveText) ?>
115
+ <br />
116
+ <small>Your card details will be stored securely with our payment provider.</small>
117
+ </label>
118
+ </li>
119
+ <?php endif; ?>
120
+ <style>
121
+ #payment_form_fatzebra .input-box:after {
122
+ content: '';
123
+ display: table;
124
+ clear: none;
125
+ }
126
+ #payment_form_fatzebra li {
127
+ position: relative;
128
+ }
129
+
130
+ #fatzebra_cc_display_number{
131
+ padding-left: 10px;
132
+ }
133
+ </style>
134
+ </ul>
135
+ </div>
app/design/frontend/base/default/template/mindarc/fatzebra/info.phtml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php if($_info = $this->getInfo()): ?>
2
+ <?php echo $this->__('Name on the Card: %s', $this->htmlEscape($this->getInfo()->getCcOwner())) ?><br />
3
+ <?php echo $this->__('Credit Card Type: %s', $this->htmlEscape($this->getCcTypeName())) ?><br />
4
+ <?php echo $this->__('Credit Card Number: xxxx-%s', $this->htmlEscape($this->getInfo()->getCcLast4())) ?><br />
5
+ <?php echo $this->__('Expiration Date: %s/%s', $this->htmlEscape($this->getCcExpMonth()), $this->htmlEscape($this->getInfo()->getCcExpYear())) ?>
6
+ <?php else: ?>
7
+ Credit Card
8
+ <?php endif; ?>
app/etc/modules/MindArc_Fatzebra.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <MindArc_FatZebra>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <depends>
8
+ <Mage_Payment />
9
+ </depends>
10
+ </MindArc_FatZebra>
11
+ </modules>
12
+ </config>
js/fatzebra/fatzebra.js ADDED
@@ -0,0 +1,351 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // V2.1.1
2
+
3
+ // IO_BB for Fraud Detection
4
+ var io_install_flash = false;
5
+ var io_bbout_element_id = 'fatzebra_io_bb';
6
+ var io_enable_rip = true;
7
+ var io_install_stm = false;
8
+ var io_exclude_stm = 12;
9
+ var originalPaymentSave;
10
+
11
+ Event.observe(window, "load", function () {
12
+ document.observe('payment-method:switched', function (e) {
13
+ var togglePaymentFields = function() {
14
+ if ($$('[name=use_saved_card]:checked').length > 0 && $$('[name=use_saved_card]:checked')[0].value == 1) {
15
+ // Disable/fade-out form
16
+ $('payment_form_fatzebra_entry').style.opacity = 0.5;
17
+ $$('#payment_form_fatzebra_entry input').each(function(item) {
18
+ item.disable();
19
+ item.removeClassName('required-entry');
20
+ });
21
+ $$('#payment_form_fatzebra_entry select').each(function(item) {
22
+ item.disable();
23
+ item.removeClassName('required-entry');
24
+ });
25
+
26
+ $('fatzebra_cc_cid').removeClassName('validate-cc-cvn');
27
+ } else {
28
+ $('payment_form_fatzebra_entry').style.opacity = 1.0;
29
+ $$('#payment_form_fatzebra_entry input').each(function(item) {
30
+ item.enable();
31
+ if (item.id !== "fatzebra_cc_save")
32
+ item.addClassName('required-entry');
33
+ });
34
+ $$('#payment_form_fatzebra_entry select').each(function(item) {
35
+ item.enable();
36
+ item.addClassName('required-entry');
37
+ });
38
+
39
+ $('fatzebra_cc_cid').addClassName('validate-cc-cvn');
40
+ }
41
+ };
42
+ $$('[name=use_saved_card]').invoke('observe', 'click', togglePaymentFields);
43
+ togglePaymentFields();
44
+ if ($('fatzebra_io_bb')) {
45
+ if (e.memo.method_code == 'fatzebra') {
46
+ // Load io_bb if not setup here...
47
+ var s = document.createElement('script');
48
+ s.src = 'https://mpsnare.iesnare.com/snare.js';
49
+ s.id = 'mpsnare';
50
+ document.getElementsByTagName('head')[0].appendChild(s);
51
+ }
52
+
53
+ $('fatzebra_io_bb').disabled = false;
54
+ $('fatzebra_cc_type').disabled = false;
55
+ }
56
+
57
+ if ($('fz_directpost_enabled') && e.memo.method_code == 'fatzebra') {
58
+ // Remove the 'name=' attr from the inputs so they aren't sent back to the server...
59
+ $('fatzebra_cc_owner').removeAttribute('name');
60
+ $('fatzebra_cc_number').removeAttribute('name');
61
+ $('fatzebra_cc_cid').removeAttribute('name');
62
+
63
+ // Hook the submit method and direct data to FZ, then update the hidden fields and submit to Magento...
64
+
65
+ if(typeof originalPaymentSave == 'undefined') {
66
+ originalPaymentSave = window.payment.save;
67
+ }
68
+
69
+ window.payment.save = function () {
70
+ // Embed these in the form
71
+ if($$('[name=use_saved_card]:checked').length > 0 && $$('[name=use_saved_card]:checked')[0].value == 1){
72
+ originalPaymentSave.apply(window.payment);
73
+ return;
74
+ }
75
+ var gwUrl = $('fz_directpost_url').value;
76
+ var nonce = $('fz_directpost_nonce').value;
77
+ var verification= $('fz_directpost_verification').value;
78
+ var v = function(name) { return $('fatzebra_' + name).value; };
79
+
80
+ var req = new Ajax.JSONRequest(gwUrl, {
81
+ parameters: {
82
+ format: 'json',
83
+ card_holder: v('cc_owner'),
84
+ card_number: v('cc_number'),
85
+ expiry_month: v('expiration'),
86
+ expiry_year: v('expiration_yr'),
87
+ cvv: v('cc_cid'),
88
+ return_path: nonce,
89
+ verification: verification
90
+ },
91
+ onSuccess: function (response) {
92
+ if (response.responseJSON.r == 1) {
93
+ var form = $('co-payment-form');
94
+ form.insert(new Element('input', {type: 'hidden', name: 'payment[cc_number]', value: response.responseJSON.card_number}));
95
+ form.insert(new Element('input', {type: 'hidden', name: 'payment[cc_owner]', value: response.responseJSON.card_holder}));
96
+ form.insert(new Element('input', {type: 'hidden', name: 'payment[cc_token]', value: response.responseJSON.token}));
97
+ $('fatzebra_cc_cid').setAttribute('name', 'payment[cc_cid]');
98
+ originalPaymentSave.apply(window.payment);
99
+ } else if (response.responseJSON.r == 97) {
100
+ alert("Credit Card Validation Error - please check your card number and try again.");
101
+ } else {
102
+ alert("Sorry there has been an error attempting to validation your credit card details. Please try again.\n\nIf this error persists please contact the store owner.\n\nError Code: " + response.responseJSON.r);
103
+ }
104
+ },
105
+ onFailure: function (response) {
106
+ alert("Sorry there has been an error attempting to validation your credit card details. Please try again.\n\nIf this error persists please contact the store owner.");
107
+ }
108
+ })
109
+ }
110
+
111
+ if (window.checkout && window.checkout.LightcheckoutSubmit) {
112
+ window.checkout.LightcheckoutSubmit = (function () {
113
+ originalLightcheckoutSubmit = window.checkout.LightcheckoutSubmit;
114
+ return function() {
115
+ // Embed these in the form
116
+
117
+ if($$('[name=use_saved_card]:checked').length > 0 && $$('[name=use_saved_card]:checked')[0].value == 1){
118
+ originalLightcheckoutSubmit.apply(window.checkout);
119
+ return;
120
+ }
121
+ var gwUrl = $('fz_directpost_url').value;
122
+ var nonce = $('fz_directpost_nonce').value;
123
+ var verification= $('fz_directpost_verification').value;
124
+ var v = function(name) { return $('fatzebra_' + name).value; };
125
+
126
+ var req = new Ajax.JSONRequest(gwUrl, {
127
+ parameters: {
128
+ format: 'json',
129
+ card_holder: v('cc_owner'),
130
+ card_number: v('cc_number'),
131
+ expiry_month: v('expiration'),
132
+ expiry_year: v('expiration_yr'),
133
+ cvv: v('cc_cid'),
134
+ return_path: nonce,
135
+ verification: verification
136
+ },
137
+ onSuccess: function (response) {
138
+ if (response.responseJSON.r == 1) {
139
+ var form = $('payment_form_fatzebra');
140
+ form.insert(new Element('input', {type: 'hidden', name: 'payment[cc_number]', value: response.responseJSON.card_number}));
141
+ form.insert(new Element('input', {type: 'hidden', name: 'payment[cc_owner]', value: response.responseJSON.card_holder}));
142
+ form.insert(new Element('input', {type: 'hidden', name: 'payment[cc_token]', value: response.responseJSON.token}));
143
+ $('fatzebra_cc_cid').setAttribute('name', 'payment[cc_cid]');
144
+ originalLightcheckoutSubmit.apply(window.checkout);
145
+ } else if (response.responseJSON.r == 97) {
146
+ alert("Credit Card Validation Error - please check your card number and try again.");
147
+ } else {
148
+ alert("Sorry there has been an error attempting to validation your credit card details. Please try again.\n\nIf this error persists please contact the store owner.\n\nError Code: " + response.responseJSON.r);
149
+ }
150
+ },
151
+ onFailure: function (response) {
152
+ alert("Sorry there has been an error attempting to validation your credit card details. Please try again.\n\nIf this error persists please contact the store owner.");
153
+ }
154
+ })
155
+ }
156
+ })();
157
+ }
158
+ }
159
+ });
160
+ document.observe('keyup', function (e, el) {
161
+ if (el = e.findElement("#fatzebra_cc_number")) {
162
+ var value = $("fatzebra_cc_number").value;
163
+ if (value.length === 0) return;
164
+
165
+ var card_id, code;
166
+ if (value.match(/^4/)) {
167
+ card_id = "card-vi";
168
+ code = "VI";
169
+ }
170
+ if (value.match(/^5/)) {
171
+ card_id = "card-mc";
172
+ code = "MC";
173
+ }
174
+ if (value.match(/^(34|37)/)) {
175
+ card_id = "card-ae";
176
+ code = "AE";
177
+ }
178
+ if (value.match(/^(36)/)) {
179
+ card_id = "card-dic";
180
+ code = "DIC";
181
+ }
182
+ if (value.match(/^(35)/)) {
183
+ card_id = "card-jcb";
184
+ code = "JCB";
185
+ }
186
+ if (value.match(/^(65)/)) {
187
+ card_id = "card-di";
188
+ code = "DI";
189
+ }
190
+
191
+ $$("img.card-logo").each(function (x) {
192
+ if (x.id != card_id) {
193
+ $(x).setStyle({opacity: 0.5});
194
+ } else {
195
+ $(x).setStyle({opacity: 1.0});
196
+ }
197
+ });
198
+
199
+ $("fatzebra_cc_type").value = code;
200
+ }
201
+ });
202
+ });
203
+
204
+
205
+ /* JSON-P implementation for Prototype.js somewhat by Dan Dean (http://www.dandean.com)
206
+ *
207
+ * *HEAVILY* based on Tobie Langel's version: http://gist.github.com/145466.
208
+ * Might as well just call this an iteration.
209
+ *
210
+ * This version introduces:
211
+ * - Support for predefined callbacks (Necessary for OAuth signed requests, by @rboyce)
212
+ * - Partial integration with Ajax.Responders (Thanks to @sr3d for the kick in this direction)
213
+ * - Compatibility with Prototype 1.7 (Thanks to @soung3 for the bug report)
214
+ * - Will not break if page lacks a <head> element
215
+ *
216
+ * See examples in README for usage
217
+ *
218
+ * VERSION 1.1.2
219
+ *
220
+ * new Ajax.JSONRequest(url, options);
221
+ * - url (String): JSON-P endpoint url.
222
+ * - options (Object): Configuration options for the request.
223
+ */
224
+ Ajax.JSONRequest = Class.create(Ajax.Base, (function () {
225
+ var id = 0, head = document.getElementsByTagName('head')[0] || document.body;
226
+ return {
227
+ initialize: function ($super, url, options) {
228
+ $super(options);
229
+ this.options.url = url;
230
+ this.options.callbackParamName = this.options.callbackParamName || 'callback';
231
+ this.options.timeout = this.options.timeout || 10; // Default timeout: 10 seconds
232
+ this.options.invokeImmediately = (!Object.isUndefined(this.options.invokeImmediately)) ? this.options.invokeImmediately : true;
233
+
234
+ if (!Object.isUndefined(this.options.parameters) && Object.isString(this.options.parameters)) {
235
+ this.options.parameters = this.options.parameters.toQueryParams();
236
+ }
237
+
238
+ if (this.options.invokeImmediately) {
239
+ this.request();
240
+ }
241
+ },
242
+
243
+ /**
244
+ * Ajax.JSONRequest#_cleanup() -> undefined
245
+ * Cleans up after the request
246
+ **/
247
+ _cleanup: function () {
248
+ if (this.timeout) {
249
+ clearTimeout(this.timeout);
250
+ this.timeout = null;
251
+ }
252
+ if (this.transport && Object.isElement(this.transport)) {
253
+ this.transport.remove();
254
+ this.transport = null;
255
+ }
256
+ },
257
+
258
+ /**
259
+ * Ajax.JSONRequest#request() -> undefined
260
+ * Invokes the JSON-P request lifecycle
261
+ **/
262
+ request: function () {
263
+
264
+ // Define local vars
265
+ var response = new Ajax.JSONResponse(this);
266
+ var key = this.options.callbackParamName,
267
+ name = '_prototypeJSONPCallback_' + (id++),
268
+ complete = function () {
269
+ if (Object.isFunction(this.options.onComplete)) {
270
+ this.options.onComplete.call(this, response);
271
+ }
272
+ Ajax.Responders.dispatch('onComplete', this, response);
273
+ }.bind(this);
274
+
275
+ // If the callback parameter is already defined, use that
276
+ if (this.options.parameters[key] !== undefined) {
277
+ name = this.options.parameters[key];
278
+ }
279
+ // Otherwise, add callback as a parameter
280
+ else {
281
+ this.options.parameters[key] = name;
282
+ }
283
+
284
+ // Build request URL
285
+ this.options.parameters[key] = name;
286
+ var url = this.options.url + ((this.options.url.include('?') ? '&' : '?') + Object.toQueryString(this.options.parameters));
287
+
288
+ // Define callback function
289
+ window[name] = function (json) {
290
+ this._cleanup(); // Garbage collection
291
+ window[name] = undefined;
292
+
293
+ response.status = 200;
294
+ response.statusText = "OK";
295
+ response.setResponseContent(json);
296
+
297
+ if (Object.isFunction(this.options.onSuccess)) {
298
+ this.options.onSuccess.call(this, response);
299
+ }
300
+ Ajax.Responders.dispatch('onSuccess', this, response);
301
+
302
+ complete();
303
+
304
+ }.bind(this);
305
+
306
+ this.transport = new Element('script', { type: 'text/javascript', src: url });
307
+
308
+ if (Object.isFunction(this.options.onCreate)) {
309
+ this.options.onCreate.call(this, response);
310
+ }
311
+ Ajax.Responders.dispatch('onCreate', this);
312
+
313
+ head.appendChild(this.transport);
314
+
315
+ this.timeout = setTimeout(function () {
316
+ this._cleanup();
317
+ window[name] = Prototype.emptyFunction;
318
+ if (Object.isFunction(this.options.onFailure)) {
319
+ response.status = 504;
320
+ response.statusText = "Gateway Timeout";
321
+ this.options.onFailure.call(this, response);
322
+ }
323
+ complete();
324
+ }.bind(this), this.options.timeout * 1000);
325
+ },
326
+ toString: function () {
327
+ return "[object Ajax.JSONRequest]";
328
+ }
329
+ };
330
+ })());
331
+
332
+ Ajax.JSONResponse = Class.create({
333
+ initialize: function (request) {
334
+ this.request = request;
335
+ },
336
+ request: undefined,
337
+ status: 0,
338
+ statusText: '',
339
+ responseJSON: undefined,
340
+ responseText: undefined,
341
+ setResponseContent: function (json) {
342
+ this.responseJSON = json;
343
+ this.responseText = Object.toJSON(json);
344
+ },
345
+ getTransport: function () {
346
+ if (this.request) return this.request.transport;
347
+ },
348
+ toString: function () {
349
+ return "[object Ajax.JSONResponse]";
350
+ }
351
+ });
media/payments/AE.png ADDED
Binary file
media/payments/DI.png ADDED
Binary file
media/payments/DIS.png ADDED
Binary file
media/payments/Fat-Zebra-Certified-small.png ADDED
Binary file
media/payments/JCB.png ADDED
Binary file
media/payments/MC.png ADDED
Binary file
media/payments/VI.png ADDED
Binary file
media/payments/mindarc.png ADDED
Binary file
package.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>MindArc_FatZebra</name>
4
+ <version>2.1.1</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/OSL-3.0">OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Accept Credit Card Payments quickly and simply with Fat Zebra</summary>
10
+ <description>Fat Zebra Online Payment Gateway Module&#xD;
11
+ &#xD;
12
+ &#xD;
13
+ The Fat Zebra extension for Magento simplifies the way you take payments for all credit cards allowing you to trade around the clock. Our extension makes running your online store Simple, Secure and Reliable.</description>
14
+ <notes>This release fixed issues with floating point conversions and client side issues around validation requirements for checkboxes.&#xD;
15
+ &#xD;
16
+ In addition to this support for GoMage Lightcheckout has also been added.</notes>
17
+ <authors><author><name>Matthew Savage</name><user>fatzebra</user><email>support@fatzebra.com.au</email></author><author><name>Sean Pieres</name><user>mindarc</user><email>seanp@mindarc.com.au</email></author></authors>
18
+ <date>2014-12-08</date>
19
+ <time>13:00:48</time>
20
+ <contents><target name="magemedia"><dir name="payments"><file name="AE.png" hash="6618b2807e770477888355c125814e47"/><file name="DI.png" hash="08f295c0cd71873070faffd474c2ebf0"/><file name="DIS.png" hash="fe70dd42f08b5fa241722143ea56e014"/><file name="Fat-Zebra-Certified-small.png" hash="68bd23468e1d66fe62029fd2fa059eb9"/><file name="JCB.png" hash="7ab40a5e183b15a5984f93ac65d5d765"/><file name="MC.png" hash="81e6a33da57071995e7687de1e8000d4"/><file name="VI.png" hash="98fc2e691849e5e18d2ead52b3298467"/><file name="mindarc.png" hash="09c872e6e97839e43e2d2e4b6f3b10f7"/></dir></target><target name="mage"><dir name="js"><dir name="fatzebra"><file name="fatzebra.js" hash="8e694fff184a96cf47dbb7911e0df5cd"/></dir></dir></target><target name="magecommunity"><dir name="MindArc"><dir name="FatZebra"><dir name="Block"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><file name="Grid.php" hash="44225a01a1e1e55194a7c132ae4dc13c"/><dir name="View"><dir name="Tab"><file name="Fraud.php" hash="9dcee42431582eff82db97b3be4ae1b1"/></dir></dir></dir></dir><dir name="Widget"><dir name="Grid"><dir name="Column"><dir name="Renderer"><file name="Fraudresult.php" hash="d9d652317b3a034b0b52b53a9720e198"/></dir></dir></dir></dir></dir><file name="Form.php" hash="e63d82a273323015c0b0b2439863339c"/><file name="Jsinit.php" hash="3aae98d2a2cac4781e96a102ccfe2ff2"/></dir><dir name="Helper"><file name="Data.php" hash="be520e21277ddd35abeef11319b259af"/></dir><dir name="Model"><dir name="Adminhtml"><file name="Comment.php" hash="bde2e451f744cb60398d8fbe74d72ea7"/><dir name="Shipping"><file name="Enabledmethods.php" hash="ba53c9d5addf3952fbed2c8e0455f32a"/></dir></dir><file name="Cardtypes.php" hash="1376e47e915a0b374e505e2323524bae"/><file name="Customer.php" hash="f3aae80ff53d63f624883b1ae4402a06"/><dir name="Entity"><file name="Setup.php" hash="dd54e8fcb22ec3b828e64246a250b3e0"/></dir><file name="Filterfraud.php" hash="47ed142fc827caf20a3030d4cc7a5316"/><file name="Fraud.php" hash="ebfc7c40647656d4d9762d5e44482aef"/><dir name="Mysql4"><file name="Fraud.php" hash="ff163c045a95dfaafeed3258a0caaf98"/></dir><file name="Observer.php" hash="b913cb42094640c7f98893a4b98217da"/><file name="Payment.php" hash="c70d10b81af05c7a53521cf1bfdda08a"/><dir name="Source"><file name="Action.php" hash="12512aed4d86e924075ed530a1213b2e"/></dir></dir><dir name="controllers"><file name="IndexController.php" hash="a86df76a4536a04d5d0fac1c9278bbc2"/></dir><dir name="etc"><file name="config.xml" hash="dc25503638ff433289c00dac79377423"/><file name="system.xml" hash="21cd5acb2f2d335fe2eb04ac07649f2e"/></dir><dir name="sql"><dir name="fatzebra_setup"><file name="mysql4-install-0.1.1-2.0.5.php" hash="5cd350c0249c3b8627735f8d00069599"/><file name="mysql4-upgrade-2.0.5-2.0.6.php" hash="7c8256bb10e9cf1264fabd8ecd7c8ef4"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="fatzebra.xml" hash="0514cd22fc526c452773a74974d69992"/></dir><dir name="template"><dir name="fatzebra"><file name="jsinit.phtml" hash="5361a5dc068223c96b1a1d78f5819aea"/><file name="tab.phtml" hash="98f37d8aeaa98e67fb2a5889fa961f61"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="fatzebra.xml" hash="b53fda9a617066cc8e48a66ca076e55e"/></dir><dir name="template"><dir name="mindarc"><dir name="fatzebra"><file name="empty.phtml" hash="414ab6b84388449e8d1c62fd98bca2a4"/><file name="form.phtml" hash="aac2c151600696787b59190ec4728ba5"/><file name="info.phtml" hash="fbde0f91701a994791d788f6099784eb"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="MindArc_Fatzebra.xml" hash="8f5541d5893da02862a3a0ca4e6a6d9c"/></dir></target></contents>
21
+ <compatible/>
22
+ <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php><package><name>Mage_Payment</name><channel>core</channel><min></min><max></max></package></required></dependencies>
23
+ </package>