shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

maxmind.php (14037B)


      1 <?php
      2 class ModelExtensionFraudMaxMind extends Model {
      3 	public function check($order_info) {
      4 		$risk_score = 0;
      5 
      6 		$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "maxmind` WHERE order_id = '" . (int)$order_info['order_id'] . "'");
      7 
      8 		if ($query->num_rows) {
      9 			$risk_score = $query->row['risk_score'];
     10 		} else {
     11 			/*
     12 			maxmind api
     13 			http://www.maxmind.com/app/ccv
     14 
     15 			paypal api
     16 			https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_IPNandPDTVariables
     17 			*/
     18 
     19 			$request = 'i=' . urlencode($order_info['ip']);
     20 			$request .= '&city=' . urlencode($order_info['payment_city']);
     21 			$request .= '&region=' . urlencode($order_info['payment_zone']);
     22 			$request .= '&postal=' . urlencode($order_info['payment_postcode']);
     23 			$request .= '&country=' . urlencode($order_info['payment_country']);
     24 			$request .= '&domain=' . urlencode(utf8_substr(strrchr($order_info['email'], '@'), 1));
     25 			$request .= '&custPhone=' . urlencode($order_info['telephone']);
     26 			$request .= '&license_key=' . urlencode($this->config->get('fraud_maxmind_key'));
     27 
     28 			if ($order_info['shipping_method']) {
     29 				$request .= '&shipAddr=' . urlencode($order_info['shipping_address_1']);
     30 				$request .= '&shipCity=' . urlencode($order_info['shipping_city']);
     31 				$request .= '&shipRegion=' . urlencode($order_info['shipping_zone']);
     32 				$request .= '&shipPostal=' . urlencode($order_info['shipping_postcode']);
     33 				$request .= '&shipCountry=' . urlencode($order_info['shipping_country']);
     34 			}
     35 
     36 			$request .= '&user_agent=' . urlencode($order_info['user_agent']);
     37 			$request .= '&forwardedIP=' . urlencode($order_info['forwarded_ip']);
     38 			$request .= '&emailMD5=' . urlencode(md5(utf8_strtolower($order_info['email'])));
     39 			//$request .= '&passwordMD5=' . urlencode($order_info['password']);
     40 			$request .= '&accept_language=' .  urlencode($order_info['accept_language']);
     41 			$request .= '&order_amount=' . urlencode($this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false));
     42 			$request .= '&order_currency=' . urlencode($order_info['currency_code']);
     43 
     44 			$curl = curl_init('https://minfraud1.maxmind.com/app/ccv2r');
     45 
     46 			curl_setopt($curl, CURLOPT_HEADER, 0);
     47 			curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
     48 			curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     49 			curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
     50 			curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
     51 			curl_setopt($curl, CURLOPT_POST, 1);
     52 			curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
     53 
     54 			$response = curl_exec($curl);
     55 
     56 			curl_close($curl);
     57 
     58 			$risk_score = 0;
     59 
     60 			if ($response) {
     61 				$order_id = $order_info['order_id'];
     62 				$customer_id = $order_info['customer_id'];
     63 
     64 				$response_info = array();
     65 
     66 				$parts = explode(';', $response);
     67 
     68 				foreach ($parts as $part) {
     69 					list($key, $value) = explode('=', $part);
     70 
     71 					$response_info[$key] = $value;
     72 				}
     73 
     74 				if (isset($response_info['countryMatch'])) {
     75 					$country_match = $response_info['countryMatch'];
     76 				} else {
     77 					$country_match = '';
     78 				}
     79 
     80 				if (isset($response_info['countryCode'])) {
     81 					$country_code = $response_info['countryCode'];
     82 				} else {
     83 					$country_code = '';
     84 				}
     85 
     86 				if (isset($response_info['highRiskCountry'])) {
     87 					$high_risk_country = $response_info['highRiskCountry'];
     88 				} else {
     89 					$high_risk_country = '';
     90 				}
     91 
     92 				if (isset($response_info['distance'])) {
     93 					$distance = $response_info['distance'];
     94 				} else {
     95 					$distance = '';
     96 				}
     97 
     98 				if (isset($response_info['ip_region'])) {
     99 					$ip_region = $response_info['ip_region'];
    100 				} else {
    101 					$ip_region = '';
    102 				}
    103 
    104 				if (isset($response_info['ip_city'])) {
    105 					$ip_city = $response_info['ip_city'];
    106 				} else {
    107 					$ip_city = '';
    108 				}
    109 
    110 				if (isset($response_info['ip_latitude'])) {
    111 					$ip_latitude = $response_info['ip_latitude'];
    112 				} else {
    113 					$ip_latitude = '';
    114 				}
    115 
    116 				if (isset($response_info['ip_longitude'])) {
    117 					$ip_longitude = $response_info['ip_longitude'];
    118 				} else {
    119 					$ip_longitude = '';
    120 				}
    121 
    122 				if (isset($response_info['ip_isp'])) {
    123 					$ip_isp = $response_info['ip_isp'];
    124 				} else {
    125 					$ip_isp = '';
    126 				}
    127 
    128 				if (isset($response_info['ip_org'])) {
    129 					$ip_org = $response_info['ip_org'];
    130 				} else {
    131 					$ip_org = '';
    132 				}
    133 
    134 				if (isset($response_info['ip_asnum'])) {
    135 					$ip_asnum = $response_info['ip_asnum'];
    136 				} else {
    137 					$ip_asnum = '';
    138 				}
    139 
    140 				if (isset($response_info['ip_userType'])) {
    141 					$ip_user_type = $response_info['ip_userType'];
    142 				} else {
    143 					$ip_user_type = '';
    144 				}
    145 
    146 				if (isset($response_info['ip_countryConf'])) {
    147 					$ip_country_confidence = $response_info['ip_countryConf'];
    148 				} else {
    149 					$ip_country_confidence = '';
    150 				}
    151 
    152 				if (isset($response_info['ip_regionConf'])) {
    153 					$ip_region_confidence = $response_info['ip_regionConf'];
    154 				} else {
    155 					$ip_region_confidence = '';
    156 				}
    157 
    158 				if (isset($response_info['ip_cityConf'])) {
    159 					$ip_city_confidence = $response_info['ip_cityConf'];
    160 				} else {
    161 					$ip_city_confidence = '';
    162 				}
    163 
    164 				if (isset($response_info['ip_postalConf'])) {
    165 					$ip_postal_confidence = $response_info['ip_postalConf'];
    166 				} else {
    167 					$ip_postal_confidence = '';
    168 				}
    169 
    170 				if (isset($response_info['ip_postalCode'])) {
    171 					$ip_postal_code = $response_info['ip_postalCode'];
    172 				} else {
    173 					$ip_postal_code = '';
    174 				}
    175 
    176 				if (isset($response_info['ip_accuracyRadius'])) {
    177 					$ip_accuracy_radius = $response_info['ip_accuracyRadius'];
    178 				} else {
    179 					$ip_accuracy_radius = '';
    180 				}
    181 
    182 				if (isset($response_info['ip_netSpeedCell'])) {
    183 					$ip_net_speed_cell = $response_info['ip_netSpeedCell'];
    184 				} else {
    185 					$ip_net_speed_cell = '';
    186 				}
    187 
    188 				if (isset($response_info['ip_metroCode'])) {
    189 					$ip_metro_code = $response_info['ip_metroCode'];
    190 				} else {
    191 					$ip_metro_code = '';
    192 				}
    193 				if (isset($response_info['ip_areaCode'])) {
    194 					$ip_area_code = $response_info['ip_areaCode'];
    195 				} else {
    196 					$ip_area_code = '';
    197 				}
    198 
    199 				if (isset($response_info['ip_timeZone'])) {
    200 					$ip_time_zone = $response_info['ip_timeZone'];
    201 				} else {
    202 					$ip_time_zone = '';
    203 				}
    204 
    205 				if (isset($response_info['ip_regionName'])) {
    206 					$ip_region_name = $response_info['ip_regionName'];
    207 				} else {
    208 					$ip_region_name = '';
    209 				}
    210 
    211 				if (isset($response_info['ip_domain'])) {
    212 					$ip_domain = $response_info['ip_domain'];
    213 				} else {
    214 					$ip_domain = '';
    215 				}
    216 				if (isset($response_info['ip_countryName'])) {
    217 					$ip_country_name = $response_info['ip_countryName'];
    218 				} else {
    219 					$ip_country_name = '';
    220 				}
    221 
    222 				if (isset($response_info['ip_continentCode'])) {
    223 					$ip_continent_code = $response_info['ip_continentCode'];
    224 				} else {
    225 					$ip_continent_code = '';
    226 				}
    227 
    228 				if (isset($response_info['ip_corporateProxy'])) {
    229 					$ip_corporate_proxy = $response_info['ip_corporateProxy'];
    230 				} else {
    231 					$ip_corporate_proxy = '';
    232 				}
    233 
    234 				if (isset($response_info['anonymousProxy'])) {
    235 					$anonymous_proxy = $response_info['anonymousProxy'];
    236 				} else {
    237 					$anonymous_proxy = '';
    238 				}
    239 
    240 				if (isset($response_info['proxyScore'])) {
    241 					$proxy_score = $response_info['proxyScore'];
    242 				} else {
    243 					$proxy_score = '';
    244 				}
    245 
    246 				if (isset($response_info['isTransProxy'])) {
    247 					$is_trans_proxy = $response_info['isTransProxy'];
    248 				} else {
    249 					$is_trans_proxy = '';
    250 				}
    251 
    252 				if (isset($response_info['freeMail'])) {
    253 					$free_mail = $response_info['freeMail'];
    254 				} else {
    255 					$free_mail = '';
    256 				}
    257 
    258 				if (isset($response_info['carderEmail'])) {
    259 					$carder_email = $response_info['carderEmail'];
    260 				} else {
    261 					$carder_email = '';
    262 				}
    263 
    264 				if (isset($response_info['highRiskUsername'])) {
    265 					$high_risk_username = $response_info['highRiskUsername'];
    266 				} else {
    267 					$high_risk_username = '';
    268 				}
    269 
    270 				if (isset($response_info['highRiskPassword'])) {
    271 					$high_risk_password = $response_info['highRiskPassword'];
    272 				} else {
    273 					$high_risk_password = '';
    274 				}
    275 
    276 				if (isset($response_info['binMatch'])) {
    277 					$bin_match = $response_info['binMatch'];
    278 				} else {
    279 					$bin_match = '';
    280 				}
    281 
    282 				if (isset($response_info['binCountry'])) {
    283 					$bin_country = $response_info['binCountry'];
    284 				} else {
    285 					$bin_country = '';
    286 				}
    287 
    288 				if (isset($response_info['binNameMatch'])) {
    289 					$bin_name_match = $response_info['binNameMatch'];
    290 				} else {
    291 					$bin_name_match = '';
    292 				}
    293 
    294 				if (isset($response_info['binName'])) {
    295 					$bin_name = $response_info['binName'];
    296 				} else {
    297 					$bin_name = '';
    298 				}
    299 
    300 				if (isset($response_info['binPhoneMatch'])) {
    301 					$bin_phone_match = $response_info['binPhoneMatch'];
    302 				} else {
    303 					$bin_phone_match = '';
    304 				}
    305 
    306 				if (isset($response_info['binPhone'])) {
    307 					$bin_phone = $response_info['binPhone'];
    308 				} else {
    309 					$bin_phone = '';
    310 				}
    311 
    312 				if (isset($response_info['custPhoneInBillingLoc'])) {
    313 					$customer_phone_in_billing_location = $response_info['custPhoneInBillingLoc'];
    314 				} else {
    315 					$customer_phone_in_billing_location = '';
    316 				}
    317 
    318 				if (isset($response_info['shipForward'])) {
    319 					$ship_forward = $response_info['shipForward'];
    320 				} else {
    321 					$ship_forward = '';
    322 				}
    323 
    324 				if (isset($response_info['cityPostalMatch'])) {
    325 					$city_postal_match = $response_info['cityPostalMatch'];
    326 				} else {
    327 					$city_postal_match = '';
    328 				}
    329 
    330 				if (isset($response_info['shipCityPostalMatch'])) {
    331 					$ship_city_postal_match = $response_info['shipCityPostalMatch'];
    332 				} else {
    333 					$ship_city_postal_match = '';
    334 				}
    335 
    336 				if (isset($response_info['score'])) {
    337 					$score = $response_info['score'];
    338 				} else {
    339 					$score = '';
    340 				}
    341 
    342 				if (isset($response_info['explanation'])) {
    343 					$explanation = $response_info['explanation'];
    344 				} else {
    345 					$explanation = '';
    346 				}
    347 
    348 				if (isset($response_info['riskScore'])) {
    349 					$risk_score = $response_info['riskScore'];
    350 				} else {
    351 					$risk_score = '';
    352 				}
    353 
    354 				if (isset($response_info['queriesRemaining'])) {
    355 					$queries_remaining = $response_info['queriesRemaining'];
    356 				} else {
    357 					$queries_remaining = '';
    358 				}
    359 
    360 				if (isset($response_info['maxmindID'])) {
    361 					$maxmind_id = $response_info['maxmindID'];
    362 				} else {
    363 					$maxmind_id = '';
    364 				}
    365 
    366 				if (isset($response_info['err'])) {
    367 					$error = $response_info['err'];
    368 				} else {
    369 					$error = '';
    370 				}
    371 
    372 				$this->db->query("INSERT INTO `" . DB_PREFIX . "maxmind` SET order_id = '" . (int)$order_id . "', customer_id = '" . (int)$customer_id . "', country_match = '" . $this->db->escape($country_match) . "', country_code = '" . $this->db->escape($country_code) . "', high_risk_country = '" . $this->db->escape($high_risk_country) . "', distance = '" . (int)$distance . "', ip_region = '" . $this->db->escape($ip_region) . "', ip_city = '" . $this->db->escape($ip_city) . "', ip_latitude = '" . $this->db->escape($ip_latitude) . "', ip_longitude = '" . $this->db->escape($ip_longitude) . "', ip_isp = '" . $this->db->escape($ip_isp) . "', ip_org = '" . $this->db->escape($ip_org) . "', ip_asnum = '" . (int)$ip_asnum . "', ip_user_type = '" . $this->db->escape($ip_user_type) . "', ip_country_confidence = '" . $this->db->escape($ip_country_confidence) . "', ip_region_confidence = '" . $this->db->escape($ip_region_confidence) . "', ip_city_confidence = '" . $this->db->escape($ip_city_confidence) . "', ip_postal_confidence = '" . $this->db->escape($ip_postal_confidence) . "', ip_postal_code = '" . $this->db->escape($ip_postal_code) . "', ip_accuracy_radius = '" . (int)$ip_accuracy_radius . "', ip_net_speed_cell = '" . $this->db->escape($ip_net_speed_cell) . "', ip_metro_code = '" . (int)$ip_metro_code . "', ip_area_code = '" . (int)$ip_area_code . "', ip_time_zone = '" . $this->db->escape($ip_time_zone) . "', ip_region_name = '" . $this->db->escape($ip_region_name) . "', ip_domain = '" . $this->db->escape($ip_domain) . "', ip_country_name = '" . $this->db->escape($ip_country_name) . "', ip_continent_code = '" . $this->db->escape($ip_continent_code) . "', ip_corporate_proxy = '" . $this->db->escape($ip_corporate_proxy) . "', anonymous_proxy = '" . $this->db->escape($anonymous_proxy) . "', proxy_score = '" . (float)$proxy_score . "', is_trans_proxy = '" . $this->db->escape($is_trans_proxy) . "', free_mail = '" . $this->db->escape($free_mail) . "', carder_email = '" . $this->db->escape($carder_email) . "', high_risk_username = '" . $this->db->escape($high_risk_username) . "', high_risk_password = '" . $this->db->escape($high_risk_password) . "', bin_match = '" . $this->db->escape($bin_match) . "', bin_country = '" . $this->db->escape($bin_country) . "',  bin_name_match = '" . $this->db->escape($bin_name_match) . "', bin_name = '" . $this->db->escape($bin_name) . "', bin_phone_match = '" . $this->db->escape($bin_phone_match) . "', bin_phone = '" . $this->db->escape($bin_phone) . "', customer_phone_in_billing_location = '" . $this->db->escape($customer_phone_in_billing_location) . "', ship_forward = '" . $this->db->escape($ship_forward) . "', city_postal_match = '" . $this->db->escape($city_postal_match) . "', ship_city_postal_match = '" . $this->db->escape($ship_city_postal_match) . "', score = '" . (float)$score . "', explanation = '" . $this->db->escape($explanation) . "', risk_score = '" . (float)$risk_score . "', queries_remaining = '" . (int)$queries_remaining . "', maxmind_id = '" . $this->db->escape($maxmind_id) . "', error = '" . $this->db->escape($error) . "', date_added = NOW()");
    373 			}
    374 		}
    375 
    376 		if ($risk_score > $this->config->get('fraud_maxmind_score') && $this->config->get('fraud_maxmind_key')) {
    377 			return $this->config->get('maxmind_order_status_id');
    378 		}
    379 	}
    380 }