<html>
<head>
<title>Authorize.Net</title>
</head>
<body>
<?php
if (file_exists("../../userhome/\$ettings.php"))
{
        ob_start();
        if (!isset($_GET['path']) and !isset($_REQUEST['path']) and !isset($_POST['path']))
        {
                require_once("../../userhome/\$ettings.php");
                require_once($path["serloc"]."admin/control.php");
        }
        ob_end_clean();
        echo "<link rel=stylesheet type=text/css href=\"".$path["wwwloc"]."userhome/style.css\">";
}
$authnet_values                         = array
(
        "x_login"                       => $x_login,
        "x_tran_key"                    => $x_tran_key,
        "x_delim_data"                  => "TRUE",
        "x_delim_char"                  => "|",
        "x_relay_response"              => "FALSE",
        "x_first_name"                  => $x_first_name,
        "x_last_name"                   => $x_last_name,
        "x_address"                     => $x_address,
        "x_city"                        => $x_city,
        "x_state"                       => $x_state,
        "x_zip"                         => $x_zip,
        "x_country"                     => $x_country,
        "x_phone"                       => $x_phone,
        "x_amount"                      => $x_amount,
        "x_method"                      => "CC",
        "x_type"                        => "AUTH_CAPTURE",
        "x_card_num"                    => $x_card_num,
        "x_exp_date"                    => $x_exp_date,
);
$fields = "";
foreach( $authnet_values as $key => $value ) $fields .= "$key=" . urlencode( $value ) . "&";
$ch = curl_init("https://secure.authorize.net/gateway/transact.dll"); 
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim( $fields, "& " ));
$resp = curl_exec($ch);
curl_close ($ch);
echo "<hr><br><table cellpadding=\"5\" cellspacing=\"0\">";
$text=$resp;
$h=substr_count($text, "|");
$h++;
for($j=1; $j<=$h; $j++)
{
        $p=strpos($text, "|");
        $p++;
        $pstr = substr($text, 0, $p);
        $pstr_trimmed = substr($pstr, 0, -1);
        if($pstr_trimmed=="")
        {
                $pstr_trimmed="NO VALUE RETURNED";
        }
        switch($j)
        {
                case 1: echo "<tr><td>Response Code: </td><td>";
                                $fval = "";
                                if($pstr_trimmed=="1")
                                {
                                        $fval="Approved";
                                }
                                elseif($pstr_trimmed=="2")
                                {
                                        $fval="Declined";
                                }
                                elseif($pstr_trimmed=="3")
                                {
                                        $fval="Error";
                                }
                                echo $fval."<br></td></tr>"; break;
                case 4: echo "<tr><td>Response Reason Text: </td><td>$pstr_trimmed<br></td></tr>"; break;
                case 10: echo "<tr><td>Amount: </td><td>$pstr_trimmed<br></td></tr>"; break;
                case 14: echo "<tr><td>Cardholder First Name: </td><td>$pstr_trimmed<br></td></tr>"; break;
                case 15: echo "<tr><td>Cardholder Last Name: </td><td>$pstr_trimmed<br></td></tr>"; break;
                case 16: echo "<tr><td>Company: </td><td>$pstr_trimmed<br></td></tr>"; break;
                case 17: echo "<tr><td>Billing Address: </td><td>$pstr_trimmed<br></td></tr>"; break;
                case 18: echo "<tr><td>City: </td><td>$pstr_trimmed<br></td></tr>"; break;
                case 19: echo "<tr><td>State: </td><td>$pstr_trimmed<br></td></tr>"; break;
                case 20: echo "<tr><td>ZIP: </td><td>$pstr_trimmed<br></td></tr>"; break;
                case 21: echo "<tr><td>Country: </td><td>$pstr_trimmed<br></td></tr>"; break;
                case 22: echo "<tr><td>Phone: </td><td>$pstr_trimmed<br></td></tr>"; break;
                case 24: echo "<tr><td>E-Mail Address: </td><td>$pstr_trimmed<br></td></tr>"; break;
        }
        $text = substr($text, $p);
}
echo "</table><br><hr>";
?>
</body></html>
