$post_array = array(
"x_login" => $username
,"x_tran_key" => $transaction_key
,"x_version" => "3.1"
,"x_test_request" => $x_test_request
,"x_delim_data" => "TRUE"
,"x_relay_response" => "FALSE"
,"x_first_name" => $REQUEST['first_name']
,"x_description" => $REQUEST['description']
,"x_last_name" => $REQUEST['last_name']
,"x_address" => $REQUEST['address']
,"x_city" => $REQUEST['city']
,"x_state" => $REQUEST['state']
,"x_zip" => $REQUEST['zip_code']
,"x_phone" => $REQUEST['phone']
,"x_email" => $_REQUEST['email']
,"x_country" => "USA"
,"x_email_customer" => "FALSE"
,"x_amount" => $total_cost
,"x_method" => "CC"
,"x_type" => "AUTH_CAPTURE"
,"x_card_num" => $credit_card_number
,"x_exp_date" => $credit_card_expiration_date
);
// [3] Convert Array to POST string (key_1=val_1&key_2=val_2...)
reset($post_array);
while (list ($key, $val) = each($post_array)) {
$data .= $key . "=" . urlencode($val) . "&";
}
// [4] Securely POST to AuthorizeNet using "curl"
$ch = curl_init("https://secure.authorize.net/gateway/transact.dll"); // URL of gateway for cURL to post to
curl_setopt($ch, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // use HTTP POST to send form data
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response.
$resp = curl_exec($ch); //execute post and get results
curl_close ($ch);
// [5] Handle Response FROM AuthorizeNet
// Set $authorized = TRUE if transaction wass successful
if ($resp{0} == 1) {
$header_1 = "Return-Path: $from_email\n";
$header_1 .= "X-Sender: $from_email\n";
$header_1 .= "From: $from_email <$from_email>\n";
$header_1 .= "X-Mailer😛HP 5.1\n";
$header_1 .= "MIME-Version: 1.0\n";
$header_1 .= "Content-Type: text/html; charset=utf-8\r\n";
$subject_1 = "Details";
$message_1 .= "<html>";
$message_1 .= "<body>";
$message_1 .= "<p><font size=\"2\" face=\"Verdana\">Message to cutomer.
<p>Gift Amount:\${$_REQUEST['total_cart']}</font></p>";
$message_1 .= "</body>";
$message_1 .= "</html>";
mail($_REQUEST['email'],$subject_1,$message_1,$header_1);
$header = "Return-Path: $admin_email\n";
$header .= "X-Sender: $admin_email\n";
$header .= "From: Name of Company<$from_email>\n";
$header .= "X-Mailer😛HP 5.1\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: text/html; charset=utf-8\r\n";
$subject = "Email Subject";
$message .= "<html>";
$message .= "<body>";
$POST['credit_card_number'] = false;
mail($b1email,$subject,$message,$header);
foreach($POST as $key => $value){
$message .= "$key : $value
";
}
$message .= "</body>";
$message .= "</html>";
foreach($admin_email as $key => $value){
mail($value,$subject,$message,$header);
}
header("location: $trans_accepted");
}elseif($resp{0} == 2){
header("location: $trans_failed");
}elseif($resp{0} == 3){
echo <<<END_HTML
<p style="margin-top: 0; margin-bottom: 0" align="center">
<font face="Arial" size="2">There was an error processing your request.</font></p>
<p align="center"><font face="Arial">
<textarea rows="5" name="S1" cols="41" style="font-weight: 700">{$resp}</textarea></font></p>
END_HTML;
}
?>