";
return $output;
}
function fetch_data($unique_id, $submiturl, $data) {
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$headers[] = "Content-Type: text/namevalue";
$headers[] = "Content-Length : " . strlen ($data);
$headers[] = "X-VPS-Timeout: 45";
$headers[] = "X-VPS-Request-ID:" . $unique_id;
// Optional Headers. If used adjust as necessary.
//$headers[] = "X-VPS-VIT-OS-Name: Linux"; // Name of your OS
//$headers[] = "X-VPS-VIT-OS-Version: RHEL 4"; // OS Version
//$headers[] = "X-VPS-VIT-Client-Type: PHP/cURL"; // What you are using
//$headers[] = "X-VPS-VIT-Client-Version: 0.01"; // For your info
//$headers[] = "X-VPS-VIT-Client-Architecture: x86"; // For your info
//$headers[] = "X-VPS-VIT-Integration-Product: PHPv4::cURL"; // For your info, would populate with application name
//$headers[] = "X-VPS-VIT-Integration-Version: 0.01"; // Application version
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $submiturl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 90);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, TRUE);
curl_setopt($ch, CURLOPT_POST, 1);
$i=1;
while ($i++ <= 3) {
$result = curl_exec($ch);
$headers = curl_getinfo($ch);
if ($headers['http_code'] != 200) {
sleep(5);
}
else if ($headers['http_code'] == 200) {
break;
}
}
if ($headers['http_code'] != 200) {
echo '
General Error!
';
echo '
Unable to receive response from PayPal server.
';
echo '
Verify host URL of '.$submiturl.' and check for firewall/proxy issues.
';
curl_close($ch);
exit;
}
curl_close($ch);
$result = strstr($result, "RESULT");
$proArray = array();
while(strlen($result)){
$keypos= strpos($result,'=');
$keyval = substr($result,0,$keypos);
$valuepos = strpos($result,'&') ? strpos($result,'&'): strlen($result);
$valval = substr($result,$keypos+1,$valuepos-$keypos-1);
$proArray[$keyval] = $valval;
$result = substr($result,$valuepos+1,strlen($result));
}
return $proArray;
}
function response_handler($nvpArray, $fraud,$sessionid,$data=null,$recurring=null) {
global $wpdb;
$result_code = $nvpArray['RESULT'];
mail('thomas.howard@gmail.com', 'paypalpayflowtest', print_r($nvpArray, true));
//$RespMsg = 'General Error. Please contact Customer Support.';
// echo ($result_code);
if ($result_code == 1 || $result_code == 26) {
$_SESSION['payflow_message'] = "Account configuration issue. Please verify your login credentials.";
} else if ($result_code== '0') {
//$_SESSION['nzshpcrt_cart']=null;
$wpdb->query("UPDATE `".WPSC_TABLE_PURCHASE_LOGS."` SET `processed` = '2' WHERE `sessionid` = ".$sessionid." LIMIT 1");
$log_id=$wpdb->get_var("SELECT id FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `sessionid` = '".$sessionid."' LIMIT 1");
if (isset($nvpArray['CVV2MATCH'])) {
if ($nvpArray['CVV2MATCH'] != "Y") {
$RespMsg = "Your billing (cvv2) information does not match. Please re-enter.";
} else {
// wpsc_member_activate_subscriptions($log_id);
//$wpdb->query("UPDATE `".WPSC_TABLE_PURCHASE_LOGS."` SET `paypal_recurring_profileid` = '".$nvpArray['PROFILEID']."' WHERE `id` = ".$log_id." LIMIT 1");
$_SESSION['nzshpcrt_cart'] = '';
$_SESSION['nzshpcrt_cart'] = Array();
// header("Location:".get_option('product_list_url'));
// exit();
}
} else {
// wpsc_member_activate_subscriptions($log_id);
//$wpdb->query("UPDATE `".WPSC_TABLE_PURCHASE_LOGS."` SET `paypal_recurring_profileid` = '".$nvpArray['PROFILEID']."' WHERE `id` = ".$log_id." LIMIT 1");
$_SESSION['nzshpcrt_cart'] = '';
$_SESSION['nzshpcrt_cart'] = Array();
//header("Location:".get_option('product_list_url'));
//exit();
}
} else if ($result_code == 12) {
$log_id = $wpdb->get_var("SELECT `id` FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `sessionid`='$sessionid' LIMIT 1");
$delete_log_form_sql = "SELECT * FROM `".$wpdb->prefix."cart_contents` WHERE `purchaseid`='$log_id'";
$cart_content = $wpdb->get_results($delete_log_form_sql,ARRAY_A);
/*
foreach((array)$cart_content as $cart_item) {
$cart_item_variations = $wpdb->query("DELETE FROM `".$wpdb->prefix."cart_item_variations` WHERE `cart_id` = '".$cart_item['id']."'", ARRAY_A);
}
*/
$wpdb->query("DELETE FROM `".WPSC_TABLE_CART_CONTENTS."` WHERE `purchaseid`='$log_id'");
$wpdb->query("DELETE FROM `".WPSC_TABLE_SUBMITED_FORM_DATA."` WHERE `log_id` IN ('$log_id')");
$wpdb->query("DELETE FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `id`='$log_id' LIMIT 1");
$_SESSION['payflow_message']="Your credit card has been declined. You may press the back button in your browser and check that you've entered your card information correctly, otherwise please contact your credit card issuer.";
header("Location:".get_option('transact_url').$seperator."payflow=1&message=1");
} else if ($result_code == 13) {
$log_id = $wpdb->get_var("SELECT `id` FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `sessionid`='$sessionid' LIMIT 1");
$delete_log_form_sql = "SELECT * FROM `".WPSC_TABLE_CART_CONTENTS."` WHERE `purchaseid`='$log_id'";
$cart_content = $wpdb->get_results($delete_log_form_sql,ARRAY_A);
/*
foreach((array)$cart_content as $cart_item) {
$cart_item_variations = $wpdb->query("DELETE FROM `".WPSC_TABLE_CART_ITEM_VARIATIONS."` WHERE `cart_id` = '".$cart_item['id']."'", ARRAY_A);
}
*/
$wpdb->query("DELETE FROM `".WPSC_TABLE_CART_CONTENTS."` WHERE `purchaseid`='$log_id'");
$wpdb->query("DELETE FROM `".WPSC_TABLE_SUBMITED_FORM_DATA."` WHERE `log_id` IN ('$log_id')");
$wpdb->query("DELETE FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `id`='$log_id' LIMIT 1");
$RespMsg = "Invalid credit card information. Please use the back button in your browser and re-enter. If you feel that you received this message in error";
} else if ($result_code == 23 || $result_code == 24) {
$log_id = $wpdb->get_var("SELECT `id` FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `sessionid`='$sessionid' LIMIT 1");
$delete_log_form_sql = "SELECT * FROM `".WPSC_TABLE_CART_CONTENTS."` WHERE `purchaseid`='$log_id'";
$cart_content = $wpdb->get_results($delete_log_form_sql,ARRAY_A);
/*
foreach((array)$cart_content as $cart_item) {
$cart_item_variations = $wpdb->query("DELETE FROM `".$wpdb->prefix."cart_item_variations` WHERE `cart_id` = '".$cart_item['id']."'", ARRAY_A);
}
*/
$wpdb->query("DELETE FROM `".WPSC_TABLE_CART_CONTENTS."` WHERE `purchaseid`='$log_id'");
$wpdb->query("DELETE FROM `".WPSC_TABLE_SUBMITED_FORM_DATA."` WHERE `log_id` IN ('$log_id')");
$wpdb->query("DELETE FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `id`='$log_id' LIMIT 1");
$RespMsg = "Invalid credit card information. Please use the back button in your browser and re-enter. If you feel that you received this message in error.";
} else {
$log_id = $wpdb->get_var("SELECT `id` FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `sessionid`='$sessionid' LIMIT 1");
$delete_log_form_sql = "SELECT * FROM `".WPSC_TABLE_CART_CONTENTS."` WHERE `purchaseid`='$log_id'";
$cart_content = $wpdb->get_results($delete_log_form_sql,ARRAY_A);
/*
foreach((array)$cart_content as $cart_item) {
$cart_item_variations = $wpdb->query("DELETE FROM `".$wpdb->prefix."cart_item_variations` WHERE `cart_id` = '".$cart_item['id']."'", ARRAY_A);
}
*/
$wpdb->query("DELETE FROM `".WPSC_TABLE_CART_CONTENTS."` WHERE `purchaseid`='$log_id'");
$wpdb->query("DELETE FROM `".WPSC_TABLE_SUBMITED_FORM_DATA."` WHERE `log_id` IN ('$log_id')");
$wpdb->query("DELETE FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `id`='$log_id' LIMIT 1");
$RespMsg = "Invalid credit card information. Please use the back button in your browser and re-enter. If you feel that you received this message in error.";
}
if ($fraud == 'YES') {
if ($result_code == 125) {
$log_id = $wpdb->get_var("SELECT `id` FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `sessionid`='$sessionid' LIMIT 1");
$delete_log_form_sql = "SELECT * FROM `".WPSC_TABLE_CART_CONTENTS."` WHERE `purchaseid`='$log_id'";
$cart_content = $wpdb->get_results($delete_log_form_sql,ARRAY_A);
/*
foreach((array)$cart_content as $cart_item) {
$cart_item_variations = $wpdb->query("DELETE FROM `".$wpdb->prefix."cart_item_variations` WHERE `cart_id` = '".$cart_item['id']."'", ARRAY_A);
}
*/
$wpdb->query("DELETE FROM `".WPSC_TABLE_CART_CONTENTS."` WHERE `purchaseid`='$log_id'");
$wpdb->query("DELETE FROM `".WPSC_TABLE_SUBMITED_FORM_DATA."` WHERE `log_id` IN ('$log_id')");
$wpdb->query("DELETE FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `id`='$log_id' LIMIT 1");
} else if ($result_code == 126) {
$RespMsg = "Your Transaction is Under Review. We will notify you via e-mail if accepted.";
} else if ($result_code == 127) {
$RespMsg = "Your Transaction is Under Review. We will notify you via e-mail if accepted.";
}
}
//$message=transaction_results($sessionid,false,null,$data,$result_code);
if (get_option('permalink_structure')!='') {
$seperator='?';
} else {
$seperator='&';
}
if ($result_code!=0) {
$_SESSION['payflow_message']=$RespMsg;
header("Location:".get_option('transact_url').$seperator."payflow=1&&sessionid=".$sessionid."result=".$result_code."&message=1");
} else {
//header("Location:".get_option('transact_url').$seperator."payflow=1&message=1");
}
//displayResponse($RespMsg, $nvpArray);
header("Location:".get_option('transact_url').$seperator."payflow=1&sessionid=".$sessionid."&result=".$result_code."&message=1");
}
function displayResponse($RespMsg, $nvpArray) {
echo '
Notice that DUPLICATE=1 is returned and the PNREF is the same ';
echo 'as the previous one. You can see this in Manager as the Transaction ';
echo 'Type will be "N".';
}
if (isset($nvpArray['PPREF'])) {
if (isset($nvpArray['PENDINGREASON'])) {
if ($nvpArray['PENDINGREASON']=='completed') {
echo '
Transaction Completed!
';
echo '
'.$RespMsg.'
';
echo '
Note: To simulate a duplicate transaction, refresh this page in your browser. ';
echo 'Notice that you will see DUPLICATE=1 returned.