Df_DFraudIntegration - Version 1.0.0

Version Notes

The Dfraud integration performs 15 checks to identify the fruaud order so that its easy for site admins to identify fraud orders.

Download this release

Release Info

Developer Biju Thajudien
Extension Df_DFraudIntegration
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/local/Df/DFraudIntegration/Block/Adminhtml/Order/View/Tab/Dfraud.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * DFraud Integration plugin.
4
+ *
5
+ * @category Df
6
+ * @package Df_DFraudIntegration
7
+ * @author Biju Thajudien <mailtobiju@gmail.com>
8
+ * @version 0.1.0
9
+ */
10
+ class Df_DFraudIntegration_Block_Adminhtml_Order_View_Tab_Dfraud
11
+ extends Mage_Adminhtml_Block_Template
12
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
13
+ {
14
+ protected $_chat = null;
15
+
16
+ protected function _construct()
17
+ {
18
+ parent::_construct();
19
+ $result = $this->getFraudDetectionData();
20
+
21
+ Mage::register('data', $result);
22
+ $this->setTemplate('dfraudintegration/dfraud.phtml');
23
+ }
24
+
25
+ public function getTabLabel() {
26
+ return $this->__('Fraud Detection');
27
+ }
28
+
29
+ public function getTabTitle() {
30
+ return $this->__('Fraud Detection');
31
+ }
32
+
33
+ public function canShowTab() {
34
+ return true;
35
+ }
36
+
37
+ public function isHidden() {
38
+ return false;
39
+ }
40
+
41
+ public function getOrder(){
42
+ return Mage::registry('current_order');
43
+ }
44
+
45
+ public function getFraudDetectionData(){
46
+ if ($order = $this->getOrder()) {
47
+ //echo "<pre>";print_r($order->grand_total);exit;
48
+ $remote_ip = $order->getRemoteIp();
49
+
50
+ $helper = Mage::helper('dfraudintegration');
51
+ try {
52
+ $response = false;
53
+ $ipLocation = $helper->getIpLocation($remote_ip);
54
+
55
+ $shippingId = $order->getShippingAddressId();
56
+ $billingId = $order->getBillingAddressId();
57
+
58
+ $billingDetails = Mage::getModel('sales/order_address')->load($billingId);
59
+
60
+ $resource = Mage::getSingleton('core/resource');
61
+ $readConnection = $resource->getConnection('core_read');
62
+ $query = 'SELECT * FROM ' . $resource->getTableName('dfraudintegration/scores');
63
+ $scores = $readConnection->fetchAll($query);
64
+
65
+ //Perform address and IP checks
66
+ $result = $helper->checkAddress($shippingId, $billingId, $ipLocation, $scores);
67
+
68
+ //Check previous orders from user and ip
69
+ $order_history = $helper->getOrderHistory($order->customer_id, $order->getRemoteIp(), $scores);
70
+ //echo "<pre>";print_r($result);
71
+ $result['order_history_cust'] = $order_history;
72
+
73
+ //Check CC bin data
74
+ $payments = $order->getAllPayments();
75
+ $binData = $helper->getBinData($payments, $remote_ip, $billingDetails['country_id'], $scores);
76
+ $result['bin'] = $binData;
77
+
78
+ //Check the order amount
79
+ $amountData = $helper->checkOrderAmount($order->grand_total, $scores);
80
+ $result['ammount_check'] = $amountData;
81
+
82
+ //Get the score summary
83
+ $result['score'] = $helper->getResultTotalScore($result);
84
+ $summary = array_merge((array)$result['summary'], (array)$order_history['summary']
85
+ , (array)$binData['summary']
86
+ , (array)$amountData['summary']);
87
+ $summaryDesc = $helper->getRiskScoreDescription($scores, $summary);
88
+ $result['summary'] = $summaryDesc;
89
+
90
+ return $result;
91
+
92
+ }
93
+ catch (Mage_Core_Exception $e) {
94
+ $response = array(
95
+ 'error' => true,
96
+ 'message' => $e->getMessage(),
97
+ );
98
+ }
99
+ catch (Exception $e) {
100
+ $response = array(
101
+ 'error' => true,
102
+ 'message' => $this->__('Cannot get dfraud data.')
103
+ );
104
+ }
105
+ }
106
+ }
107
+
108
+ }
109
+ ?>
app/code/local/Df/DFraudIntegration/Block/Adminhtml/Sales/Order/Dfraud.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Deliverynote Block
5
+ *
6
+ * @category Dh
7
+ * @package Dh_Deliverynote
8
+ * @author Drew Hunter <drewdhunter@gmail.com>
9
+ * @version 0.1.0
10
+ */
11
+ class Df_DFraudIntegration_Block_Adminhtml_Sales_Order_Dfraud extends Mage_Adminhtml_Block_Template
12
+ {
13
+ private $_note;
14
+
15
+ protected function _prepareLayout()
16
+ {
17
+ $onclick = "submitAndReloadArea($('dfraudintegration').parentNode, '".$this->getSubmitUrl()."')";
18
+ $button = $this->getLayout()->createBlock('adminhtml/widget_button')
19
+ ->setData(array(
20
+ 'label' => Mage::helper('sales')->__('Get DFraud Data'),
21
+ 'class' => 'save',
22
+ 'onclick' => $onclick
23
+ ));
24
+ $this->setChild('submit_button', $button);
25
+ return parent::_prepareLayout();
26
+ }
27
+
28
+ public function getSubmitUrl()
29
+ {
30
+ return $this->getUrl('*/dfraud', array('order_id'=>$this->getOrder()->getId()));
31
+ }
32
+
33
+ /**
34
+ * Retrieve order model
35
+ *
36
+ * @return Mage_Sales_Model_Order
37
+ */
38
+ public function getOrder()
39
+ {
40
+ return Mage::registry('sales_order');
41
+ }
42
+
43
+ /**
44
+ * Based on the object being viewed i.e. order, invoice etc then
45
+ * lets get the note from the order if available
46
+ *
47
+ * @return void
48
+ */
49
+ private function _initNote()
50
+ {
51
+ echo "asdfadsfa";exit;
52
+ $noteId = '';
53
+
54
+ if (! is_null(Mage::registry('current_order'))) {
55
+ $noteId = Mage::registry('current_order')->getData('delivery_note_id');
56
+ }
57
+ elseif(! is_null(Mage::registry('current_shipment'))) {
58
+ $noteId = Mage::registry('current_shipment')->getOrder()->getData('delivery_note_id');
59
+ }
60
+ elseif(! is_null(Mage::registry('current_invoice'))) {
61
+ $noteId = Mage::registry('current_invoice')->getOrder()->getData('delivery_note_id');
62
+ }
63
+ elseif(! is_null(Mage::registry('current_creditmemo'))) {
64
+ $noteId = Mage::registry('current_creditmemo')->getOrder()->getData('delivery_note_id');
65
+ }
66
+
67
+ if ($noteId != '') {
68
+ $this->_note = Mage::getModel('deliverynote/note')->load($noteId)->getNote();
69
+ }
70
+ }
71
+
72
+ /**
73
+ * Initialise the delivery instruction and return
74
+ *
75
+ * @return mixed bool|string
76
+ */
77
+ protected function getNote()
78
+ {
79
+
80
+ if (is_null($this->_note)) {
81
+ $this->_initNote();
82
+ }
83
+ return empty($this->_note) ? false : $this->_note;
84
+ }
85
+ }
app/code/local/Df/DFraudIntegration/Helper/Data.php ADDED
@@ -0,0 +1,649 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * DFraud Integration plugin.
5
+ *
6
+ * @category Df
7
+ * @package Df_DFraudIntegration
8
+ * @author Biju Thajudien <mailtobiju@gmail.com>
9
+ * @version 0.1.0
10
+ */
11
+
12
+ class Df_DFraudIntegration_Helper_Data extends Mage_Core_Helper_Abstract
13
+ {
14
+ /**
15
+ * Return the front end label as defined in config
16
+ *
17
+ * @return string
18
+ */
19
+ public function getFrontendLabel()
20
+ {
21
+ return Mage::getStoreConfig('dfraudintegration_options/basic_settings/frontend_label');
22
+ }
23
+
24
+ public function getLicenceKey() {
25
+ return Mage::getStoreConfig('dfraudintegration_options/basic_settings/licence_key');
26
+ }
27
+
28
+ public function getIpLocation($ip){
29
+ $location_details = array();
30
+
31
+ $geoIpUrl = 'http://www.geobytes.com/IpLocator.htm?GetLocation&template=php3.txt&IpAddress='.$ip;
32
+ $tags = get_meta_tags($geoIpUrl);
33
+
34
+ $location_details['ip'] = $ip;
35
+ $location_details['known'] = $tags['known'];
36
+ $location_details['country'] = $tags['country'];
37
+ $location_details['region'] = $tags['region'];
38
+ $location_details['regioncode'] = $tags['regioncode'];
39
+ $location_details['city'] = $tags['city'];
40
+ $location_details['latitude'] = $tags['latitude'];
41
+ $location_details['longitude'] = $tags['longitude'];
42
+ $location_details['timezone'] = $tags['timezone'];
43
+ $location_details['country_id'] = $tags['iso2'];
44
+
45
+ //print_r($tags);
46
+
47
+ return $location_details;
48
+ }
49
+
50
+ public function checkAddress($shippingId, $billingId, $ipLocation, $scores){
51
+ $checks = array('region','postcode','lastname','street','city','email','telephone','country_id','firstname',
52
+ 'middlename');
53
+
54
+ $ipChecks = array('region','city','country_id');
55
+
56
+ $mismatch = array();
57
+
58
+ $shippingDetails = Mage::getModel('sales/order_address')->load($shippingId);
59
+ $billingDetails = Mage::getModel('sales/order_address')->load($billingId);
60
+
61
+ //check if the address exist with google geocode
62
+ //$this->p($scores);
63
+ $shippingGeoResult = $this->checkAddressExist($shippingDetails);
64
+ $billingGeoResult = $this->checkAddressExist($billingDetails);
65
+
66
+ $mismatch['shippingGeoResult'] = $shippingGeoResult;
67
+ $mismatch['billingGeoResult'] = $billingGeoResult;
68
+
69
+ //$this->p($shippingGeoResult);$this->p($billingGeoResult);
70
+ //Distance between billing and shipping address
71
+ $mismatch['dis']['bill_ship'] = $this->distance($shippingGeoResult['loc']['location'], $billingGeoResult['loc']['location']);
72
+
73
+ $ipLatLon['lat'] = $ipLocation['latitude'];
74
+ $ipLatLon['lng'] = $ipLocation['longitude'];
75
+ $mismatch['dis']['ip_ship'] = $this->distance($ipLatLon, $shippingGeoResult['loc']['location']);
76
+
77
+ $mismatch['dis']['ip_bill'] = $this->distance($ipLatLon, $billingGeoResult['loc']['location']);
78
+
79
+ $max_distance = Mage::getStoreConfig('dfraudintegration_options/dfraud_module_settings/maximum_distance');
80
+ $mismatch['dis']['score']['total'] = 0;
81
+ if($mismatch['dis']['ip_bill'] > $max_distance) {
82
+ $mismatch['dis']['score']['total'] = $this->getScore($scores,'dis_bill_ip');
83
+ $summary['dis_bill_ip'] = 1;
84
+ }
85
+ $mismatch['dis']['score']['max'] = $this->getModuleTotalScore($scores,array('dis_bill_ip'));
86
+
87
+ //check if billing and shipping address match
88
+ $addressDiff = false;
89
+ foreach($checks as $param){
90
+ if($shippingDetails[$param] != $billingDetails[$param]) {
91
+ $addressDiff = true;
92
+ $mismatch['address'][$param]['billing'] = $billingDetails[$param];
93
+ $mismatch['address'][$param]['shipping'] = $shippingDetails[$param];
94
+ }
95
+ }
96
+
97
+ $mismatch['address']['score']['total'] = 0;
98
+ if($addressDiff) {
99
+ $mismatch['address']['score']['total'] = $this->getScore($scores,'address_bill_ship');
100
+ $summary['address_bill_ship'] = 1;
101
+ }
102
+ $mismatch['address']['score']['max'] = $this->getModuleTotalScore($scores,array('address_bill_ship'));
103
+
104
+ //compare ip address with billing and shipping address
105
+ $mismatch['ip']['location'] = $ipLocation;
106
+ $mismatch['ip']['location']['loc_str'] = $ipLocation['city'].", ".$ipLocation['region'].", ".$ipLocation['country'];
107
+ foreach($ipChecks as $param){
108
+ if(! $this->isStringEqual($ipLocation[$param], $billingDetails[$param])) {
109
+ $mismatch['ip']['ip_bill_diff'][$param] = 1;
110
+ $mismatch['ip']['score'][$param] = $this->getScore($scores,'ip_bill_'.$param);
111
+ $summary['ip_bill_'.$param] = 1;
112
+ }
113
+ if(! $this->isStringEqual($ipLocation[$param], $shippingDetails[$param])) {
114
+ $mismatch['ip']['ip_ship_diff'][$param] = 1;
115
+ }
116
+ //if($ipLocation[$param] != $billingDetails[$param]) {
117
+ $mismatch['ip'][$param]['ip'] = $ipLocation[$param];
118
+ $mismatch['ip'][$param]['billing'] = $billingDetails[$param];
119
+ //}
120
+ //if($ipLocation[$param] != $shippingDetails[$param]) {
121
+ $mismatch['ip'][$param]['ip'] = $ipLocation[$param];
122
+ $mismatch['ip'][$param]['shipping'] = $shippingDetails[$param];
123
+ //}
124
+ }
125
+
126
+
127
+ $total = 0;
128
+ foreach($mismatch['ip']['score'] as $ip_scores){
129
+ $total += $ip_scores;
130
+ }
131
+ $module_max = $this->getModuleTotalScore($scores, array('ip_bill_city','ip_bill_region','ip_bill_country_id'));
132
+ $mismatch['ip']['score']['total'] = $total;
133
+ $mismatch['ip']['score']['max'] = $module_max;
134
+
135
+
136
+ //check high risk country
137
+ $resource = Mage::getSingleton('core/resource');
138
+ $readConnection = $resource->getConnection('core_read');
139
+ $query = 'SELECT * FROM ' . $resource->getTableName('dfraudintegration/highriskcountries');
140
+ $results = $readConnection->fetchAll($query);
141
+
142
+ $country_id = 'country_id';
143
+ foreach($results as $highRisk) {
144
+ // var_dump($highRisk);
145
+ if($ipLocation[$country_id] == $highRisk[$country_id]) {
146
+ $mismatch['hrc']['ip'] = true;
147
+ $mismatch['hrc']['score']['ip'] = $this->getScore($scores,'hr_ip');
148
+ $summary['hr_ip'] = 1;
149
+ }
150
+ if($shippingDetails[$country_id] == $highRisk[$country_id]) {
151
+ $mismatch['hrc']['shipping'] = true;
152
+ $mismatch['hrc']['score']['shipping'] = $this->getScore($scores,'hr_ship');
153
+ $summary['hr_ship'] = 1;
154
+ }
155
+ if($billingDetails[$country_id] == $highRisk[$country_id]) {
156
+ $mismatch['hrc']['billing'] = true;
157
+ $mismatch['hrc']['score']['billing'] = $this->getScore($scores,'hr_bill');
158
+ $summary['hr_bill'] = 1;
159
+ }
160
+ }
161
+
162
+ $hrctotal = 0;
163
+ foreach($mismatch['hrc']['score'] as $hrcscore) {
164
+ $hrctotal += $hrcscore;
165
+ }
166
+ $mismatch['hrc']['score']['total'] = $hrctotal;
167
+ $mismatch['hrc']['score']['max'] = $this->getModuleTotalScore($scores,array('hr_ip','hr_ship','hr_bill'));
168
+
169
+ //Email valid check
170
+ $email_result = $this->checkEmailValid($order->customer_email);
171
+ $mismatch['email'] = $email_result;
172
+
173
+ //Check postal codes
174
+ $post_loc_bill = $this->checkPostalCode($billingDetails['postcode'],$billingDetails['country_id']);
175
+
176
+ //print_r($post_loc_bill);
177
+ if(!empty($post_loc_bill['postalcodes'])) {
178
+ foreach($post_loc_bill['postalcodes'] as $postCode) {
179
+ if($this->isStringContains($billingDetails['street'], $postCode['placeName'])){
180
+ $loc = $postCode['placeName'];
181
+ $loc .= ", ".$postCode['adminName1'];
182
+ $loc .= ", ".$postCode['countryCode'];
183
+ break;
184
+ }
185
+ }
186
+ if($loc != ""){
187
+ $mismatch['post_loc']['billing'] = $loc;
188
+ } else {
189
+ $loc = "<strong>Address and postal code exact match not found.<br>Matches for postal code (".
190
+ $post_loc_bill['postalcodes'][0]['postalcode']."):</strong><br>";
191
+ foreach($post_loc_bill['postalcodes'] as $postCode) {
192
+ $loc .= $postCode['placeName'];
193
+ if(!is_null($postCode['adminName1']))
194
+ $loc .= ", ".$postCode['adminName1'];
195
+ $loc .= ", ".$postCode['countryCode'];
196
+ $loc .= "<br>";
197
+ }
198
+ $mismatch['post_loc']['billing'] = $loc;
199
+ }
200
+
201
+ } else {
202
+ $mismatch['post_loc']['billing'] = "NOT FOUND";
203
+ }
204
+
205
+ if($mismatch['post_loc']['billing'] == "NOT FOUND") {
206
+ $mismatch['post_loc']['score']['billing'] = $this->getScore($scores, 'zip_bill');
207
+ $summary['zip_bill'] = 1;
208
+ }
209
+
210
+ if($billingDetails['postcode'] != $shippingDetails['postcode']
211
+ || $billingDetails['country_id'] != $shippingDetails['country_id']) {
212
+
213
+ $post_loc_ship = $this->checkPostalCode($shippingDetails['postcode'],$shippingDetails['country_id']);
214
+ //print_r($post_loc_ship);
215
+ $loc = "";
216
+ if(!empty($post_loc_ship['postalcodes'])) {
217
+ foreach($post_loc_ship['postalcodes'] as $postCode) {
218
+ if($this->isStringContains($shippingDetails['street'], $postCode['placeName'])){
219
+ $loc = $postCode['placeName'];
220
+ $loc .= ", ".$postCode['adminName1'];
221
+ $loc .= ", ".$postCode['countryCode'];
222
+ break;
223
+ }
224
+ }
225
+ if($loc != ""){
226
+ $mismatch['post_loc']['shipping'] = $loc;
227
+ } else {
228
+ $loc = "<strong>Address and postal code exact match not found. <br>Matches for postal code (".
229
+ $post_loc_ship['postalcodes'][0]['postalcode']."):</strong><br>";
230
+ foreach($post_loc_ship['postalcodes'] as $postCode) {
231
+ $loc .= $postCode['placeName'];
232
+ if(!is_null($postCode['adminName1']))
233
+ $loc .= ", ".$postCode['adminName1'];
234
+ $loc .= ", ".$postCode['countryCode'];
235
+ $loc .= "<br>";
236
+ }
237
+ $mismatch['post_loc']['shipping'] = $loc;
238
+ }
239
+ } else {
240
+ $mismatch['post_loc']['shipping'] = "NOT FOUND";
241
+ }
242
+
243
+ } else {
244
+ $mismatch['post_loc']['shipping'] = $mismatch['post_loc']['billing'];
245
+ }
246
+
247
+ if($mismatch['post_loc']['shipping'] == "NOT FOUND") {
248
+ $mismatch['post_loc']['score']['shipping'] = $this->getScore($scores, 'zip_ship');
249
+ $summary['zip_ship'] = 1;
250
+ }
251
+
252
+ $ziptotal = 0;
253
+ foreach($mismatch['post_loc']['score'] as $zipscore) {
254
+ $ziptotal += $zipscore;
255
+ }
256
+ $mismatch['post_loc']['score']['total'] = $ziptotal;
257
+ $mismatch['post_loc']['score']['max'] = $this->getModuleTotalScore($scores,array('zip_bill','zip_ship'));
258
+
259
+ $mismatch['summary'] = $summary;
260
+ //$this->p($mismatch);exit;
261
+ return $mismatch;
262
+ }
263
+
264
+ public function getOrderHistory($custId, $ip, $scores){
265
+ //Get the order history of the customer
266
+ $orders = Mage::getResourceModel('sales/order_collection')
267
+ ->addFieldToSelect('*')
268
+ ->addFieldToFilter('customer_id', $custId);
269
+ $order_count = count($orders->getItems());
270
+
271
+ $orders_ip = Mage::getResourceModel('sales/order_collection')
272
+ ->addFieldToSelect('*')
273
+ ->addFieldToFilter('remote_ip', $ip);
274
+ $order_count_ip = count($orders_ip->getItems());
275
+
276
+ $resource = Mage::getSingleton('core/resource');
277
+ $readConnection = $resource->getConnection('core_read');
278
+ $query = 'SELECT * FROM ' . $resource->getTableName('sales/order_status');
279
+ $statuss = $readConnection->fetchAll($query);
280
+
281
+
282
+ //$this->p($results);
283
+ $order_status['count'] = $order_count;
284
+ foreach($statuss as $status) {
285
+ $order_status['status'][$status['label']] = 0;
286
+ foreach($orders as $order) {
287
+ if($order->getStatus() == $status['status']) {
288
+ $order_status['status'][$status['label']] ++;
289
+ }
290
+ }
291
+ }
292
+
293
+ $order_status_ip['count'] = $order_count_ip;
294
+ foreach($statuss as $status) {
295
+ $order_status_ip['status'][$status['label']] = 0;
296
+ foreach($orders_ip as $order) {
297
+ if($order->getStatus() == $status['status']) {
298
+ $order_status_ip['status'][$status['label']] ++;
299
+ }
300
+ }
301
+ }
302
+
303
+ $user_orders = array("user" => $order_status,"ip"=>$order_status_ip);
304
+
305
+ $user_orders['count']['score']['order_hist_count_ip_user'] = 0;
306
+ if($order_status_ip['count'] != $order_status['count'] ) {
307
+ $user_orders['count']['score']['order_hist_count_ip_user'] = $this->getScore($scores, 'order_hist_count_ip_user');
308
+ }
309
+
310
+ $fraudLabels = array('Suspected Fraud');
311
+ foreach($fraudLabels as $fraudLabel) {
312
+ if($order_status_ip['status'][$fraudLabel] > 0) {
313
+ $user_orders['ip']['score']['order_hist_fraud'] = $this->getScore($scores, 'order_hist_fraud');
314
+ $summary['order_hist_fraud'] = 1;
315
+ }
316
+ }
317
+
318
+ foreach($fraudLabels as $fraudLabel) {
319
+ if($order_status['status'][$fraudLabel] > 0) {
320
+ $user_orders['user']['score']['order_hist_fraud'] = $this->getScore($scores, 'order_hist_fraud');
321
+ $summary['order_hist_fraud'] = 1;
322
+ }
323
+ }
324
+
325
+ $total = $user_orders['count']['score']['order_hist_count_ip_user'] +
326
+ ( $user_orders['ip']['score']['order_hist_fraud'] > 0 ? $user_orders['ip']['score']['order_hist_fraud'] :
327
+ $user_orders['user']['score']['order_hist_fraud'] );
328
+
329
+ if($order_count == 1) {
330
+ $total += $this->getScore($scores, 'order_hist_first_order');
331
+ $summary['order_hist_first_order'] = 1;
332
+ }
333
+
334
+ $user_orders['score']['total'] = $total;
335
+ $user_orders['score']['max'] = $this->getModuleTotalScore($scores,array('order_hist_count_ip_user',
336
+ 'order_hist_fraud',
337
+ 'order_hist_first_order'));
338
+ $user_orders['summary'] = $summary;
339
+ //$this->p($user_orders);exit;
340
+
341
+ return $user_orders;
342
+ }
343
+
344
+ private function isStringContains($major, $minor){
345
+ $major = str_replace(' ','',$major);
346
+ $minor = str_replace(' ','',$minor);
347
+
348
+ return strpos(strtoupper($major), strtoupper($minor));
349
+ }
350
+
351
+ private function isStringEqual($major, $minor){
352
+ $major = str_replace(' ','',$major);
353
+ $minor = str_replace(' ','',$minor);
354
+
355
+ return strcasecmp($major,$minor) == 0 ? true : false;
356
+ }
357
+
358
+ public function checkPostalCode($postcode,$country) {
359
+ // Build validation request
360
+ $Params = array('postalcode' => $postcode,
361
+ 'country' => $country,
362
+ 'username' => 'dfraud');
363
+ $Request = @http_build_query($Params);
364
+ $ctxData = array(
365
+ 'method' => "GET",
366
+ 'header' => "Connection: close\r\n".
367
+ "Content-Length: ".strlen($Request)."\r\n",
368
+ 'content'=> $Request);
369
+ $ctx = @stream_context_create(array('http' => $ctxData));
370
+
371
+ $api = "http://api.geonames.org/postalCodeLookupJSON?".$Request;
372
+ $json = @file_get_contents($api, false, null);
373
+ $result = json_decode($json, true);
374
+
375
+ return $result;
376
+ }
377
+
378
+ public function checkEmailValid($email) {
379
+ // Build validation request
380
+ $Params = array('email' => $email,
381
+ 'api' => '987588a43b3');
382
+ $Request = @http_build_query($Params);
383
+ $ctxData = array(
384
+ 'method' => "GET",
385
+ 'header' => "Connection: close\r\n".
386
+ "Content-Length: ".strlen($Request)."\r\n",
387
+ 'content'=> $Request);
388
+ $ctx = @stream_context_create(array('http' => $ctxData));
389
+
390
+ // Check validation result
391
+ $APIUrl = 'http://123airtime.com/email_verify/email_verifier.php?'.$Request;
392
+ $json = @file_get_contents($APIUrl, false, null);
393
+ $json = iconv('UTF-8', 'ISO-8859-1//TRANSLIT//IGNORE', $json);
394
+
395
+ $result = json_decode($json, true);
396
+
397
+ //print_r($result);
398
+ return $result['result'];
399
+ }
400
+ public function p($data){
401
+ echo("<pre>");
402
+ print_r($data);
403
+ }
404
+
405
+ private function checkAddressExist($address){
406
+
407
+ $addressStr = $address->street;
408
+ if(!is_null($address->city)) {
409
+ $addressStr .= ','.$address->city;
410
+ }
411
+ if(!is_null($address->region)) {
412
+ $addressStr .= ','.$address->region;
413
+ }
414
+ if(!is_null($address->country_id)) {
415
+ $addressStr .=','.$address->country_id;
416
+ }
417
+ $api = "http://maps.googleapis.com/maps/api/geocode/json?address=";
418
+ $APIUrl = $api.urlencode($addressStr).'&sensor=true';
419
+ $json = @file_get_contents($APIUrl, false, null);
420
+ $result_loc = json_decode($json,true);
421
+
422
+ if($result_loc['status'] == 'ZERO_RESULTS') {
423
+ $street = explode("\n", $address->street);
424
+ $addressStr = $street[1].','.$address->city.','.$address->country_id;
425
+ $APIUrl = $api.urlencode($addressStr).'&sensor=true';
426
+ $json = @file_get_contents($APIUrl, false, null);
427
+ $result_street = json_decode($json,true);
428
+
429
+ if($result_street['status'] == 'ZERO_RESULTS') {
430
+ $addressStr = $address->city.','.$address->country_id;
431
+ $APIUrl = $api.urlencode($addressStr).'&sensor=true';
432
+ $json = @file_get_contents($APIUrl, false, null);
433
+ $result_city = json_decode($json,true);
434
+
435
+ if($result_city['status'] == 'ZERO_RESULTS') {
436
+ $address_result['status'] = 0;
437
+ $address_result['type'] = 'City';
438
+ } else {
439
+ $address_result['status'] = 1;
440
+ $address_result['type'] = 'City';
441
+ $address_result['loc'] = $result_city['results'][0]['geometry']['location'];
442
+ $address_result['formatted_address'] = $result_city['results'][0]['formatted_address'];
443
+ $address_result['url'] = $APIUrl;
444
+ }
445
+ } else {
446
+ $address_result['status'] = 1;
447
+ $address_result['type'] = 'Street';
448
+ $address_result['loc'] = $result_street['results'][0]['geometry']['location'];
449
+ $address_result['formatted_address'] = $result_street['results'][0]['formatted_address'];
450
+ $address_result['url'] = $APIUrl;
451
+ }
452
+ } else {
453
+ $address_result['status'] = 1;
454
+ $address_result['type'] = 'Full';
455
+ $address_result['loc'] = $result_loc['results'][0]['geometry'];
456
+ $address_result['formatted_address'] = $result_loc['results'][0]['formatted_address'];
457
+ $address_result['url'] = $APIUrl;
458
+
459
+ }
460
+ //$this->p($addressStr);
461
+ return $address_result;
462
+ }
463
+
464
+ private function distance($loc1, $loc2) {
465
+ $pi80 = M_PI / 180;
466
+ $lat1 = $loc1['lat']; $lng1 = $loc1['lng'];
467
+ $lat2 = $loc2['lat']; $lng2 = $loc2['lng'];
468
+
469
+ $lat1 *= $pi80;
470
+ $lng1 *= $pi80;
471
+ $lat2 *= $pi80;
472
+ $lng2 *= $pi80;
473
+
474
+ $r = 6372.797; // mean radius of Earth in km
475
+ $dlat = $lat2 - $lat1;
476
+ $dlng = $lng2 - $lng1;
477
+ $a = sin($dlat / 2) * sin($dlat / 2) + cos($lat1) * cos($lat2) * sin($dlng / 2) * sin($dlng / 2);
478
+ $c = 2 * atan2(sqrt($a), sqrt(1 - $a));
479
+ $km = $r * $c;
480
+
481
+ return ceil($km);
482
+ }
483
+
484
+ private function getScore($scores, $key){
485
+ foreach($scores as $score) {
486
+ if($score['field'] == $key) {
487
+ return $score['score'];
488
+ }
489
+ }
490
+ }
491
+
492
+ private function getModuleTotalScore($scores, $keys){
493
+ foreach($scores as $score) {
494
+ if(in_array($score['field'],$keys)) {
495
+ $total += $score['score'];
496
+ }
497
+ }
498
+ return $total;
499
+ }
500
+
501
+ public function getBinData($payments, $ip, $country_id, $scores){
502
+
503
+ foreach($payments as $pay) {
504
+ $payData = $pay->getData();
505
+ $ccEncrypt = $payData['cc_number_enc'];
506
+ if(isset($ccEncrypt)) {
507
+ $ccBinNo = substr($pay->decrypt($ccEncrypt), 0, 6);
508
+ $encyptedBin = $this->encrypt($ccBinNo);
509
+ //echo "Encrypted=".$encypted;
510
+ //echo "Decypted=".$this->decrypt($encypted);exit;
511
+
512
+ $params = array('apikey' => $this->getLicenceKey(),
513
+ 'ccBin' => $encyptedBin,
514
+ 'ip' => $ip,
515
+ 'country' => $country_id);
516
+ $url = 'http://ecomshopsecurity.com/dfraud_checks/bin/BinData.php';
517
+ $result_api = $this->getApiResult($params, $url);
518
+
519
+ /*$result_api = array('bin'=>
520
+ array('binCountry' => 'US', 'binName' => 'State Bank of India',
521
+ 'binPhone' => '123456'),
522
+ 'lic'=>array('result'=>0, 'err'=>"User request exceeded free limit of 50 requests. <br/>Please update your licence from<br/>
523
+ <a href=\"http://ecomshopsecurity.com/index.php/dfraud-integration.html\" target=\"_blank\">http://ecomshopsecurity.com/index.php/dfraud-integration.html</a>"));*/
524
+
525
+ $result = $result_api['bin'];
526
+ if($result_api['lic']['result'] == 1) {
527
+ if($country_id != $result['binCountry']) {
528
+ $result['country_match'] = "NO";
529
+ $result['score']['total'] = $this->getScore($scores, 'bin_country');
530
+ $summary['bin_country'] = 1;
531
+ } else {
532
+ $result['score']['total'] = 0;
533
+ $result['country_match'] = "YES";
534
+ }
535
+ } else {
536
+ $result = array('binCountry' => '-', 'binName' => '-', 'binPhone' => '-');
537
+ $result['country_match'] = "-";
538
+ $result['score']['total'] = 0;
539
+ $result['non_cc'] = 1;
540
+ $result['err'] = $result_api['lic']['err'];
541
+ }
542
+
543
+ } else {
544
+ $result = array('binCountry' => '-', 'binName' => '-', 'binPhone' => '-');
545
+ $result['country_match'] = "-";
546
+ $result['score']['total'] = 0;
547
+ $result['non_cc'] = 1;
548
+ }
549
+ }
550
+
551
+ $result['score']['max'] = $this->getModuleTotalScore($scores,array('bin_country'));
552
+ $result['summary'] = $summary;
553
+
554
+ //$this->p($result); exit;
555
+ return $result;
556
+ }
557
+
558
+ private function encrypt($str) {
559
+ $key = "80cdc815";
560
+ $block = mcrypt_get_block_size('des', 'ecb');
561
+ $pad = $block - (strlen($str) % $block);
562
+ $str .= str_repeat(chr($pad), $pad);
563
+
564
+ $ecrypt = mcrypt_encrypt(MCRYPT_DES, $key, $str, MCRYPT_MODE_ECB);
565
+
566
+ return base64_encode($ecrypt);
567
+ }
568
+
569
+ public function getApiResult($params, $url) {
570
+ $Request = @http_build_query($params);
571
+ $ctxData = array(
572
+ 'method' => "GET",
573
+ 'header' => "Connection: close\r\n".
574
+ "Content-Length: ".strlen($Request)."\r\n",
575
+ 'content'=> $Request);
576
+ $ctx = @stream_context_create(array('http' => $ctxData));
577
+
578
+ $APIUrl = $url.'?'.$Request;
579
+
580
+ $json = @file_get_contents($APIUrl, false, null);
581
+ $json = iconv('UTF-8', 'ISO-8859-1//TRANSLIT//IGNORE', $json);
582
+
583
+ return json_decode($json, true);
584
+
585
+ }
586
+
587
+ public function getResultTotalScore($results) {
588
+
589
+ $total = 0; $max = 0;
590
+ foreach($results as $key => $a_result) {
591
+ if(is_array($a_result)) {
592
+ $total += $a_result['score']['total'];
593
+ $max += $a_result['score']['max'];
594
+ }
595
+ }
596
+ $m_result = array();
597
+ $m_result['total'] = $total;
598
+ $m_result['max'] = $max;
599
+
600
+ return $m_result;
601
+ }
602
+
603
+ public function getRiskScoreDescription($scores, $fields) {
604
+ $i = 0;
605
+ foreach($fields as $key=>$field) {
606
+ foreach($scores as $score) {
607
+ if($score['field'] == $key) {
608
+ $summary['issues'][$i]['desc'] = $score['description'];
609
+ $summary['issues'][$i++]['risk'] = $score['risk'];
610
+ }
611
+ }
612
+ }
613
+
614
+ $j = 0;
615
+ foreach($summary['issues'] as $summ) {
616
+ $risks[$j++] = $summ['risk'];
617
+ }
618
+
619
+ if(in_array('HIGH', $risks)) {
620
+ $summary['risk'] = 'HIGH';
621
+ } else if(in_array('MEDIUM', $risks)){
622
+ $summary['risk'] = 'MEDIUM';
623
+ } else {
624
+ $summary['risk'] = 'LOW';
625
+ }
626
+
627
+
628
+ return $summary;
629
+ }
630
+
631
+ public function checkOrderAmount($amount, $scores) {
632
+ $max_amount = Mage::getStoreConfig('dfraudintegration_options/dfraud_module_settings/maximum_order_amount');
633
+ $result['amount'] = $amount;
634
+ $result['max_amount'] = $max_amount;
635
+ $result['score']['total'] = 0;
636
+ if($amount > $max_amount) {
637
+ $result['amount_higher'] = "YES";
638
+ $result['score']['total'] = $this->getScore($scores, 'order_amount_avg');
639
+ $summary['order_amount_avg'] = 1;
640
+ } else {
641
+ $result['amount_higher'] = "NO";
642
+ }
643
+ $result['score']['max'] = $this->getModuleTotalScore($scores,array('order_amount_avg'));
644
+ $result['summary'] = $summary;
645
+
646
+ //$this->p($result);exit;
647
+ return $result;
648
+ }
649
+ }
app/code/local/Df/DFraudIntegration/Model/Dfraud.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * DFraud Integration plugin.
5
+ *
6
+ * @category Df
7
+ * @package Df_DFraudIntegration
8
+ * @author Biju Thajudien <mailtobiju@gmail.com>
9
+ * @version 0.1.0
10
+ */
11
+ class Df_DFraudIntegration_Model_Dfraud extends Mage_Core_Model_Abstract
12
+ {
13
+ protected function _construct()
14
+ {
15
+ $this->_init('dfraudintegration/dfraud');
16
+ }
17
+ }
app/code/local/Df/DFraudIntegration/Model/HighriskCountries.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * DFraud Integration plugin.
5
+ *
6
+ * @category Df
7
+ * @package Df_DFraudIntegration
8
+ * @author Biju Thajudien <mailtobiju@gmail.com>
9
+ * @version 0.1.0
10
+ */
11
+ class Df_DFraudIntegration_Model_HighriskCountries extends Mage_Core_Model_Abstract
12
+ {
13
+ protected function _construct()
14
+ {
15
+ $this->_init('dfraudintegration/highriskcountries');
16
+ }
17
+ }
app/code/local/Df/DFraudIntegration/Model/Observer.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Delivery Note Observer Model
5
+ *
6
+ * @category Dh
7
+ * @package Dh_Deliverynote
8
+ * @author Drew Hunter <drewdhunter@gmail.com>
9
+ * @version 0.1.0
10
+ */
11
+ class Df_DFraudIntegration_Model_Observer extends Mage_Core_Helper_Abstract
12
+ {
13
+ /**
14
+ * Take the note from post and and store it in the current quote.
15
+ *
16
+ * When the quote gets converted we will store the delivery note
17
+ * and assign to the order
18
+ *
19
+ * @param Varien_Object $observer
20
+ * @return Dh_Deliverynote_Model_Observer
21
+ */
22
+ public function checkoutEventCreateDeliveryNote($observer)
23
+ {
24
+ $note = $observer->getEvent()->getRequest()->getParam('deliverynote-note');
25
+
26
+ if (! empty($note)) {
27
+ $observer->getEvent()->getQuote()->setDeliveryNote((string)$note)->save();
28
+ }
29
+ return $this;
30
+ }
31
+
32
+ /**
33
+ * If the quote has a delivery note then lets save that note and
34
+ * assign the id to the order
35
+ *
36
+ * @param Varien_Object $observer
37
+ * @return Dh_Deliverynote_Model_Observer
38
+ */
39
+ public function salesEventConvertQuoteToOrder($observer)
40
+ {
41
+ if ($note = $observer->getEvent()->getQuote()->getDeliveryNote()) {
42
+ $deliveryNote = Mage::getModel('dfraud/note')->setNote($note)->save();
43
+
44
+ $observer->getEvent()->getOrder()
45
+ ->setDeliveryNoteId($deliveryNote->getDeliveryNoteId());
46
+ }
47
+ return $this;
48
+ }
49
+ }
app/code/local/Df/DFraudIntegration/Model/Resource/Dfraud.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * DFraud Integration plugin.
5
+ *
6
+ * @category Df
7
+ * @package Df_DFraudIntegration
8
+ * @author Biju Thajudien <mailtobiju@gmail.com>
9
+ * @version 0.1.0
10
+ */
11
+ class Df_DFraudIntegration_Model_Resource_Dfraud extends Mage_Core_Model_Mysql4_Abstract
12
+ {
13
+ protected function _construct()
14
+ {
15
+
16
+ $this->_init('dfraudintegration/dfraud', 'dfraud_id');
17
+ }
18
+ }
app/code/local/Df/DFraudIntegration/Model/Resource/HighriskCountries.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * DFraud Integration plugin.
5
+ *
6
+ * @category Df
7
+ * @package Df_DFraudIntegration
8
+ * @author Biju Thajudien <mailtobiju@gmail.com>
9
+ * @version 0.1.0
10
+ */
11
+ class Df_DFraudIntegration_Model_Resource_HighriskCountries extends Mage_Core_Model_Mysql4_Abstract
12
+ {
13
+ protected function _construct()
14
+ {
15
+
16
+ $this->_init('dfraudintegration/highriskcountries', 'id');
17
+ }
18
+ }
app/code/local/Df/DFraudIntegration/Model/Resource/Scores.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * DFraud Integration plugin.
5
+ *
6
+ * @category Df
7
+ * @package Df_DFraudIntegration
8
+ * @author Biju Thajudien <mailtobiju@gmail.com>
9
+ * @version 0.1.0
10
+ */
11
+ class Df_DFraudIntegration_Model_Resource_Scores extends Mage_Core_Model_Mysql4_Abstract
12
+ {
13
+ protected function _construct()
14
+ {
15
+
16
+ $this->_init('dfraudintegration/scores', 'id');
17
+ }
18
+ }
app/code/local/Df/DFraudIntegration/Model/Resource/Setup.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * DFraud Integration plugin.
4
+ *
5
+ * @category Df
6
+ * @package Df_DFraudIntegration
7
+ * @author Biju Thajudien <mailtobiju@gmail.com>
8
+ * @version 0.1.0
9
+ */
10
+ class Df_DFraudIntegration_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup {
11
+ }
12
+ ?>
app/code/local/Df/DFraudIntegration/Model/Scores.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * DFraud Integration plugin.
5
+ *
6
+ * @category Df
7
+ * @package Df_DFraudIntegration
8
+ * @author Biju Thajudien <mailtobiju@gmail.com>
9
+ * @version 0.1.0
10
+ */
11
+ class Df_DFraudIntegration_Model_Scores extends Mage_Core_Model_Abstract
12
+ {
13
+ protected function _construct()
14
+ {
15
+ $this->_init('dfraudintegration/scores');
16
+ }
17
+ }
app/code/local/Df/DFraudIntegration/controllers/Adminhtml/DfraudController.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * DFraud Integration plugin.
4
+ *
5
+ * @category Df
6
+ * @package Df_DFraudIntegration
7
+ * @author Biju Thajudien <mailtobiju@gmail.com>
8
+ * @version 0.1.0
9
+ */
10
+ class Df_DFraudIntegration_Adminhtml_DfraudController extends Mage_Adminhtml_Controller_Action
11
+ {
12
+ /**
13
+ * Initialize order model instance
14
+ *
15
+ * @return Mage_Sales_Model_Order || false
16
+ */
17
+ protected function _initOrder()
18
+ {
19
+ $id = $this->getRequest()->getParam('order_id');
20
+ $order = Mage::getModel('sales/order')->load($id);
21
+
22
+ if (!$order->getId()) {
23
+ $this->_getSession()->addError($this->__('This order no longer exists.'));
24
+ $this->_redirect('*/*/');
25
+ $this->setFlag('', self::FLAG_NO_DISPATCH, true);
26
+ return false;
27
+ }
28
+ Mage::register('sales_order', $order);
29
+ Mage::register('current_order', $order);
30
+
31
+ echo "<pre>";print_r($shippingDetails);
32
+
33
+ return $order;
34
+ }
35
+
36
+ /**
37
+ * Index action
38
+ */
39
+ public function indexAction()
40
+ {
41
+ if ($order = $this->_initOrder()) {
42
+ //echo "<pre>";print_r($order->customer_email);
43
+ $remote_ip = "197.79.0.3";//$order->getRemoteIp();
44
+
45
+ $helper = Mage::helper('dfraudintegration');
46
+ try {
47
+ $response = false;
48
+ $ipLocation = $helper->getIpLocation($remote_ip);
49
+
50
+ $shippingId = $order->getShippingAddressId();
51
+ $billingId = $order->getBillingAddressId();
52
+
53
+ $addressMismatch = $helper->checkAddress($shippingId, $billingId, $ipLocation);
54
+ $email_result = $helper->checkEmailValid($order->customer_email);
55
+
56
+
57
+ }
58
+ catch (Mage_Core_Exception $e) {
59
+ $response = array(
60
+ 'error' => true,
61
+ 'message' => $e->getMessage(),
62
+ );
63
+ }
64
+ catch (Exception $e) {
65
+ $response = array(
66
+ 'error' => true,
67
+ 'message' => $this->__('Cannot get dfraud data.')
68
+ );
69
+ }
70
+ }
71
+
72
+ }
73
+
74
+
75
+ }
76
+ ?>
app/code/local/Df/DFraudIntegration/etc/config.xml ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+
3
+ <config>
4
+ <modules>
5
+ <Df_DFraudIntegration>
6
+ <version>1.0.0</version>
7
+ </Df_DFraudIntegration>
8
+ </modules>
9
+ <global>
10
+ <models>
11
+ <dfraudintegration>
12
+ <class>Df_DFraudIntegration_Model</class>
13
+ <resourceModel>dfraudintegration_resource</resourceModel>
14
+ </dfraudintegration>
15
+ <dfraudintegration_resource>
16
+ <class>Df_DFraudIntegration_Model_Resource</class>
17
+ <entities>
18
+ <dfraud>
19
+ <table>dfraud</table>
20
+ </dfraud>
21
+ <highriskcountries>
22
+ <table>dfraud_highrisk_countries</table>
23
+ </highriskcountries>
24
+ <scores>
25
+ <table>dfraud_score</table>
26
+ </scores>
27
+ </entities>
28
+ </dfraudintegration_resource>
29
+ </models>
30
+ <helpers>
31
+ <dfraudintegration>
32
+ <class>Df_DFraudIntegration_Helper</class>
33
+ </dfraudintegration>
34
+ </helpers>
35
+ <resources>
36
+ <dfraudintegration_setup>
37
+ <setup>
38
+ <module>Df_DFraudIntegration</module>
39
+ <class>Df_DFraudIntegration_Model_Resource_Setup</class>
40
+ </setup>
41
+ </dfraudintegration_setup>
42
+ </resources>
43
+ <blocks>
44
+ <dfraudintegration>
45
+ <class>Df_DFraudIntegration_Block</class>
46
+ </dfraudintegration>
47
+ </blocks>
48
+ <remote_addr_headers><!-- list headers that contain real client IP if webserver is behind a reverse proxy -->
49
+ <header1>HTTP_X_FORWARDED_FOR</header1>
50
+ <header2>HTTP_X_REAL_IP</header2>
51
+ <header3>REMOTE_ADDR</header3>
52
+ </remote_addr_headers>
53
+ <events>
54
+ <!--<checkout_type_onepage_save_order_after>-->
55
+ <sales_order_place_after>
56
+ <observers>
57
+ <send_request_to_subuno>
58
+ <type>singleton</type>
59
+ <class>Cartform_SubunoIntegration_Controller_Observer</class>
60
+ <method>sendRequestToSubuno</method>
61
+ </send_request_to_subuno>
62
+ </observers>
63
+ </sales_order_place_after>
64
+ <!--</checkout_type_onepage_save_order_after> -->
65
+ </events>
66
+ </global>
67
+ <admin>
68
+ <routers>
69
+ <adminhtml>
70
+ <args>
71
+ <modules>
72
+ <Df_DFraudIntegration before="Mage_Adminhtml">Df_DFraudIntegration_Adminhtml</Df_DFraudIntegration>
73
+ </modules>
74
+ </args>
75
+ </adminhtml>
76
+ </routers>
77
+ </admin>
78
+ <adminhtml>
79
+ <layout>
80
+ <updates>
81
+ <adminhtml_dfraudintegration>
82
+ <file>dfraudintegration.xml</file>
83
+ </adminhtml_dfraudintegration>
84
+ </updates>
85
+
86
+ </layout>
87
+ <acl>
88
+ <resources>
89
+ <admin>
90
+ <children>
91
+ <system>
92
+ <children>
93
+ <config>
94
+ <children>
95
+ <dfraudintegration_options>
96
+ <title>DFraud Interation</title>
97
+ </dfraudintegration_options>
98
+ </children>
99
+ </config>
100
+ </children>
101
+ </system>
102
+ </children>
103
+ </admin>
104
+ </resources>
105
+ </acl>
106
+ <translate>
107
+ <modules>
108
+ <Df_DFraudIntegration>
109
+ <files>
110
+ <default>Dh_DFraudIntegration.csv</default>
111
+ </files>
112
+ </Df_DFraudIntegration>
113
+ </modules>
114
+ </translate>
115
+ </adminhtml>
116
+ <default>
117
+ <dfraudintegration_options>
118
+ <basic_settings>
119
+ <licence_key>123456</licence_key>
120
+ </basic_settings>
121
+ <dfraud_module_settings>
122
+ <maximum_order_amount>100</maximum_order_amount>
123
+ <maximum_distance>200</maximum_distance>
124
+ </dfraud_module_settings>
125
+ </dfraudintegration_options>
126
+ </default>
127
+
128
+ </config>
app/code/local/Df/DFraudIntegration/etc/system.xml ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <tabs>
3
+ <dfraudintegration translate="label" module="dfraudintegration">
4
+ <label>DFraud Integration</label>
5
+ <sort_order>999999</sort_order>
6
+ </dfraudintegration>
7
+ </tabs>
8
+ <sections>
9
+ <dfraudintegration_options translate="label" module="dfraudintegration">
10
+ <label>DFraud Integration Options</label>
11
+ <tab>dfraudintegration</tab>
12
+ <frontend_type>text</frontend_type>
13
+ <sort_order>10</sort_order>
14
+ <show_in_default>1</show_in_default>
15
+ <show_in_website>1</show_in_website>
16
+ <show_in_store>1</show_in_store>
17
+ <groups>
18
+ <basic_settings translate="label">
19
+ <label>Basic Settings</label>
20
+ <frontend_type>text</frontend_type>
21
+ <sort_order>1</sort_order>
22
+ <show_in_default>1</show_in_default>
23
+ <show_in_website>1</show_in_website>
24
+ <show_in_store>1</show_in_store>
25
+ <fields>
26
+ <licence_key translate="label">
27
+ <label>Licence Key</label>
28
+ <frontend_type>text</frontend_type>
29
+ <sort_order>30</sort_order>
30
+ <show_in_default>1</show_in_default>
31
+ <show_in_website>1</show_in_website>
32
+ <show_in_store>1</show_in_store>
33
+ <comment>The licence key for DFraud integration module.</comment>
34
+ </licence_key>
35
+ </fields>
36
+ </basic_settings>
37
+ <dfraud_module_settings>
38
+ <label>Settings</label>
39
+ <frontend_type>text</frontend_type>
40
+ <sort_order>20</sort_order>
41
+ <show_in_default>1</show_in_default>
42
+ <show_in_website>1</show_in_website>
43
+ <show_in_store>1</show_in_store>
44
+ <comment>Use this section to set the fraud check values.</comment>
45
+ <fields>
46
+ <maximum_distance translate="label">
47
+ <label>Maximum distance between billing and IP address</label>
48
+ <frontend_type>text</frontend_type>
49
+ <sort_order>20</sort_order>
50
+ <show_in_default>1</show_in_default>
51
+ <show_in_website>1</show_in_website>
52
+ <show_in_store>1</show_in_store>
53
+ <validate>validate-number</validate>
54
+ </maximum_distance>
55
+ <maximum_order_amount translate="label">
56
+ <label>Maximum order amount for the store</label>
57
+ <frontend_type>text</frontend_type>
58
+ <sort_order>20</sort_order>
59
+ <show_in_default>1</show_in_default>
60
+ <show_in_website>1</show_in_website>
61
+ <show_in_store>1</show_in_store>
62
+ <validate>validate-number</validate>
63
+ <comment>Set this value to an average value of an order in your store. DFraud module will get this value to validate the order amount.</comment>
64
+ </maximum_order_amount>
65
+ </fields>
66
+ </dfraud_module_settings>
67
+ </groups>
68
+ </dfraudintegration_options>
69
+ </sections>
70
+ </config>
app/code/local/Df/DFraudIntegration/sql/dfraudintegration_setup/mysql4-install-1.0.0.php ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * DFraud Integration plugin.
4
+ *
5
+ * @category Df
6
+ * @package Df_DFraudIntegration
7
+ * @author Biju Thajudien <mailtobiju@gmail.com>
8
+ * @version 0.1.0
9
+ */
10
+
11
+ /**
12
+ * @var $installer Mage_Core_Model_Resource_Setup
13
+ */
14
+ $installer = $this;
15
+
16
+ /**
17
+ * Creating table magentostudy_news
18
+ */
19
+ $table = $installer->getConnection()
20
+ ->newTable($installer->getTable('dfraudintegration/highriskcountries'))
21
+ ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
22
+ 'unsigned' => true,
23
+ 'identity' => true,
24
+ 'nullable' => false,
25
+ 'primary' => true,
26
+ ), 'Entity id')
27
+ ->addColumn('country_id', Varien_Db_Ddl_Table::TYPE_TEXT, 2, array(
28
+ 'nullable' => true,
29
+ ), 'Title')
30
+ ->addColumn('country', Varien_Db_Ddl_Table::TYPE_TEXT, 63, array(
31
+ 'nullable' => true,
32
+ 'default' => null,
33
+ ), 'Author')
34
+ ->addColumn('region', Varien_Db_Ddl_Table::TYPE_TEXT, 63, array(
35
+ 'nullable' => true,
36
+ 'default' => null,
37
+ ), 'Author')
38
+ ->addIndex($installer->getIdxName(
39
+ $installer->getTable('dfraudintegration/highriskcountries'),
40
+ array('id'),
41
+ Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX
42
+ ),
43
+ array('id'),
44
+ array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX)
45
+ )
46
+
47
+ ->setComment('Dfraud High Risk Countries');
48
+
49
+ $installer->getConnection()->createTable($table);
50
+
51
+ //Ukraine, Indonesia, Yugoslavia, Lithuania, Egypt, Romania, Bulgaria, Turkey, Russia, Pakistan, Malaysia, and Israel
52
+
53
+ $table = $installer->getConnection()
54
+ ->newTable($installer->getTable('dfraudintegration/scores'))
55
+ ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
56
+ 'unsigned' => true,
57
+ 'identity' => true,
58
+ 'nullable' => false,
59
+ 'primary' => true,
60
+ ), 'Entity id')
61
+ ->addColumn('field', Varien_Db_Ddl_Table::TYPE_TEXT, 200, array(
62
+ 'nullable' => true,
63
+ ), 'Field')
64
+ ->addColumn('score', Varien_Db_Ddl_Table::TYPE_TEXT, 63, array(
65
+ 'nullable' => true,
66
+ 'default' => null,
67
+ ), 'Score')
68
+ ->addColumn('description', Varien_Db_Ddl_Table::TYPE_TEXT, 200, array(
69
+ 'nullable' => true,
70
+ 'default' => null,
71
+ ), 'Description')
72
+ ->addColumn('risk', Varien_Db_Ddl_Table::TYPE_TEXT, 10, array(
73
+ 'nullable' => true,
74
+ 'default' => null,
75
+ ), 'Risk')
76
+ ->addIndex($installer->getIdxName(
77
+ $installer->getTable('dfraudintegration/scores'),
78
+ array('id'),
79
+ Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX
80
+ ),
81
+ array('id'),
82
+ array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX)
83
+ )
84
+
85
+ ->setComment('Dfraud Scores');
86
+
87
+ $installer->getConnection()->createTable($table);
88
+
89
+ $installer->startSetup();
90
+
91
+ $installer->run("
92
+ insert into {$this->getTable('dfraud_score')}
93
+ (`field`,`score`, `description`,`risk`)
94
+ values
95
+ ('address_bill_ship', '0.5', 'Billing and shipping address doesn''t match.', 'HIGH'),
96
+ ('zip_bill', '0.75', 'Billing address post code not found.', 'MEDIUM'),
97
+ ('dis_bill_ip', '0.75', 'Distance between billing and IP location exceeds maximum.', 'MEDIUM'),
98
+ ('ip_bill_city', '0.5', 'IP and Billing address differs (City).', 'MEDIUM'),
99
+ ('ip_bill_region', '0.75', 'IP and Billing address differs (Region).', 'MEDIUM'),
100
+ ('ip_bill_country_id', '1.00', 'IP and Billing address differs (Country)', 'MEDIUM'),
101
+ ('hr_bill', '1.25', 'Billing address in high risk country', 'HIGH'),
102
+ ('hr_ship', '1.00', 'Shipping address in high risk country', 'HIGH'),
103
+ ('hr_ip', '1.00', 'IP address in high risk country', 'HIGH'),
104
+ ('order_hist_fraud', '1.25', 'Previous Fraud orders from user exists.', 'HIGH'),
105
+ ('order_hist_count_ip_user', '0.50', 'Order count of User and IP doesn''t match', 'LOW'),
106
+ ('order_amount_avg', '0.75', 'Order amount is greater than average order amount', 'HIGH'),
107
+ ('bin_country', '1.50', 'CC issuing country and Billing address country doesn''t match', 'HIGH'),
108
+ ('order_hist_first_order', '0.25', 'First order from user', 'LOW'),
109
+ ('zip_ship', '0.5', 'Shipping address post code not found', 'MEDIUM');
110
+ ");
111
+
112
+ $installer->run("
113
+ insert into {$this->getTable('dfraud_highrisk_countries')}
114
+ (`country_id`,`country`,`region`)
115
+ values ('UA', 'Ukraine', ''),
116
+ ('ID','Indonesia',''),('YG','Yugoslavia',''),('YG','Yugoslavia',''),
117
+ ('LT','Lithuania',''),('EG','Egypt',''),('RO','Romania','')
118
+ ,('BG','Bulgaria',''),('TR','Turkey',''),('RU','Russia',''),('PK','Pakistan',''),
119
+ ('MY','Malaysia',''),('IL','Israel','');
120
+ ");
121
+ $installer->endSetup();
122
+ ?>
app/design/adminhtml/default/default/layout/dfraudintegration.xml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <layout>
4
+ <!-- Orders -->
5
+ <!--<adminhtml_sales_order_view>
6
+ <reference name="order_tab_info">
7
+ <action method="setTemplate" ifconfig="dfraudintegration_options/basic_settings/plug_and_play">
8
+ <template>dfraudintegration/sales/order/view/tab/info.phtml</template>
9
+ </action>
10
+ <block type="dfraudintegration/adminhtml_sales_order_dfraud" name="dfraudintegration" template="dfraudintegration/dfraud.phtml" />
11
+ </reference>
12
+ </adminhtml_sales_order_view>-->
13
+ <adminhtml_sales_order_view>
14
+ <reference name="sales_order_tabs">
15
+ <action method="addTab">
16
+ <name>DFraud Data</name>
17
+ <block>dfraudintegration/adminhtml_order_view_tab_dfraud</block>
18
+ </action>
19
+ </reference>
20
+ </adminhtml_sales_order_view>
21
+ </layout>
app/design/adminhtml/default/default/template/dfraudintegration/dfraud.phtml ADDED
@@ -0,0 +1,560 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $result = Mage::registry('data'); ?>
2
+ <div class="box-left">
3
+ <!--Address Checking-->
4
+ <div class="entry-edit">
5
+ <div class="entry-edit-head">
6
+ <h4 class="icon-head head-account">Order Address Checks</h4>
7
+ </div>
8
+ <div class="fieldset">
9
+ <table cellspacing="0" class="form-list">
10
+ <tbody><tr>
11
+ <td class="label"><label>Billing and Shipping address match</label></td>
12
+ <td class="value">
13
+ <?php
14
+ if(count($result['address']) > 1) {?>
15
+ <strong>NO</strong>
16
+ <? } else { ?>
17
+ <strong>YES</strong>
18
+ <? } ?>
19
+ </td>
20
+ </tr>
21
+ <?php
22
+ if(isset($result['address'])) {?>
23
+ <tr>
24
+ <td class="label"><label>Mismatches</label></td>
25
+ <td width="500">
26
+ <table>
27
+ <tr>
28
+ <td></td>
29
+ <td><strong>Billing</strong></td>
30
+ <td><strong>Shipping</strong></td>
31
+ </tr>
32
+ <? if(isset($result['address']['street']['billing'])) {?>
33
+ <tr>
34
+ <td width="60"><strong>Street</strong></td>
35
+ <td width="120"><? echo $result['address']['street']['billing'] ?></td>
36
+ <td width="120"><? echo $result['address']['street']['shipping'] ?></td>
37
+ </tr>
38
+ <? } ?>
39
+
40
+ <? if(isset($result['address']['city']['billing'])) {?>
41
+ <tr>
42
+ <td width="60"><strong>City</strong></td>
43
+ <td width="120"><? echo $result['address']['city']['billing'] ?></td>
44
+ <td width="120"><? echo $result['address']['city']['shipping'] ?></td>
45
+ </tr>
46
+ <? } ?>
47
+
48
+ <? if(isset($result['address']['region']['billing'])) {?>
49
+ <tr>
50
+ <td width="60"><strong>Region</strong></td>
51
+ <td width="120"><? echo $result['address']['region']['billing'] ?></td>
52
+ <td width="120"><? echo $result['address']['region']['shipping'] ?></td>
53
+ </tr>
54
+ <? } ?>
55
+
56
+ <? if(isset($result['address']['country_id']['billing'])) {?>
57
+ <tr>
58
+ <td width="60"><strong>Country</strong></td>
59
+ <td width="120"><? echo $result['address']['country_id']['billing'] ?></td>
60
+ <td width="120"><? echo $result['address']['country_id']['shipping'] ?></td>
61
+ </tr>
62
+ <? } ?>
63
+
64
+ <? if(isset($result['address']['postcode']['billing'])) {?>
65
+ <tr>
66
+ <td width="60"><strong>PostCode</strong></td>
67
+ <td width="120"><? echo $result['address']['postcode']['billing'] ?></td>
68
+ <td width="120"><? echo $result['address']['postcode']['shipping'] ?></td>
69
+ </tr>
70
+ <? } ?>
71
+ </table>
72
+ </td>
73
+ </tr>
74
+ <? } ?>
75
+ <tr>
76
+ <td class="label"><label>Score</label></td>
77
+ <td class="value">
78
+ <strong>
79
+ <?php echo $result['address']['score']['total']." / ".$result['address']['score']['max']; ?>
80
+ </strong>
81
+ </td>
82
+ </tr>
83
+ </tbody></table>
84
+ </div>
85
+ </div>
86
+ </div>
87
+
88
+ <div class="box-right">
89
+ <!--Order Information-->
90
+ <div class="entry-edit">
91
+ <div class="entry-edit-head">
92
+ <h4 class="icon-head head-account">Post code Checks</h4>
93
+ </div>
94
+ <div class="fieldset">
95
+ <table cellspacing="0" class="form-list">
96
+ <tbody>
97
+ <tr>
98
+ <td class="label"><label>Billing Post Code Location</label></td>
99
+ <td class="value">
100
+ <?php echo $result['post_loc']['billing']; ?>
101
+ </td>
102
+ </tr>
103
+ <tr>
104
+ <td class="label"><label>Shipping Post Code Location</label></td>
105
+ <td class="value">
106
+ <?php echo $result['post_loc']['shipping']; ?>
107
+ </td>
108
+ </tr>
109
+ <tr>
110
+ <td class="label"><label>Score</label></td>
111
+ <td class="value">
112
+ <strong>
113
+ <?php echo $result['post_loc']['score']['total']." / ".$result['post_loc']['score']['max']; ?>
114
+ </strong>
115
+ </td>
116
+ </tr>
117
+ </tbody>
118
+ </table>
119
+ </div>
120
+ </div>
121
+ </div>
122
+
123
+
124
+
125
+
126
+ <div class="box-right">
127
+ <!--Account Information-->
128
+ <div class="entry-edit">
129
+ <div class="entry-edit-head">
130
+ <h4 class="icon-head head-account">IP Location Checks</h4>
131
+ <div class="tools"></div>
132
+ </div>
133
+ <div class="fieldset">
134
+ <div class="hor-scroll">
135
+ <table cellspacing="0" class="form-list">
136
+ <tbody>
137
+ <tr>
138
+ <td class="label"><label>IP Address</label></td>
139
+ <td class="value"><? echo $result['ip']['location']['ip'] ?></td>
140
+ </tr>
141
+ <tr>
142
+ <td class="label"><label>IP Latitude</label></td>
143
+ <td class="value"><? echo $result['ip']['location']['latitude'] ?></td>
144
+ </tr>
145
+ <tr>
146
+ <td class="label"><label>IP Longitude</label></td>
147
+ <td class="value"><? echo $result['ip']['location']['longitude'] ?></td>
148
+ </tr>
149
+ <tr>
150
+ <td class="label"><label>IP Location</label></td>
151
+ <td class="value"><? echo $result['ip']['location']['loc_str'] ?></td>
152
+ </tr>
153
+ <tr>
154
+ <td class="label"><label>IP and Billing Address Match</label></td>
155
+ <td class="value">
156
+ <strong>
157
+ <? if(isset($result['ip']['ip_bill_diff']))
158
+ echo "NO";
159
+ else
160
+ echo "YES";
161
+ ?>
162
+ </strong>
163
+ </td>
164
+ </tr>
165
+ <?php
166
+ if(isset($result['ip'])) {?>
167
+ <tr>
168
+ <td class="label"><label>Details</label></td>
169
+ <td width="400">
170
+ <table>
171
+ <tr>
172
+ <td></td>
173
+ <td><strong>IP</strong></td>
174
+ <td><strong>Billing</strong></td>
175
+ <td><strong>Shipping</strong></td>
176
+ </tr>
177
+
178
+ <tr>
179
+ <td width="60"><strong>City</strong></td>
180
+ <td width="100"><? echo $result['ip']['city']['ip'] ?></td>
181
+ <td width="100"><? echo $result['ip']['city']['billing'] ?></td>
182
+ <td width="100"><? echo $result['ip']['city']['shipping'] ?></td>
183
+ </tr>
184
+ <tr>
185
+ <td><strong>Region</strong></td>
186
+ <td><? echo $result['ip']['region']['ip'] ?></td>
187
+ <td><? echo $result['ip']['region']['billing'] ?></td>
188
+ <td><? echo $result['ip']['region']['shipping'] ?></td>
189
+ </tr>
190
+ <tr>
191
+ <td><strong>Country</strong></td>
192
+ <td><? echo $result['ip']['country_id']['ip'] ?></td>
193
+ <td><? echo $result['ip']['country_id']['billing'] ?></td>
194
+ <td><? echo $result['ip']['country_id']['shipping'] ?></td>
195
+ </tr>
196
+
197
+ </table>
198
+ </td>
199
+ </tr>
200
+ <? } ?>
201
+ <tr>
202
+ <td class="label"><label>Score</label></td>
203
+ <td class="value">
204
+ <strong>
205
+ <?php echo $result['ip']['score']['total']." / ".$result['ip']['score']['max']; ?>
206
+ </strong>
207
+ </td>
208
+ </tr>
209
+ </tbody></table>
210
+ </div>
211
+ </div>
212
+ </div>
213
+ </div>
214
+
215
+ <div class="box-left">
216
+ <!--Order Information-->
217
+ <div class="entry-edit">
218
+ <div class="entry-edit-head">
219
+ <h4 class="icon-head head-account">Credit Card BIN Checks</h4>
220
+ </div>
221
+ <div class="fieldset">
222
+ <table cellspacing="0" class="form-list">
223
+ <tbody>
224
+ <? if( isset($result['bin']['err']) ) { ?>
225
+ <tr>
226
+ <td width="400">
227
+ <strong><i><? echo $result['bin']['err']; ?></i></strong>
228
+ </td>
229
+ </tr>
230
+ <? } else { ?>
231
+ <tr>
232
+ <td class="label"><label>CC Country</label></td>
233
+ <td class="value">
234
+ <strong><? echo $result['bin']['binCountry']; ?></strong>
235
+ </td>
236
+ </tr>
237
+ <tr>
238
+ <td class="label"><label>CC Bank</label></td>
239
+ <td class="value">
240
+ <strong><? echo $result['bin']['binName']; ?></strong>
241
+ </td>
242
+ </tr>
243
+ <tr>
244
+ <td class="label"><label>Bank Phone</label></td>
245
+ <td class="value">
246
+ <strong><? echo $result['bin']['binPhone']; ?></strong>
247
+ </td>
248
+ </tr>
249
+ <tr>
250
+ <td class="label"><label>Is Billing & CC Country Match?</label></td>
251
+ <td class="value">
252
+ <strong><? echo $result['bin']['country_match']; ?></strong>
253
+ </td>
254
+ </tr>
255
+ <tr>
256
+ <td class="label"><label>Score</label></td>
257
+ <td class="value">
258
+ <strong>
259
+ <?php echo $result['bin']['score']['total']." / ".$result['bin']['score']['max']; ?>
260
+ </strong>
261
+ </td>
262
+ </tr>
263
+ <? } ?>
264
+ </tbody>
265
+ </table>
266
+ </div>
267
+ </div>
268
+ </div>
269
+
270
+
271
+ <div class="box-left">
272
+ <!--Order Information-->
273
+ <div class="entry-edit">
274
+ <div class="entry-edit-head">
275
+ <h4 class="icon-head head-account">Order Amount Check</h4>
276
+ </div>
277
+ <div class="fieldset">
278
+ <table cellspacing="0" class="form-list">
279
+ <tbody>
280
+ <tr>
281
+ <td class="label"><label>Is Order amount greater that maximum?</label></td>
282
+ <td class="value">
283
+ <strong>
284
+ <? echo $result['ammount_check']['amount_higher']; ?>
285
+ </strong>
286
+ </td>
287
+ </tr>
288
+ <tr>
289
+ <td class="label"><label>Order Amount</label></td>
290
+ <td class="value">
291
+ <strong><? echo $result['ammount_check']['amount']; ?></strong>
292
+ </td>
293
+ </tr>
294
+ <tr>
295
+ <td class="label"><label>Max Amount</label></td>
296
+ <td class="value">
297
+ <strong><? echo $result['ammount_check']['max_amount']; ?></strong>
298
+ </td>
299
+ </tr>
300
+ <tr>
301
+ <td class="label"><label>Score</label></td>
302
+ <td class="value">
303
+ <strong>
304
+ <?php echo $result['ammount_check']['score']['total']." / ".$result['ammount_check']['score']['max']; ?>
305
+ </strong>
306
+ </td>
307
+ </tr>
308
+ </tbody>
309
+ </table>
310
+ </div>
311
+ </div>
312
+ </div>
313
+
314
+
315
+ <div class="box-right">
316
+ <!--Order Information-->
317
+ <div class="entry-edit">
318
+ <div class="entry-edit-head">
319
+ <h4 class="icon-head head-account">High Risk Country Checks</h4>
320
+ </div>
321
+ <div class="fieldset">
322
+ <table cellspacing="0" class="form-list">
323
+ <tbody>
324
+ <tr>
325
+ <td class="label"><label>Is Billing Country High Risk?</label></td>
326
+ <td class="value">
327
+ <strong>
328
+ <? if(isset($result['hrc']['billing']))
329
+ echo "YES";
330
+ else
331
+ echo "NO";
332
+ ?>
333
+ </strong>
334
+ </td>
335
+ </tr>
336
+ <tr>
337
+ <td class="label"><label>Is Shipping Country High Risk?</label></td>
338
+ <td class="value">
339
+ <strong>
340
+ <? if(isset($result['hrc']['shipping']))
341
+ echo "YES";
342
+ else
343
+ echo "NO";
344
+ ?>
345
+ </strong>
346
+ </td>
347
+ </tr>
348
+ <tr>
349
+ <td class="label"><label>Is IP Country High Risk?</label></td>
350
+ <td class="value">
351
+ <strong>
352
+ <? if(isset($result['hrc']['ip']))
353
+ echo "YES";
354
+ else
355
+ echo "NO";
356
+ ?>
357
+ </strong>
358
+ </td>
359
+ </tr>
360
+ <tr>
361
+ <td class="label"><label>Score</label></td>
362
+ <td class="value">
363
+ <strong>
364
+ <?php echo $result['hrc']['score']['total']." / ".$result['hrc']['score']['max']; ?>
365
+ </strong>
366
+ </td>
367
+ </tr>
368
+ </tbody>
369
+ </table>
370
+ </div>
371
+ </div>
372
+ </div>
373
+
374
+
375
+ <div class="box-left">
376
+ <!--Order Information-->
377
+ <div class="entry-edit">
378
+ <div class="entry-edit-head">
379
+ <h4 class="icon-head head-account">Order History</h4>
380
+ </div>
381
+ <div class="fieldset">
382
+ <table cellspacing="0" class="form-list">
383
+ <tbody>
384
+ <tr>
385
+ <td class="label"><label>Total Orders from User</label></td>
386
+ <td class="value">
387
+ <strong><? echo $result['order_history_cust']['user']['count']; ?></strong>
388
+ </td>
389
+ </tr>
390
+ <tr>
391
+ <td class="label"><label>Order Status : </label></td>
392
+ <td class="value">
393
+ <strong>
394
+ <table>
395
+ <?
396
+ foreach($result['order_history_cust']['user']['status'] as $key=>$status) {
397
+ if($status > 0 ) {
398
+ ?>
399
+ <tr>
400
+ <td width="150"><? echo $key; ?></td>
401
+ <td><? echo $status; ?></td>
402
+ </tr>
403
+ <? } } ?>
404
+ </table>
405
+ </strong>
406
+ </td>
407
+ </tr>
408
+ <tr>
409
+ <td class="label"><label>Total Orders from IP</label></td>
410
+ <td class="value">
411
+ <strong><? echo $result['order_history_cust']['ip']['count']; ?></strong>
412
+ </td>
413
+ </tr>
414
+ <tr>
415
+ <td class="label"><label>Order Status : </label></td>
416
+ <td class="value">
417
+ <strong>
418
+ <table>
419
+ <?
420
+ foreach($result['order_history_cust']['ip']['status'] as $key=>$status) {
421
+ if($status > 0 ) {
422
+ ?>
423
+ <tr>
424
+ <td width="150"><? echo $key; ?></td>
425
+ <td><? echo $status; ?></td>
426
+ </tr>
427
+ <? } } ?>
428
+ </table>
429
+ </strong>
430
+ </td>
431
+ </tr>
432
+ <tr>
433
+ <td class="label"><label>Score</label></td>
434
+ <td class="value">
435
+ <strong>
436
+ <?php echo $result['order_history_cust']['score']['total']." / ".$result['order_history_cust']['score']['max']; ?>
437
+ </strong>
438
+ </td>
439
+ </tr>
440
+ </tbody>
441
+ </table>
442
+ </div>
443
+ </div>
444
+ </div>
445
+
446
+
447
+ <div class="box-right">
448
+ <!--Order Information-->
449
+ <div class="entry-edit">
450
+ <div class="entry-edit-head">
451
+ <h4 class="icon-head head-account">Geo Location Checks</h4>
452
+ </div>
453
+ <div class="fieldset">
454
+ <table cellspacing="0" class="form-list">
455
+ <tbody>
456
+ <tr>
457
+ <td class="label"><label>Distance between Billing/Shipping Location</label></td>
458
+ <td class="value"><? echo $result['dis']['bill_ship'] ?> KM</td>
459
+ </tr>
460
+ <tr>
461
+ <td class="label"><label>Distance between Billing/IP Location</label></td>
462
+ <td class="value"><? echo $result['dis']['ip_bill'] ?> KM</td>
463
+ </tr>
464
+ <tr>
465
+ <td class="label"><label>Distance between Shipping/IP Location</label></td>
466
+ <td class="value"><? echo $result['dis']['ip_ship'] ?> KM</td>
467
+ </tr>
468
+
469
+ <tr>
470
+ <td class="label"><label>Billing Address - Nearest Verified Location</label></td>
471
+ <td class="value"><? echo $result['billingGeoResult']['formatted_address'] ?></td>
472
+ </tr>
473
+ <tr>
474
+ <td class="label"><label>Check Type</label></td>
475
+ <td class="value"><? echo $result['billingGeoResult']['type'] ?></td>
476
+ </tr>
477
+ <tr>
478
+ <td class="label"><label>Shipping address - Nearest Verified Location</label></td>
479
+ <td class="value"><? echo $result['shippingGeoResult']['formatted_address'] ?></td>
480
+ </tr>
481
+ <tr>
482
+ <td class="label"><label>Check Type</label></td>
483
+ <td class="value"><? echo $result['shippingGeoResult']['type'] ?></td>
484
+ </tr>
485
+ <tr>
486
+ <td class="label"><label>Score</label></td>
487
+ <td class="value">
488
+ <strong>
489
+ <?php echo $result['dis']['score']['total']." / ".$result['dis']['score']['max']; ?>
490
+ </strong>
491
+ </td>
492
+ </tr>
493
+ </tbody>
494
+ </table>
495
+ </div>
496
+ </div>
497
+ </div>
498
+
499
+
500
+
501
+
502
+
503
+
504
+ <div class="box-left">
505
+ <!--Order Information-->
506
+ <div class="entry-edit">
507
+ <div class="entry-edit-head">
508
+ <h4 class="icon-head head-account">Risk Score Summary</h4>
509
+ </div>
510
+ <div class="fieldset">
511
+ <table cellspacing="0" class="form-list">
512
+ <tbody>
513
+ <tr>
514
+ <td class="label" width="200"><strong>Issues</strong></td>
515
+ <td class="label" width="200"><strong>Risk</strong></td>
516
+ </tr>
517
+ <?php
518
+ foreach($result['summary']['issues'] as $summary) { ?>
519
+ <tr>
520
+ <td class="value" width="200">
521
+ <? echo $summary['desc']; ?>
522
+ </td>
523
+ <td class="value">
524
+ <strong><? echo $summary['risk']; ?></strong><br/>
525
+ </td>
526
+ </tr>
527
+ <? } ?>
528
+ <tr>
529
+ <td class="label" colspan="2"></td>
530
+ </tr>
531
+ <tr>
532
+ <td class="label"><label>Total score</label></td>
533
+ <td class="value">
534
+ <strong>
535
+ <?php echo $result['score']['total']." / ".$result['score']['max']; ?>
536
+ </strong>
537
+ </td>
538
+ </tr>
539
+ <tr>
540
+ <td class="label"><label>Risk Assesment</label></td>
541
+ <td class="value">
542
+ <strong>
543
+ <?php echo $result['summary']['risk']; ?>
544
+ </strong>
545
+ </td>
546
+ </tr>
547
+
548
+ </tbody>
549
+ </table>
550
+ </div>
551
+ </div>
552
+ </div>
553
+
554
+
555
+ <!--<div class="entry-edit-head" id='dfraudintegration'>
556
+ <h4 class="icon-head head-deliverynote"><?php echo $this->__(Mage::helper('dfraudintegration')->getFrontendLabel()) ?></h4>
557
+ </div>-->
558
+
559
+
560
+ <?php //$data = Mage::registry('data'); echo "<pre>";print_r($data);?>
app/design/adminhtml/default/default/template/dfraudintegration/note-create.phtml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <div class="box-right entry-edit">
2
+ <div class="entry-edit-head"><h4><?php echo $this->__($this->getFrontendLabel()) ?></h4></div>
3
+ <fieldset id="order-deliverynote">
4
+ <label for="deliverynote-note"><?php echo $this->__($this->getFrontendLabel()) ?></label><br>
5
+ <?php $characterCount = $this->getCharacterCount(); ?>
6
+ <textarea cols="15" rows="2" id='deliverynote-note' name='deliverynote' style="width:98%; height:8em;" <?php if ($characterCount !== false): ?>class="validate-length maximum-length-<?php echo $characterCount ?>"<?php endif; ?>></textarea>
7
+ </fieldset>
8
+ </div>
app/etc/modules/Df_DFraudIntegration.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Df_DFraudIntegration>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Df_DFraudIntegration>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Df_DFraudIntegration</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>The DFraud Integration extension helps magento site admins to identify fruad orders.</summary>
10
+ <description>The Dfraud integration performs 15 checks to identify the fruaud order so that its easy for site admins to identify fraud orders.</description>
11
+ <notes>The Dfraud integration performs 15 checks to identify the fruaud order so that its easy for site admins to identify fraud orders.</notes>
12
+ <authors><author><name>Biju Thajudien</name><user>bijuthaj</user><email>mailtobiju@gmail.com</email></author></authors>
13
+ <date>2013-06-06</date>
14
+ <time>17:53:33</time>
15
+ <contents><target name="magelocal"><dir name="Df"><dir name="DFraudIntegration"><dir name="Block"><dir name="Adminhtml"><dir name="Order"><dir name="View"><dir name="Tab"><file name="Dfraud.php" hash="3ebba9d972f9ff19c3b0c9b464840ae9"/></dir></dir></dir><dir name="Sales"><dir name="Order"><file name="Dfraud.php" hash="ec55335f14b3adf56649d3e081f99f38"/></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="e278ed6b55796eef3000ef459680fb3e"/></dir><dir name="Model"><file name="Dfraud.php" hash="5f0040d5f36cefd3f8fe4934e2ce06a8"/><file name="HighriskCountries.php" hash="d2d957dd4af7c0a124027003e23c9d42"/><file name="Observer.php" hash="c8bfd8bea285fcf9b22416a24d61750f"/><dir name="Resource"><file name="Dfraud.php" hash="a1d158afb971c3bf72ea487e97300e2e"/><file name="HighriskCountries.php" hash="a662b20d8c82322181fd654b2f5b1c66"/><file name="Scores.php" hash="d930d4b38f744d4b80b4e61ac6d16912"/><file name="Setup.php" hash="852be8f15c3cc83671daddf449e78b47"/></dir><file name="Scores.php" hash="c104ec746c14a40488043bba4cbd86a5"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="DfraudController.php" hash="5230eae76462009471a73e340be043bd"/></dir></dir><dir name="etc"><file name="config.xml" hash="cd1d49b3796e466b571f16ab6a87878b"/><file name="system.xml" hash="56a1d181014706bc19def7d63a5cf399"/></dir><dir name="sql"><dir name="dfraudintegration_setup"><file name="mysql4-install-1.0.0.php" hash="82e29518d79f0b485c827b575763ff75"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="dfraudintegration.xml" hash="6154540dc6253d842f9ad74430993a11"/></dir><dir name="template"><dir name="dfraudintegration"><file name="dfraud.phtml" hash="4225212d04d90b4a84c44337cd9d8d3f"/><file name="note-create.phtml" hash="90bc4162eeb8834afc64a391316a01d0"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Df_DFraudIntegration.xml" hash="8445e26ba8008487227c017f04d77b21"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>