get_row("SELECT * FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `sessionid`= ".$sessionid." LIMIT 1",ARRAY_A) ; if ($purchase_log['totalprice']==0) { header("Location: ".get_option('transact_url').$seperator."sessionid=".$sessionid); exit(); } $cart_sql = "SELECT * FROM `".WPSC_TABLE_CART_CONTENTS."` WHERE `purchaseid`='".$purchase_log['id']."'"; $cart = $wpdb->get_results($cart_sql,ARRAY_A) ; //written by allen //exit("
".print_r($cart,true).""); $member_subtype = get_product_meta($cart[0]['prodid'],'is_permenant',true); $status = get_product_meta($cart[0]['prodid'],'is_membership',true); $is_member = $status; $is_perm = $member_subtype; //end of written by allen $transact_url = get_option('transact_url'); // paypal connection variables $data['business'] = get_option('paypal_multiple_business'); $data['return'] = urlencode($transact_url.$seperator."sessionid=".$sessionid."&gateway=paypal"); $data['cancel_return'] = urlencode($transact_url); $data['notify_url'] =urlencode(get_option('siteurl')."/?ipn_request=true"); $data['rm'] = '2'; //data['bn'] = 'Instinct-WP-e-commerce_ShoppingCart_EC'; // look up the currency codes and local price $currency_code = $wpdb->get_results("SELECT `code` FROM `".WPSC_TABLE_CURRENCY_LIST."` WHERE `id`='".(int)get_option('currency_type')."' LIMIT 1",ARRAY_A); $local_currency_code = $currency_code[0]['code']; $paypal_currency_code = get_option('paypal_curcode'); if($paypal_currency_code == '') { $paypal_currency_code = 'US'; } //exit(get_option('currency_type'). " ".$paypal_currency_code); // Stupid paypal only accepts payments in one of 5 currencies. Convert from the currency of the users shopping cart to the curency which the user has specified in their paypal preferences. $curr=new CURRENCYCONVERTER(); $data['currency_code'] = $paypal_currency_code; // $data['lc'] = 'US'; $data['lc'] = $paypal_currency_code; $data['bn'] = 'wp-e-commerce'; $data['no_shipping'] = (int)(bool)get_option('paypal_ship'); if(get_option('address_override') == 1) { $data['address_override'] = '1'; } $data['no_note'] = '1'; switch($paypal_currency_code) { case "JPY": $decimal_places = 0; break; case "HUF": $decimal_places = 0; default: $decimal_places = 2; break; } $i = 1; $all_donations = true; $all_no_shipping = true; $total = $wpsc_cart->calculate_total_price(); $discount = $wpsc_cart->coupons_amount; //exit($discount); if(($discount > 0)) { if($paypal_currency_code != $local_currency_code) { $paypal_currency_productprice = $curr->convert( $wpsc_cart->calculate_total_price(),$paypal_currency_code,$local_currency_code); $paypal_currency_shipping = $curr->convert($local_currency_shipping,$paypal_currency_code,$local_currency_code); $base_shipping = $curr->convert($wpsc_cart->calculate_total_shipping(),$paypal_currency_code, $local_currency_code); $tax_price = $curr->convert($item['tax_charged'],$paypal_currency_code, $local_currency_code); } else { $paypal_currency_productprice = $wpsc_cart->calculate_total_price(); $paypal_currency_shipping = $local_currency_shipping; $base_shipping = $wpsc_cart->calculate_total_shipping(); $tax_price = $item['tax_charged']; } $data['item_name_'.$i] = "Your Shopping Cart"; $data['amount_'.$i] = number_format(sprintf("%01.2f",$paypal_currency_productprice),$decimal_places,'.',''); $data['quantity_'.$i] = 1; // $data['item_number_'.$i] = 0; $data['shipping_'.$i] = 0; $data['shipping2_'.$i] = 0; $data['handling_'.$i] = 0; $i++; } else { foreach((array)$cart as $item) { $product_data = $wpdb->get_results("SELECT * FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `id`='".$item['prodid']."' LIMIT 1",ARRAY_A); $product_data = $product_data[0]; if ((float)$item['price'] == 0 ) { continue; } $variation_count = count($product_variations); $local_currency_productprice = $item['price']; $local_currency_shipping = $item['pnp']; if($paypal_currency_code != $local_currency_code) { $paypal_currency_productprice = $curr->convert($local_currency_productprice,$paypal_currency_code,$local_currency_code); $paypal_currency_shipping = $curr->convert($local_currency_shipping,$paypal_currency_code,$local_currency_code); // exit($paypal_currency_productprice . " " . $paypal_currency_shipping.' '.$local_currency_productprice . " " . $local_currency_code); $base_shipping = $curr->convert($purchase_log['base_shipping'],$paypal_currency_code, $local_currency_code); //exit($paypal_currency_productprice.' Local>'.$local_currency_productprice.' Base shp'.$base_shipping); $tax_price = $curr->convert($item['tax_charged'],$paypal_currency_code, $local_currency_code); } else { $paypal_currency_productprice = $local_currency_productprice; $paypal_currency_shipping = $local_currency_shipping; $base_shipping = $purchase_log['base_shipping']; $tax_price = $item['tax_charged']; } //exit("
".print_r(, true).''); $data['item_name_'.$i] = urlencode(stripslashes($item['name'])); $data['amount_'.$i] = number_format(sprintf("%01.2f", $paypal_currency_productprice),$decimal_places,'.',''); $data['tax_'.$i] = number_format(sprintf("%01.2f",$tax_price),$decimal_places,'.',''); $data['quantity_'.$i] = $item['quantity']; $data['item_number_'.$i] = $product_data['id']; if($item['donation'] !=1) { $all_donations = false; $data['shipping_'.$i] = number_format($paypal_currency_shipping,$decimal_places,'.',''); $data['shipping2_'.$i] = number_format($paypal_currency_shipping,$decimal_places,'.',''); } else { $data['shipping_'.$i] = number_format(0,$decimal_places,'.',''); $data['shipping2_'.$i] = number_format(0,$decimal_places,'.',''); } if($product_data['no_shipping'] != 1) { $all_no_shipping = false; } $data['handling_'.$i] = ''; $i++; } } $data['tax'] = ''; //exit($base_shipping); if(($base_shipping > 0) && ($all_donations == false) && ($all_no_shipping == false)) { $data['handling_cart'] = number_format($base_shipping,$decimal_places,'.',''); } $data['custom'] = ''; $data['invoice'] = $sessionid; // User details if($_POST['collected_data'][get_option('paypal_form_first_name')] != '') { $data['first_name'] = urlencode($_POST['collected_data'][get_option('paypal_form_first_name')]); } if($_POST['collected_data'][get_option('paypal_form_last_name')] != '') { $data['last_name'] = urlencode($_POST['collected_data'][get_option('paypal_form_last_name')]); } if($_POST['collected_data'][get_option('paypal_form_address')] != '') { $address_rows = explode("\n\r",$_POST['collected_data'][get_option('paypal_form_address')]); $data['address1'] = urlencode(str_replace(array("\n", "\r"), '', $address_rows[0])); unset($address_rows[0]); if($address_rows != null) { $data['address2'] = implode(", ",$address_rows); } else { $data['address2'] = ''; } } if($_POST['collected_data'][get_option('paypal_form_city')] != '') { $data['city'] = urlencode($_POST['collected_data'][get_option('paypal_form_city')]); } if($_POST['collected_data'][get_option('paypal_form_state')] != '') { $data['state'] = urlencode($_POST['collected_data'][get_option('paypal_form_state')]); } if($_POST['collected_data'][get_option('paypal_form_country')] != '') { if(is_array($_POST['collected_data'][get_option('paypal_form_country')])) { $country = $_POST['collected_data'][get_option('paypal_form_country')][0]; $id = $_POST['collected_data'][get_option('paypal_form_country')][1]; $state = wpsc_get_state_by_id($id, 'code'); } else { $country = $_POST['collected_data'][get_option('paypal_form_country')]; } $data['country'] = urlencode($country); if($state != ''){ $data['state'] = $state; } } if(is_numeric($_POST['collected_data'][get_option('paypal_form_post_code')])) { $data['zip'] = urlencode($_POST['collected_data'][get_option('paypal_form_post_code')]); } // Change suggested by waxfeet@gmail.com, if email to be sent is not there, dont send an email address $email_data = $wpdb->get_results("SELECT `id`,`type` FROM `".WPSC_TABLE_CHECKOUT_FORMS."` WHERE `type` IN ('email') AND `active` = '1'",ARRAY_A); foreach((array)$email_data as $email) { $data['email'] = $_POST['collected_data'][$email['id']]; } if(($_POST['collected_data'][get_option('email_form_field')] != null) && ($data['email'] == null)) { $data['email'] = $_POST['collected_data'][get_option('email_form_field')]; } $data['upload'] = '1'; $data['cmd'] = "_ext-enter"; $data['redirect_cmd'] = "_cart"; $datacount = count($data); $num = 0; foreach($data as $key=>$value) { $amp = '&'; $num++; if($num == $datacount) { $amp = ''; } //$output .= $key.'='.urlencode($value).$amp; $output .= $key.'='.$value.$amp; } if(get_option('paypal_ipn') == 0) { //ensures that digital downloads still work for people without IPN, less secure, though //$wpdb->query("UPDATE `".WPSC_TABLE_PURCHASE_LOGS."` SET `processed` = '2' WHERE `sessionid` = ".$sessionid." LIMIT 1"); } //written by allen if ($is_member == '1') { $membership_length = get_product_meta($cart[0]['prodid'],'membership_length',true); if ($is_perm == '1'){ $permsub = '&src=1'; } else { $permsub = ''; } $output = 'cmd=_xclick-subscriptions&business='.urlencode($data['business']).'&no_note=1&item_name='.urlencode($data['item_name_1']).'&return='.urlencode($data['return']).'&cancel_return='.urlencode($data['cancel_return']).$permsub.'&a3='.urlencode($data['amount_1']).'&p3='.urlencode($membership_length['length']).'&t3='.urlencode(strtoupper($membership_length['unit'])); } if(defined('WPSC_ADD_DEBUG_PAGE') and (WPSC_ADD_DEBUG_PAGE == true) ) { echo "Test the URL here"; echo "
".print_r($data,true).""; // echo "
".print_r($_POST,true).""; exit(); } header("Location: ".get_option('paypal_multiple_url')."?".$output); exit(); } function nzshpcrt_paypal_ipn() { global $wpdb; // needs to execute on page start // look at page 36 //exit(WPSC_GATEWAY_DEBUG ); if(($_GET['ipn_request'] == 'true') && (get_option('paypal_ipn') == 1)) { // read the post from PayPal system and add 'cmd' $fields = 'cmd=_notify-validate'; $message = ""; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $fields .= "&$key=$value"; } // post back to PayPal system to validate $results = ''; if(function_exists('curl_init')) { $ch=curl_init(); curl_setopt($ch, CURLOPT_URL, get_option('paypal_multiple_url')); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_NOPROGRESS, 1); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); curl_setopt($ch, CURLOPT_TIMEOUT, 120); curl_setopt($ch, CURLOPT_USERAGENT, "WP e-Commerce ".WPSC_PRESENTABLE_VERSION); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $results = curl_exec($ch); curl_close($ch); } else { $replace_strings[0] = 'http://'; $replace_strings[1] = 'https://'; $replace_strings[2] = '/cgi-bin/webscr'; $paypal_url = str_replace($replace_strings, "",get_option('paypal_multiple_url')); $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; $fp = fsockopen($paypal_url, 80, $errno, $errstr, 30); if($fp) { fputs ($fp, $header . $fields); while (!feof($fp)) { $res = fgets ($fp, 1024); $results .= $fields; } fclose ($fp); } } // assign posted variables to local variables $sessionid = $_POST['invoice']; $transaction_id = $_POST['txn_id']; $verification_data['item_name'] = $_POST['item_name']; $verification_data['item_number'] = $_POST['item_number']; $verification_data['payment_status'] = $_POST['payment_status']; $verification_data['payment_amount'] = $_POST['mc_gross']; $verification_data['payment_currency'] = $_POST['mc_currency']; $verification_data['txn_id'] = $_POST['txn_id']; $verification_data['receiver_email'] = $_POST['receiver_email']; $verification_data['payer_email'] = $_POST['payer_email']; if(strcmp ($results, "VERIFIED") == 0){ switch($verification_data['payment_status']) { case 'Processed': // I think this is mostly equivalent to Completed case 'Completed': $wpdb->query("UPDATE `".WPSC_TABLE_PURCHASE_LOGS."` SET `processed` = '2' WHERE `sessionid` = ".$sessionid." LIMIT 1"); transaction_results($sessionid, false, $transaction_id); break; case 'Failed': // if it fails, delete it $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"); break; case 'Pending': // need to wait for "Completed" before processing $sql = "UPDATE `".WPSC_TABLE_PURCHASE_LOGS."` SET `transactid` = '".$transaction_id."', `date` = '".time()."' WHERE `sessionid` = ".$sessionid." LIMIT 1"; $wpdb->query($sql) ; break; default: // if nothing, do nothing, safest course of action here. break; } } else if (strcmp ($results, "INVALID") == 0) { // Its already logged, not much need to do more } /* * Detect use of sandbox mode, if sandbox mode is present, send debugging email. */ if(stristr(get_option('paypal_multiple_url'), "sandbox") || (defined('WPSC_ADD_DEBUG_PAGE') and (WPSC_ADD_DEBUG_PAGE == true)) ) { $message = "This is a debugging message sent because it appears that you are using sandbox mode.\n\rIt is only sent if the paypal URL contains the word \"sandbox\"\n\r\n\r"; $message .= "RESULTS:\n\r".print_r($results,true)."\n\r\n\r"; $message .= "OUR_POST:\n\r".print_r($header . $req,true)."\n\r\n\r"; $message .= "THEIR_POST:\n\r".print_r($_POST,true)."\n\r\n\r"; $message .= "GET:\n\r".print_r($_GET,true)."\n\r\n\r"; $message .= "SERVER:\n\r".print_r($_SERVER,true)."\n\r\n\r"; //$wpdb->query("INSERT INTO `paypal_log` ( `id` , `text` , `date` ) VALUES ( '', '$message', NOW( ) );"); mail(get_option('purch_log_email'), "IPN Data", $message); } exit(); } } function submit_paypal_multiple(){ if($_POST['paypal_multiple_business'] != null) { update_option('paypal_multiple_business', $_POST['paypal_multiple_business']); } if($_POST['paypal_multiple_url'] != null) { update_option('paypal_multiple_url', $_POST['paypal_multiple_url']); } if($_POST['paypal_curcode'] != null) { update_option('paypal_curcode', $_POST['paypal_curcode']); } if($_POST['paypal_curcode'] != null) { update_option('paypal_curcode', $_POST['paypal_curcode']); } if($_POST['paypal_ipn'] != null) { update_option('paypal_ipn', (int)$_POST['paypal_ipn']); } if($_POST['address_override'] != null) { update_option('address_override', (int)$_POST['address_override']); } if($_POST['paypal_ship'] != null) { update_option('paypal_ship', (int)$_POST['paypal_ship']); } foreach((array)$_POST['paypal_form'] as $form => $value) { update_option(('paypal_form_'.$form), $value); } return true; } function form_paypal_multiple() { global $wpdb, $wpsc_gateways; $output = "