Electronic Check Secure Payment Form
* indicates a required field |
|
_err;
MyFormCheck::check_email($customer_email);
$err .= $MyFormCheck->_err;
if($user_agree != 'Yes'){
$err .= '
You have to agree authorization statement.';
}
if($err == ''){
$DEBUGGING = 1; # Display additional information to track down problems
$TESTING = 1; # Set the testing flag so that transactions are not live
$ERROR_RETRIES = 2; # Number of transactions to post if soft errors occur
$auth_net_login_id = "4n8m2QXE";
$auth_net_tran_key = "45EYzyyxBd4798DV";
$auth_net_url = "https://secure.authorize.net/gateway/transact.dll";
# Uncomment the line ABOVE for test accounts or BELOW for live merchant accounts
//Test Account
// $auth_net_login_id = "54PB5egZ";
// $auth_net_tran_key = "48V258vr55AE8tcg";
// $auth_net_url = "https://test.authorize.net/gateway/transact.dll";
$authnet_values = array
(
"x_login" => $auth_net_login_id,
"x_version" => "3.1",
"x_delim_char" => "|",
"x_delim_data" => "TRUE",
"x_type" => "AUTH_CAPTURE",
"x_method" => "ECHECK",
"x_tran_key" => $auth_net_tran_key,
"x_relay_response" => "FALSE",
"x_bank_aba_code" => $ABARoutingNumber,
"x_bank_acct_num" => $AccountNumber,
"x_bank_acct_type" => $AccountType,
"x_bank_name" => $BankName,
"x_bank_acct_name" => $AccountName,
"x_echeck_type" => "WEB",
"x_amount" => $chargetotal,
"x_first_name" => $sname,
"x_last_name" => "",
"x_address" => htmlspecialchars($saddress1),
"x_city" => $scity,
"x_state" => $sstate,
"x_zip" => $szip,
"x_country" => "USA",
"x_phone" => $Telephone,
"x_email" => $customer_email,
"x_customer_ip" => $_SERVER['REMOTE_ADDR'],
"Insurance_Carrier" => htmlspecialchars($_POST["Carrier"]),
"Policy_Number" => htmlspecialchars($_POST["Policy_Number"]),
"Comments" => htmlspecialchars($_POST["comments"]),
);
$fields = "";
while(list($key, $value) = each($authnet_values)) {
$data .= $key . '=' . urlencode(ereg_replace(',', '', $value)) . '&';
}
// Remove the last "&" from the string
$data = substr($data, 0, -1);
//exec("/usr/bin/curl -k -d '$data' $auth_net_url", $response);
$request = curl_init($auth_net_url); // initiate curl object
curl_setopt($request, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
curl_setopt($request, CURLOPT_POSTFIELDS, $data); // use HTTP POST to send form data
curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response.
$post_response = curl_exec($request); // execute curl post and store results in $post_response
// This line takes the response and breaks it into an array using the specified delimiting character
$result = explode($authnet_values['x_delim_char'], $post_response);
//print_r($authnet_response);
//add this line.
//$result = explode(",", urldecode($response[0]));
$resp = $result[0];
$text = $resp;
$tok = strtok($text,"|");
while(!($tok === FALSE)){
$tok = strtok("|");
}
$text = $resp;
$h = substr_count($text, "|");
$h++;
for($j=1; $j <= $h; $j++){
$p = strpos($text, "|");
if ($p === false) { // note: three equal signs
}else{
$p++;
$pstr = substr($text, 0, $p);
$pstr_trimmed = substr($pstr, 0, -1); // removes "|" at the end
if($pstr_trimmed==""){
$pstr_trimmed="NO VALUE RETURNED";
}
switch($j){
case 1:
$fval="";
if($pstr_trimmed=="1"){
$fval="Approved";
$success_payment = "Approved";
}elseif($pstr_trimmed=="2"){
$fval="Declined";
}elseif($pstr_trimmed=="3"){
$fval="Error";
}
break;
case 2:
break;
case 3:
$response_reason_text = $result[3];
break;
case 4:
$response_reason_text = $pstr_trimmed;
break;
case 39:
$fval="";
if($pstr_trimmed=="M"){
$fval="M = Match";
}elseif($pstr_trimmed=="N"){
$fval="N = No Match";
}elseif($pstr_trimmed=="P"){
$fval="P = Not Processed";
}elseif($pstr_trimmed=="S"){
$fval="S = Should have been present";
}elseif($pstr_trimmed=="U"){
$fval="U = Issuer unable to process request";
}else{
$fval="NO VALUE RETURNED";
}
break;
default:
break;
}
// remove the part that we identified and work with the rest of the string
$text = substr($text, $p);
}// if ($p === false)
}// end for($j=1; $j <= $h; $j++)
if($success_payment != 'Approved') {
$err = $response_reason_text;
if(strlen($response_reason_text)<=0){
$err = $result[3];
}
if(strpos($err,'approved.')>0){
$t=time();
$d = date("F d, Y");
$from_email = "payment@insureusa.com";
$subject = "InsureUSA Insurance echeck Payment Confirmation";
$message = implode('', file("echeck_receipt.html"));
$message = str_replace("[DATE]",$d,$message);
$message = str_replace("[sname]",$_POST['sname'],$message);
$message = str_replace("[saddress1]",$_POST['saddress1'],$message);
$message = str_replace("[acc_type_1]",$_POST['acc_type_1'],$message);
$message = str_replace("[scity]",$_POST['scity'],$message);
$message = str_replace("[szip]",$_POST['szip'],$message);
$message = str_replace("[sstate]",$_POST['sstate'],$message);
$message = str_replace("[Carrier]",$_POST['Carrier'],$message);
$message = str_replace("[Policy_Number]",$_POST['Policy_Number'],$message);
$message = str_replace("[chargetotal]",$_POST['chargetotal'],$message);
$message = str_replace("[Telephone]",$_POST['Telephone'],$message);
$message = str_replace("[customer_email]",$_POST['customer_email'],$message);
$message = str_replace("[customer_signature]",$_POST['customer_signature'],$message);
$message = str_replace("[comments]",$_POST['comments'],$message);
/****** Mail to Customer ***********/
MyMail::my_send_mail( $_POST['customer_email'], $subject, $message, $from_email, "InsureUSA.com");
$err .= $MyMail->_err;
/****** Mail to Admin ***********/
$subject = "InsureUSA Website Echeck Payment";
$from_email = "payment@insureusa.com";
MyMail::my_send_mail( $from_email, $subject, $message, $_POST['customer_email'], "InsureUSA.com");
$err .= $MyMail->_err;
$_SESSION['customer_email'] = $_POST['customer_email'];
header("Location:secure-form-thanks.htm");
}
}
elseif($success_payment == 'Approved'){
$t=time();
$d = date("F d, Y");
$from_email = "payment@insureusa.com";
$subject = "InsureUSA Insurance echeck Payment Confirmation";
$message = implode('', file("echeck_receipt.html"));
$message = str_replace("[DATE]",$d,$message);
$message = str_replace("[sname]",$_POST['sname'],$message);
$message = str_replace("[saddress1]",$_POST['saddress1'],$message);
$message = str_replace("[acc_type_1]",$_POST['acc_type_1'],$message);
$message = str_replace("[scity]",$_POST['scity'],$message);
$message = str_replace("[szip]",$_POST['szip'],$message);
$message = str_replace("[sstate]",$_POST['sstate'],$message);
$message = str_replace("[Carrier]",$_POST['Carrier'],$message);
$message = str_replace("[Policy_Number]",$_POST['Policy_Number'],$message);
$message = str_replace("[chargetotal]",$_POST['chargetotal'],$message);
$message = str_replace("[Telephone]",$_POST['Telephone'],$message);
$message = str_replace("[customer_email]",$_POST['customer_email'],$message);
$message = str_replace("[customer_signature]",$_POST['customer_signature'],$message);
$message = str_replace("[comments]",$_POST['comments'],$message);
/****** Mail to Customer ***********/
MyMail::my_send_mail( $_POST['customer_email'], $subject, $message, $from_email, "InsureUSA.com");
$err .= $MyMail->_err;
/****** Mail to Admin ***********/
$subject = "InsureUSA Website Echeck Payment";
$from_email = "payment@insureusa.com";
MyMail::my_send_mail( $from_email, $subject, $message, $_POST['customer_email'], "InsureUSA.com");
$err .= $MyMail->_err;
$_SESSION['customer_email'] = $_POST['customer_email'];
header("Location:secure-form-thanks.htm");
exit();
}
else{
$err = "Payment is not approved. It is decliend by payment gateway.";
}
}// if($err == '')
}//if(isset($_POST['submit']) && $_POST['submit']!='' )
?>
|