<?
### DO THIS FIRST:
include_once("/BANGK!/master_config.php");
include_once($master_config_root_path . "/shared/functions.shared");
include_once($master_config_root_path . "/shared/session.shared");


/*
$input_transaction['maxmind']['customer_ip'] = NULL;
$input_transaction['maxmind']['geo_data'] = NULL;
$input_transaction['maxmind']['city'] = NULL;
$input_transaction['maxmind']['region'] = NULL;
$input_transaction['maxmind']['post_code'] = NULL;
$input_transaction['maxmind']['country'] = NULL;
$input_transaction['maxmind']['credit_card']['bin'] = NULL;

*/


if($_SESSION['testing']) unset($_SESSION['transaction']['maxmind']);
if(!$_SESSION['transaction']['maxmind']) {
########################################################################################################
########################################################################################################
########################################################################################################



	/// SET VARS
	//customer ip // required
	if($input_transaction['maxmind']['customer_ip']) {
		$_SESSION['transaction']['maxmind']['customer_ip'] = $input_transaction['maxmind']['customer_ip'];
	} else {
		$_SESSION['transaction']['maxmind']['customer_ip'] = $_SERVER['REMOTE_ADDR'];
	}
	
	//bin
	if($input_transaction['maxmind']['credit_card']['bin']) {
		$_SESSION['transaction']['maxmind']['credit_card']['bin'] = $input_transaction['maxmind']['credit_card']['bin'];
	} else {
		$_SESSION['transaction']['maxmind']['credit_card']['bin'] = NULL;
	}
	
	//geodata
	if($input_transaction['maxmind']['geo_data']) {
		$_SESSION['transaction']['maxmind']['geo_data'] = $input_transaction['maxmind']['geo_data'];
	} else {
		$_SESSION['transaction']['maxmind']['geo_data'] = $session['geo'];
	}
	
	//city
	if($input_transaction['maxmind']['city']) {
		$_SESSION['transaction']['maxmind']['city'] = $input_transaction['maxmind']['city'];
	} else {
		$_SESSION['transaction']['maxmind']['city'] = NULL;
	}
	
	//region
	if($input_transaction['maxmind']['region']) {
		$_SESSION['transaction']['maxmind']['region'] = $input_transaction['maxmind']['region'];
	} else {
		$_SESSION['transaction']['maxmind']['region'] = NULL;
	}
	
	//postal
	if($input_transaction['maxmind']['post_code']) {
		$_SESSION['transaction']['maxmind']['post_code'] = $input_transaction['maxmind']['post_code'];
	} else {
		$_SESSION['transaction']['maxmind']['post_code'] = NULL;
	}
	
	//country
	if($input_transaction['maxmind']['country_iso2']) {
		$_SESSION['transaction']['maxmind']['country_iso2'] = $input_transaction['maxmind']['country_iso2'];
	} else {
		$_SESSION['transaction']['maxmind']['country_iso2'] = $session['geo']['ison'];
	}
	

	logger("transaction['maxmind']"); logger($_SESSION['transaction']['maxmind']);
	
	/// SET KURL PARAMETERS
	$_SESSION['transaction']['maxmind']['parameters'] = "";
	$_SESSION['transaction']['maxmind']['parameters'] .= "i=" . $_SESSION['transaction']['maxmind']['customer_ip'];
	$_SESSION['transaction']['maxmind']['parameters'] .= "&city=" . $_SESSION['transaction']['maxmind']['city'];
	$_SESSION['transaction']['maxmind']['parameters'] .= "&region=" . $_SESSION['transaction']['maxmind']['region'];
	$_SESSION['transaction']['maxmind']['parameters'] .= "&postal=" . $_SESSION['transaction']['maxmind']['post_code'];
	$_SESSION['transaction']['maxmind']['parameters'] .= "&country=" . $_SESSION['transaction']['maxmind']['country_iso2'];
	$_SESSION['transaction']['maxmind']['parameters'] .= "&license_key=TuG3uxB3yvj4";
	$_SESSION['transaction']['maxmind']['parameters'] .= "&requested_type=premium";
	$_SESSION['transaction']['maxmind']['parameters'] .= "&txn_type=creditcard";
	$_SESSION['transaction']['maxmind']['parameters'] .= "&bin=" . $_SESSION['transaction']['maxmind']['credit_card']['bin']; // first six digits of credit card
	
	/// KURL IT:
	$_SESSION['transaction']['maxmind']['url'] = "https://minfraud2.maxmind.com/app/ccv2r";
	$_SESSION['transaction']['maxmind']['results'] = processorCURLER($_SESSION['transaction']['maxmind']['url'],$_SESSION['transaction']['maxmind']['parameters']); // save results to session?
	
	//test("tmp_maxmind['parameters']",$input_transaction['maxmind']['parameters']);
	
	//logger("retry['maxmind']['url']: " . $input_transaction['maxmind']['url']);
	//logger("retry['maxmind']['parameters']: " . $input_transaction['maxmind']['parameters']);
	//logger("tmp_maxmind['results']"); logger($input_transaction['maxmind']['results']);
	
	
	
	$tmp_maxmind_results = $_SESSION['transaction']['maxmind']['results'];
	//test("tmp_maxmind_results",$tmp_maxmind_results);
	
	
	$tmp_maxmind_results_exploded = explode(";",$tmp_maxmind_results);
	//test("tmp_exploded_results",$tmp_maxmind_results_exploded);
	
	foreach($tmp_maxmind_results_exploded as $key => $value) {
		//test("key",$key);
		//test("value",$value);
		$tmp_explosion = explode("=",$tmp_maxmind_results_exploded[$key]);
		if($key == 0) {
			$distance_explosion = explode("distance=",$tmp_explosion[1]);
			$input_transaction['maxmind']['distance'] = $distance_explosion[1];
		} else {
			 $tmp_maxmind[$tmp_explosion[0]] = $tmp_explosion[1];
		}
	}
	
	$_SESSION['transaction']['maxmind'] = $tmp_maxmind;
	
	//test("session['maxmind']",$_SESSION['transaction']['maxmind']);
	
	/*
	    [distance] => 
	    [countryMatch] => 
	    [countryCode] => 
	    [freeMail] => 
	    [anonymousProxy] => 
	    [score] => 
	    [binMatch] => 
	    [binCountry] => 
	    [err] => IP_REQUIRED
	    [proxyScore] => 
	    [spamScore] => 
	    [ip_region] => 
	    [ip_city] => 
	    [ip_latitude] => 
	    [ip_longitude] => 
	    [binName] => 
	    [ip_isp] => 
	    [ip_org] => 
	    [binNameMatch] => 
	    [binPhoneMatch] => 
	    [binPhone] => 
	    [custPhoneInBillingLoc] => 
	    [highRiskCountry] => 
	    [queriesRemaining] => 184
	    [cityPostalMatch] => 
	    [shipCityPostalMatch] => 
	    [maxmindID] => L15SJKTT
	 */
	



########################################################################################################
########################################################################################################
########################################################################################################
}


 
unset($input_transaction['maxmind']['customer_ip']);
unset($input_transaction['maxmind']['geo_data']);
unset($input_transaction['maxmind']['city']);
unset($input_transaction['maxmind']['region']);
unset($input_transaction['maxmind']['postal_code']);
unset($input_transaction['maxmind']['country']);
unset($input_transaction['maxmind']['credit_card']['bin']);
unset($input_transaction['maxmind']['credit_card']['country_iso2']);



?>


