");
#
# Build fields string to post, nicer than the old code
#
$num = 0;
foreach($authorize_data as $key => $value) {
if($num > 0) {
$fields .= "&";
}
$fields .= $key."=".$value;
$num++;
}
#
# Start CURL session
#
$user_agent = "WP eCommerce plugin for Wordpress";
$referrer = get_option('transact_url');
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, "https://secure.authorize.net/gateway/transact.dll");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_NOPROGRESS, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_REFERER, $referrer);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$buffer = curl_exec($ch);
curl_close($ch);
// This section of the code is the change from Version 1.
// This allows this script to process all information provided by Authorize.net...
// and not just whether if the transaction was successful or not
// Provided in the true spirit of giving by Chuck Carpenter (Chuck@MLSphotos.com)
// Be sure to email him and tell him how much you appreciate his efforts for PHP coders everywhere
$return = preg_split("/[,]+/", "$buffer"); // Splits out the buffer return into an array so . . .
$details = $return[0]; // This can grab the Transaction ID at position 1 in the array
$wpdb->query("UPDATE `".WPSC_TABLE_PURCHASE_LOGS."` SET `transactid` = '".$wpdb->escape($return[18])."' WHERE `sessionid` = ".$sessionid." LIMIT 1");
// echo "Location: ".$transact_url.$seperator."sessionid=".$sessionid;
// exit("
".print_r($return,true)."
");
// Change the number to grab additional information. Consult the AIM guidelines to see what information is provided in each position.
// For instance, to get the Transaction ID from the returned information (in position 7)..
// Simply add the following:
// $x_trans_id = $return[6];
// You may then use the switch statement (or other process) to process the information provided
// Example below is to see if the transaction was charged successfully
if(get_option('permalink_structure') != '')
{
$seperator ="?";
}
else
{
$seperator ="&";
}
switch ($details)
{
case 1: // Credit Card Successfully Charged
$processing_stage = $wpdb->get_var("SELECT `processed` FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `sessionid` = ".$sessionid." LIMIT 1");
if($processing_stage < 2) {
$wpdb->query("UPDATE `".WPSC_TABLE_PURCHASE_LOGS."` SET `processed` = '2' WHERE `sessionid` = ".$sessionid." LIMIT 1");
}
header("Location: ".get_option('transact_url').$seperator."sessionid=".$sessionid);
exit();
break;
default: // Credit Card Not Successfully Charged
$_SESSION['wpsc_checkout_misc_error_messages'][] = "Credit Card Processing Error: ".$return[3];//. " ". print_r($return,true)
header("Location: ".get_option('shopping_cart_url').$seperator."total=".nzshpcrt_overall_total_price($_POST['collected_data'][get_option('country_form_field')]));
exit();
break;
}
}
function submit_authorize()
{
//exit("