Credit Card Number *

%s

Credit Card Expiry * /

%s

CVV

%s

"; } function gateway_authorize($seperator, $sessionid) { global $wpdb; $purchase_log_sql = "SELECT * FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `sessionid`= ".$sessionid." LIMIT 1"; $purchase_log = $wpdb->get_row($purchase_log_sql,ARRAY_A); $cart_sql = "SELECT * FROM `".WPSC_TABLE_CART_CONTENTS."` WHERE `purchaseid`='".$purchase_log['id']."'"; $cart = $wpdb->get_results($cart_sql,ARRAY_A); $prodid=$cart[0]['prodid']; $product_sql = "SELECT * FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `id`='".$prodid."'"; $product_data = $wpdb->get_results($product_sql,ARRAY_A); $status = get_product_meta($prodid,'is_membership',true); $free_trial = get_product_meta($prodid,'free_trial',true); if (($status[0] == 1) && function_exists('wpsc_members_init')) { $membership_length = get_product_meta($prodid,'membership_length',true); $membership_length = $membership_length[0]; $length = $membership_length['length']; $unit = $membership_length['unit']; if ($unit == 'd') { $unit='days'; } elseif ($unit == 'm') { $unit='months'; } $amount = nzshpcrt_overall_total_price($_SESSION['selected_country']); $loginname = get_option('authorize_login'); $transactionkey = get_option("authorize_password"); $firstName = $_POST['collected_data'][get_option('authorize_form_first_name')]; $lastName = $_POST['collected_data'][get_option('authorize_form_last_name')]; $cardNumber = $_POST['card_number']; $expirationDate ="20" . $_POST['expiry']['year']."-".$_POST['expiry']['month'] ; $cardCode = $_POST['card_code']; $startDate=date('Y-m-d'); $totalOccurrences = 99; $trialOccurrences =1; $amount = $product_data[0]['price']; $trialAmount = 0; $xml = "". "". "". "" . $loginname . "". "" . $transactionkey . "". "". "Instinct". "". "Samplesubscription". "". "". "". $length ."". "". $unit ."". "". "" . $startDate . "". "". $totalOccurrences . "". "". $trialOccurrences . "". "". "". $amount ."". "" . $trialAmount . "". "". "". "" . $cardNumber . "". "" . $expirationDate . "". "" . $cardCode . "". "". "". "". "". $firstName . "". "" . $lastName . "". "". "". ""; // exit("
".print_r($xml,1)."
"); //Send the XML via curl $response = send_request_via_curl($host,$path,$xml); //If curl is unavilable you can try using fsockopen /* $response = send_request_via_fsockopen($host,$path,$content); */ //If the connection and send worked $response holds the return from Authorize.Net if ($response) { list ($refId, $resultCode, $code, $text, $subscriptionId) =parse_return($response); if ($code == 'I00001') { $wpdb->query("UPDATE `".WPSC_TABLE_PURCHASE_LOGS."` SET `processed` = '2' WHERE `sessionid` = ".$sessionid." LIMIT 1"); $results=$wpdb->get_results("select * from `".WPSC_TABLE_LOGGED_SUBSCRIPTIONS."` where cart_id=".$cart[0]['id']."",ARRAY_A); $sub_id=$results[0]['id']; wpsc_member_activate_subscriptions($sub_id); header("Location: ".get_option('transact_url').$seperator."sessionid=".$sessionid); } else { echo " refId: $refId
"; echo " resultCode: $resultCode
"; echo " code: $code
"; echo " text: $text
"; echo " subscriptionId: $subscriptionId

"; } } else { echo "send failed
"; } //Dump the response to the screen for debugging //echo "$response"; //Display response SOAP exit(''); } if($selected_region = $purchase_log['shipping_country'] != null) { $selected_country = $purchase_log['shipping_country']; $selected_region = $purchase_log['shipping_region']; } else { $selected_country = $purchase_log['billing_country']; $selected_region = $purchase_log['billing_region']; } $region_list = $wpdb->get_row("SELECT `".WPSC_TABLE_REGION_TAX."`.* FROM `".WPSC_TABLE_REGION_TAX."`, `".WPSC_TABLE_CURRENCY_LIST."` WHERE `".WPSC_TABLE_CURRENCY_LIST."`.`isocode` IN('".$selected_country."') AND `".WPSC_TABLE_CURRENCY_LIST."`.`id` = `".WPSC_TABLE_REGION_TAX."`.`country_id` AND `".WPSC_TABLE_REGION_TAX."`.`id` IN ('".$selected_region."') LIMIT 1",ARRAY_A) ; if($region_list != null) { $selected_region_code = $region_list['code']; } else { $selected_region_code = 0; } $authorize_data = array(); $authorize_data['x_Version'] = "3.1"; $authorize_data['x_Login'] = urlencode(get_option('authorize_login')); $authorize_data['x_Password'] = urlencode(get_option("authorize_password")); $authorize_data['x_Delim_Data'] = urlencode("TRUE"); $authorize_data['x_Delim_Char'] = urlencode(","); $authorize_data['x_Encap_Char'] = urlencode(""); $authorize_data['x_Type'] = urlencode("AUTH_CAPTURE"); $authorize_data['x_ADC_Relay_Response'] = urlencode("FALSE"); if(get_option('authorize_testmode') == 1) { $authorize_data['x_Test_Request'] = urlencode("TRUE"); } $authorize_data['x_Method'] = urlencode("CC"); $authorize_data['x_Amount'] = number_format(nzshpcrt_overall_total_price($_SESSION['delivery_country'],false,false),2); $authorize_data['x_First_Name'] = urlencode($_POST['collected_data'][get_option('authorize_form_first_name')]); $authorize_data['x_Last_Name'] = urlencode($_POST['collected_data'][get_option('authorize_form_last_name')]); $authorize_data['x_Card_Num'] = urlencode($_POST['card_number']); $authorize_data['x_Exp_Date'] = urlencode(($_POST['expiry']['month'] . $_POST['expiry']['year'])); $authorize_data['x_Card_Code'] = urlencode($_POST['card_code']); $authorize_data['x_Address'] = urlencode($_POST['collected_data'][get_option('authorize_form_address')]); $authorize_data['x_City'] = urlencode($_POST['collected_data'][get_option('authorize_form_city')]); $authorize_data['x_Zip'] = urlencode($_POST['collected_data'][get_option('authorize_form_post_code')]); $authorize_data['x_State'] = urlencode($selected_region_code); $authorize_data['x_Country'] = urlencode($selected_country); $authorize_data['x_Phone'] = urlencode($_POST['collected_data'][get_option('authorize_form_phone')]); $authorize_data['x_Email'] = urlencode($_POST['collected_data'][get_option('authorize_form_email')]); $authorize_data['x_Email_Customer'] = urlencode("TRUE"); $authorize_data['x_Merchant_Email'] = urlencode(get_option('purch_log_email')); if($x_Password!='') { $authorize_data['x_Password']=$x_Password; } //exit("
".print_r($authorize_data,true)."
"); # # 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("
".print_r($_POST,true)."
"); update_option('authorize_login', $_POST['authorize_login']); update_option('authorize_password', $_POST['authorize_password']); if($_POST['authorize_testmode'] == 1) { update_option('authorize_testmode', 1); } else { update_option('authorize_testmode', 0); } foreach((array)$_POST['authorize_form'] as $form => $value) { update_option(('authorize_form_'.$form), $value); } return true; } function form_authorize() { $output .= " Authorize API Login ID Authorize Transaction Key Test Mode \n"; if(get_option('authorize_testmode') == 1) { $output .= "\n"; } else { $output .= "\n"; } $output .= "
Forms Sent to Gateway First Name Field Last Name Field Address Field City Field State Field Postal code/Zip code Field Email Field Phone Number Field "; return $output; } function send_request_via_curl($host,$path,$content) { if (get_option('authorize_testmode')=='1'){ $host = "apitest.authorize.net"; } else { $host = "api.authorize.net"; } $path = "/xml/v1/request.api"; $posturl = "https://" . $host . $path; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $posturl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $content); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); $response = curl_exec($ch); return $response; } //Function to parse Authorize.net response function parse_return($content) { $refId = substring_between($content,'',''); $resultCode = substring_between($content,'',''); $code = substring_between($content,'',''); $text = substring_between($content,'',''); $subscriptionId = substring_between($content,'',''); return array ($refId, $resultCode, $code, $text, $subscriptionId); } //Helper function for parsing response function substring_between($haystack,$start,$end) { if (strpos($haystack,$start) === false || strpos($haystack,$end) === false) { return false; } else{ $start_position = strpos($haystack,$start)+strlen($start); $end_position = strpos($haystack,$end); return substr($haystack,$start_position,$end_position-$start_position); } } function authorize_response(){ global $wpdb; // mail('hanzhimeng@gmail.com','',print_r($_SERVER,1)); } add_action('init', 'authorize_response'); ?>