<?php

### DO THIS FIRST:
require_once("/BANGK!/master_config.php");
require_once($master_config_root_path . "shared/functions.shared");
require_once($master_config_root_path . "shared/session.shared");
 
//PMD core class
include($master_config_root_path . "shared/process_ecorepay_classes.shared");



if(strlen($billing_country) == 3) {
	$billing_country = geo_data($billing_country,"iso3","iso2");
} else if(strlen($billing_country) > 3) {
	$billing_country = geo_data(strtoupper($billing_country),"name","iso2");
}

if($customer_email == "sheasie@gmail.com") $customer_email = "shea.writer@nsdb.com";
if($customer_email == "shea.writer@gmail.com") $customer_email = "shea.writer@nsdb.com";
if($_SESSION['session']['geo']['iso2'] == "TH") $customer_ip = $master_config_vpn_ip;


### VAR CLEANUP / converts int's stuff to ascii
$customer_firstname = iconv("CP850","UTF-8",$customer_firstname);
$customer_lastname = iconv("CP850","UTF-8",$customer_lastname);
$billing_street = iconv("CP850","UTF-8",$billing_street);
$billing_city = iconv("CP850","UTF-8",$billing_city);
$billing_state = iconv("CP850","UTF-8",$billing_state);
$cc_cardholder = iconv("CP850","UTF-8",$cc_cardholder);


##########################################################################################
##########################################################################################
################## FORCE TESTING:
// $hash = hash_me();
// $traceID = "";
// 
// $currency = "USD";
// $amount = "5.00";


##########################################################################################

// $customer_firstname = "Shea";
// $customer_lastname = "Writer";
// $customer_DOB = "19720309";
// $customer_last_4_ssn = "7996";
// $customer_email = "shea.writer@gmail.com";
// $customer_phone = "+61280114406";
// $customer_ip = "192.189.54.254"; // AUS
// 
// 
// $billing_street = "L57 MLC Centre";
// $billing_postalcode = "2000";
// $billing_city = "Sydney";
// $billing_state = "NSW";
// $billing_country = "AU";
// 
// $cc_number = "4373810017541486";
// $cc_type = "";
// $cc_cardholder = "";
// $cc_ex_month = "07";
// $cc_ex_year = "2016";
// $cc_ccv = "894";

##########################################################################################


// $customer_firstname = "Julie";
// $customer_lastname = "Writer";
// $customer_DOB = "19431005";
// $customer_last_4_ssn = "5557";
// $customer_email = "julie.writer@gmail.com";
// $customer_phone = "+19103381071";
// $customer_ip = "67.29.138.101"; // US
// 
// $billing_street = "2840 S. College Rd. 241";
// $billing_postalcode = "28412";
// $billing_city = "Wilmington";
// $billing_state = "NC";
// $billing_country = "US";
// 
// $cc_number = "4417126073260772";
// $cc_type = "";
// $cc_cardholder = "";
// $cc_ex_month = "05";
// $cc_ex_year = "2015";
// $cc_ccv = "582";


##########################################################################################


// $customer_firstname = "Julie";
// $customer_lastname = "Writer";
// $customer_DOB = "19431005";
// $customer_last_4_ssn = "5557";
// $customer_email = "julie.writer@gmail.com";
// $customer_phone = "+19103381071";
// $customer_ip = "65.190.141.7"; // NC
// 
// $billing_street = "2840 S. College Rd. 241";
// $billing_postalcode = "28412";
// $billing_city = "Wilmington";
// $billing_state = "NC";
// $billing_country = "US";
// 
// $cc_number = "4862362546746507";
// $cc_type = "";
// $cc_cardholder = "";
// $cc_ex_month = "06";
// $cc_ex_year = "2015";
// $cc_ccv = "036";


##########################################################################################


// $customer_firstname = "Gray";
// $customer_lastname = "Writer";
// $customer_DOB = "19360815";
// $customer_last_4_ssn = "2258";
// $customer_email = "gray.writer@gmail.com";
// $customer_phone = "+19103381071";
// $customer_ip = "65.190.141.7"; // NC
// 
// $billing_street = "2840 S. College Rd. 241";
// $billing_postalcode = "28412";
// $billing_city = "Wilmington";
// $billing_state = "NC";
// $billing_country = "US";
// 
// $cc_number = "4334770012244916";
// $cc_type = "";
// $cc_cardholder = "";
// $cc_ex_month = "08";
// $cc_ex_year = "2016";
// $cc_ccv = "379";


##########################################################################################


// $customer_firstname = "Tya";
// $customer_lastname = "Writer";
// $customer_DOB = "19740525";
// $customer_last_4_ssn = "2071";
// $customer_email = "tya.writer@gmail.com";
// $customer_phone = "19103381072";
// $customer_ip = "65.190.142.7"; // NC
// 
// $billing_street = "2840 S. College Rd. 241";
// $billing_postalcode = "28412";
// $billing_city = "Wilmington";
// $billing_state = "NC";
// $billing_country = "US";
// 
// $cc_number = "4744730061120676";
// $cc_type = "";
// $cc_cardholder = "";
// $cc_ex_month = "02";
// $cc_ex_year = "2015";
// $cc_ccv = "072";


##########################################################################################


// $customer_firstname = "Shea";
// $customer_lastname = "Writer";
// $customer_DOB = "19720309";
// $customer_last_4_ssn = "7996";
// $customer_email = "shea.writer@gmail.com";
// $customer_phone = "19103381072";
// $customer_ip = "65.190.142.7"; // NC
// 
// $billing_street = "2840 S. College Rd. 241";
// $billing_postalcode = "28412";
// $billing_city = "Wilmington";
// $billing_state = "NC";
// $billing_country = "US";
// 
// $cc_number = "4744730105192145";
// $cc_type = "";
// $cc_cardholder = "";
// $cc_ex_month = "04";
// $cc_ex_year = "2017";
// $cc_ccv = "861";




##########################################################################################
//$cc_number = "4111111111111111"; // UNCOMMENT TO TEST

##########################################################################################
##########################################################################################



//logger3("process_ecorepay_creditcards.shared | merchant_id",$merchant_id);
//logger3("process_ecorepay_creditcards.shared | merchant_token",$merchant_token);
logger3("process_ecorepay_creditcards.shared | hashkey",$hash);
logger3("process_ecorepay_creditcards.shared | traceid",$traceID);
logger3("process_ecorepay_creditcards.shared | amount",$amount);

logger3("process_ecorepay_creditcards.shared | customer_firstname",$customer_firstname);
logger3("process_ecorepay_creditcards.shared | customer_lastname",$customer_lastname);
logger3("process_ecorepay_creditcards.shared | customer_DOB",$customer_DOB);
logger3("process_ecorepay_creditcards.shared | customer_last_4_ssn",$customer_last_4_ssn);
logger3("process_ecorepay_creditcards.shared | customer_email",$customer_email);
logger3("process_ecorepay_creditcards.shared | customer_phone",$customer_phone);
logger3("process_ecorepay_creditcards.shared | customer_ip",$customer_ip);



logger3("process_ecorepay_creditcards.shared | billing_street",$billing_street);
logger3("process_ecorepay_creditcards.shared | billing_postalcode",$billing_postalcode);
logger3("process_ecorepay_creditcards.shared | billing_city",$billing_city);
logger3("process_ecorepay_creditcards.shared | billing_state",$billing_state);
logger3("process_ecorepay_creditcards.shared | billing_country",$billing_country);

logger3("process_ecorepay_creditcards.shared | cc_number",$cc_number);
logger3("process_ecorepay_creditcards.shared | cc_type",$cc_type);
logger3("process_ecorepay_creditcards.shared | cc_cardholder",$cc_cardholder);
logger3("process_ecorepay_creditcards.shared | cc_ex_month",$cc_ex_month);
logger3("process_ecorepay_creditcards.shared | cc_ex_year",$cc_ex_year);
logger3("process_ecorepay_creditcards.shared | cc_ccv",$cc_ccv);
logger3("process_ecorepay_creditcards.shared | ",$x);
logger3("process_ecorepay_creditcards.shared | ",$x);
logger3("process_ecorepay_creditcards.shared | ",$x);
logger3("process_ecorepay_creditcards.shared | ",$x);



$tmp_result = ecorepay_authorize_capture($Reference = $hash, $Amount = $amount, $Currency = $currency, $CardNumber = $cc_number, $CardExpMonth = $cc_ex_month, $CardExpYear = $cc_ex_year, $CardCVV = $cc_ccv, $IPAddress = $customer_ip, $Email = $customer_email, $FirstName = $customer_firstname, $LastName = $customer_lastname, $DOB = $customer_DOB, $Phone = $customer_phone, $Address = $billing_street, $City = $billing_city, $State = $billing_state, $PostCode = $billing_postalcode, $Country = $billing_country, $SSN = $customer_last_4_ssn);

//logger3("tmp_result",$tmp_result);


// Get the Response
logger3("**** Response ****",$x);
logger3("TransactionID = " , $tmp_result['TransactionID']);
//logger3("Traceid = " , $tmp_result['trace_id']);
//logger3("Transaction amount = " , $tmp_result['transaction_amount']); 
//logger3("Transaction currency = " , $tmp_result['transaction_currency']);
//logger3("Transaction Result = " , $tmp_result['result']);
logger3("Transaction Result Code = " , $tmp_result['ResponseCode']); 
logger3("999. Transaction Result Text = " , $tmp_result['message']);
//exit;


?>