function gateway_paystation($seperator, $sessionid) { $price = number_format(nzshpcrt_overall_total_price(wpsc_get_customer_meta('billing_country')), 2, '', ','); $url = "https://www.paystation.co.nz/dart/darthttp.dll?paystation&pi=" . get_option('paystation_id') . "&ms=" . $sessionid . "&am=" . $price . ""; header("Location: {$url}"); exit; }
function gateway_paystation($seperator, $sessionid) { $price = number_format(nzshpcrt_overall_total_price($_SESSION['delivery_country']), 2, '', ','); $url = "https://www.paystation.co.nz/dart/darthttp.dll?paystation&pi=" . get_option('paystation_id') . "&ms=" . $sessionid . "&am=" . $price . ""; $_SESSION['checkoutdata'] = ''; header("Location: {$url}"); exit; }
function gateway_dps($seperator, $sessionid) { $_SESSION['checkoutdata'] = ''; //exit(); //require_once(ABSPATH . 'wp-content/plugins/wp-shopping-cart/gold_cart_files/pxaccess.php'); $PxAccess_Url = get_option('access_url'); $PxAccess_Userid = get_option('access_userid'); $PxAccess_Key = get_option('access_key'); $Mac_Key = get_option('mac_key'); $pxaccess = new PxAccess($PxAccess_Url, $PxAccess_Userid, $PxAccess_Key, $Mac_Key); $request = new PxPayRequest(); $http_host = getenv("HTTP_HOST"); $request_uri = getenv("SCRIPT_NAME"); $server_url = get_option('siteurl'); $script_url = get_option('transact_url'); //Using this code after PHP version 4.3.4 ?page_id=$_GET['page_id'] //echo $script_url . '<br />'; //exit(get_option('checkout_url')); # the following variables are read from the form $Address1 = $_POST['address']; $Address2 = ""; #Set up PxPayRequest Object $request->setAmountInput(nzshpcrt_overall_total_price($_SESSION['delivery_country'])); $request->setTxnData1(get_option('blogname')); # whatever you want to appear, original: $request->setTxnData1("Widget order"); $request->setTxnData2("n/a"); # whatever you want to appear $request->setTxnData3("n/a"); # whatever you want to appear $request->setTxnType("Purchase"); if (get_option('dps_curcode') != '') { $request->setInputCurrency(get_option('dps_curcode')); } else { $request->setInputCurrency("USD"); } $request->setMerchantReference($sessionid); # fill this with your order number $request->setEmailAddress(get_option('purch_log_email')); $request->setUrlFail($script_url); $request->setUrlSuccess($script_url); #Call makeResponse of PxAccess object to obtain the 3-DES encrypted payment request $request_string = $pxaccess->makeRequest($request); header("Location: {$request_string}"); exit; }
function gateway_ideal($seperator, $sessionid) { global $wpdb; $purchase_log_sql = "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= " . $sessionid . " LIMIT 1"; $purchase_log = $wpdb->get_results($purchase_log_sql, ARRAY_A); $submiturl = "https://internetkassa.abnamro.nl/ncol/prod/orderstandard.asp"; $amount = nzshpcrt_overall_total_price(wpsc_get_customer_meta('shipping_country')); if ($_POST['collected_data'][get_option('ideal_form_post_code')] != '') { $postcode = $_POST['collected_data'][get_option('ideal_form_post_code')]; } if ($_POST['collected_data'][get_option('ideal_form_address')] != '') { $address = $_POST['collected_data'][get_option('ideal_form_address')]; } if ($_POST['collected_data'][get_option('ideal_form_email')] != '') { $email = $_POST['collected_data'][get_option('ideal_form_email')]; } if ($_POST['collected_data'][get_option('ideal_form_city')] != '') { $city = $_POST['collected_data'][get_option('ideal_form_city')]; } if ($_POST['collected_data'][get_option('ideal_form_country')] != '') { $country = $_POST['collected_data'][get_option('ideal_form_country')][0]; $country = $wpdb->get_var("SELECT country FROM {$wpdb->prefix}currency_list WHERE isocode='{$country}'"); } if ($_POST['collected_data'][get_option('ideal_form_first_name')] != '') { $name = $_POST['collected_data'][get_option('ideal_form_first_name')] . " " . $_POST['collected_data'][get_option('ideal_form_last_name')]; } ?> <body onload="setTimeout('submit_purchase()',50)"> <script type="text/javascript"> var Amount = <?php echo $amount; ?> ; var PSPID = "<?php echo get_option('ideal_id'); ?> "; var AM; if (isNaN(Amount)) { alert("Amount not a number: " + Amount + " !"); AM = ""; } else { AM = Math.round(parseFloat(Amount)*100); } </script> <form method='post' action='<?php echo $submiturl; ?> ' id='ideal_form' name='ideal_form'> <script type="text/javascript"> document.write("<input type=\"hidden\" NAME=\"PSPID\" value=\"" + PSPID + "\" />"); document.write("<input type=\"hidden\" NAME=\"amount\" value=\"" + AM + "\" />"); </script> <input type="hidden" NAME="orderID" value="<?php echo $purchase_log[0]['id']; ?> " /> <input type="hidden" name="currency" value="<?php echo get_option('ideal_currency'); ?> " /> <input type="hidden" name="language" value="<?php echo get_option('ideal_language'); ?> " /> <input type="hidden" name="accepturl" value="<?php echo get_option('product_list_url'); ?> "> <input type="hidden" name="cancelurl" value="<?php echo get_option('shopping_cart_url'); ?> "> <!--customer information starts--> <input type="hidden" name="CN" value="<?php echo $name; ?> "> <input type="hidden" name="EMAIL" value="<?php echo $email; ?> "> <input type="hidden" name="ownerZIP" value="<?php echo $postcode; ?> "> <input type="hidden" name="owneraddress" value="<?php echo $address; ?> "> <input type="hidden" name="ownercty" value="<?php echo $country; ?> "> <input type="hidden" name="ownertown" value="<?php echo $city; ?> "> <input type="hidden" name="ownertelno" value="<?php echo $phone; ?> "> <!--customer information ends--> <input type="hidden" name="PM" value="iDEAL" /> </form> </body> <?php // $fields = "PSPID=".get_option('ideal_id')."&orderID=".$sessionid."&amount=".$amount."&PM=iDEAL&language=".get_option('ideal_language')."¤cy=".get_option('ideal_currency'); // exit($fields); // header("Location:". $submiturl.$fields); // exit($result); }
function nzshpcrt_submit_checkout() { /* * This is the function used for handling the submitted checkout page */ global $wpdb, $nzshpcrt_gateways, $user_ID; session_start(); if (get_option('permalink_structure') != '') { $seperator = "?"; } else { $seperator = "&"; } if ($_POST['submitwpcheckout'] == 'true') { $check_checkout_page = $wpdb->get_var("SELECT `id` FROM `" . $wpdb->posts . "` WHERE `post_content` LIKE '%[checkout]%' LIMIT 1"); if (is_numeric($check_checkout_page)) { $returnurl = "Location: " . get_option('shopping_cart_url') . $seperator . "total=" . $_GET['total']; } else { $returnurl = "Location: " . get_option('shopping_cart_url'); } $_SESSION['collected_data'] = $_POST['collected_data']; $find_us = $_POST['how_find_us']; if (!($_POST['engrave1'] == '' && $_POST['engrave2'] == '')) { $engrave = $wpdb->escape($_POST['engrave1'] . "," . $_POST['engrave2']); } $any_bad_inputs = false; foreach ($_POST['collected_data'] as $value_id => $value) { $form_sql = "SELECT * FROM `" . $wpdb->prefix . "collect_data_forms` WHERE `id` = '{$value_id}' LIMIT 1"; $form_data = $wpdb->get_results($form_sql, ARRAY_A); $form_data = $form_data[0]; /* if($_POST['collected_data'][get_option('paypal_form_address')] != '') { $map_data['address'] = addslashes($_POST['collected_data'][get_option('paypal_form_address')]); } if($_POST['collected_data'][get_option('paypal_form_city')] != '') { $map_data['city'] = addslashes($_POST['collected_data'][get_option('paypal_form_city')]); } if(preg_match("/^[a-zA-Z]{2}$/",$_SESSION['selected_country'])) { $map_data['country'] = $_SESSION['selected_country']; } $map_data['zipcode']=''; $map_data['radius'] = '50000'; $map_data['state'] = ''; $map_data['submit'] = 'Find Store'; $i=0; if (function_exists('getdistance')) { $maps = getdistance($map_data); while($rows = mysql_fetch_array($maps)) { if ($i==0) { $closest_store = $rows[5]; } $i++; } } //$wpdb->query("UPDATE `".$wpdb->prefix."purchase_logs` SET `closest_store` = '".$closest_store."' WHERE `id` = '".$log_id."' LIMIT 1 ;"); */ $bad_input = false; if ($form_data['mandatory'] == 1 || $form_data['type'] == "coupon") { switch ($form_data['type']) { case "email": if (!preg_match("/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-.]+\\.[a-zA-Z]{2,5}\$/", $value)) { $any_bad_inputs = true; $bad_input = true; } break; case "delivery_country": break; case "country": break; default: if ($value == null) { $any_bad_inputs = true; $bad_input = true; } break; } /* if($form_data['type'] == "coupon") { if($value != '') { // only act if data has been entered $coupon_sql = "SELECT * FROM `".$wpdb->prefix."wpsc_coupon_codes` WHERE `coupon_code` = '".$value."' AND `active` = '1' LIMIT 1"; $coupon_data = $wpdb->get_results($coupon_sql,ARRAY_A); if($coupon_data == null) { $any_bad_inputs = true; $bad_input = true; } } } */ if ($bad_input === true) { switch ($form_data['name']) { case TXT_WPSC_FIRSTNAME: $bad_input_message .= TXT_WPSC_PLEASEENTERAVALIDNAME . ""; break; case TXT_WPSC_LASTNAME: $bad_input_message .= TXT_WPSC_PLEASEENTERAVALIDSURNAME . ""; break; case TXT_WPSC_EMAIL: $bad_input_message .= TXT_WPSC_PLEASEENTERAVALIDEMAILADDRESS . ""; break; case TXT_WPSC_ADDRESS1: case TXT_WPSC_ADDRESS2: $bad_input_message .= TXT_WPSC_PLEASEENTERAVALIDADDRESS . ""; break; case TXT_WPSC_CITY: $bad_input_message .= TXT_WPSC_PLEASEENTERAVALIDCITY . ""; break; case TXT_WPSC_PHONE: $bad_input_message .= TXT_WPSC_PLEASEENTERAVALIDPHONENUMBER . ""; break; case TXT_WPSC_COUNTRY: $bad_input_message .= TXT_WPSC_PLEASESELECTCOUNTRY . ""; break; // case TXT_WPSC_COUPON: // $bad_input_message .= TXT_WPSC_COUPON_DOESNT_EXIST . ""; // break; // case TXT_WPSC_COUPON: // $bad_input_message .= TXT_WPSC_COUPON_DOESNT_EXIST . ""; // break; default: $bad_input_message .= TXT_WPSC_PLEASEENTERAVALID . " " . strtolower($form_data['name']) . "."; break; } $bad_input_message .= "\n\r"; } } } // this here section handles uploading files specified by the user for products $accepted_file_types['mime'][] = 'image/jpeg'; $accepted_file_types['mime'][] = 'image/gif'; $accepted_file_types['mime'][] = 'image/png'; $accepted_file_types['ext'][] = 'jpeg'; $accepted_file_types['ext'][] = 'jpg'; $accepted_file_types['ext'][] = 'gif'; $accepted_file_types['ext'][] = 'png'; foreach ($_SESSION['nzshpcrt_cart'] as $key => $item) { $can_have_uploaded_image = get_product_meta($item->product_id, 'can_have_uploaded_image', true); if ($can_have_uploaded_image[0] == 'on') { $file_data['name'] = basename($_FILES['uploaded_image']['name'][$key]); $file_data['type'] = $_FILES['uploaded_image']['type'][$key]; $file_data['tmp_name'] = $_FILES['uploaded_image']['tmp_name'][$key]; $file_data['error'] = $_FILES['uploaded_image']['error'][$key]; $file_data['size'] = $_FILES['uploaded_image']['size'][$key]; $mime_type_data = wpsc_get_mimetype($file_data['tmp_name'], true); $name_parts = explode('.', basename($file_data['name'])); $extension = array_pop($name_parts); echo $extension . "<br />"; if ($mime_type_data['is_reliable'] == true) { $mime_type = $mime_type_data['mime_type']; } else { // if we can't use what PHP provides us with, we have to trust the user as there aren't really any other choices. $mime_type = $file_data['type']; } if (array_search($mime_type, $accepted_file_types['mime']) !== false && array_search($extension, $accepted_file_types['ext']) !== false) { if (is_file(WPSC_USER_UPLOADS_DIR . $file_data['name'])) { $name_parts = explode('.', basename($file_data['name'])); $extension = array_pop($name_parts); $name_base = implode('.', $name_parts); $file_data['name'] = null; $num = 2; // loop till we find a free file name, first time I get to do a do loop in yonks do { $test_name = "{$name_base}-{$num}.{$extension}"; if (!file_exists(WPSC_USER_UPLOADS_DIR . $test_name)) { $file_data['name'] = $test_name; } $num++; } while ($file_data['name'] == null); } //exit($file_data['name']); if (move_uploaded_file($file_data['tmp_name'], WPSC_USER_UPLOADS_DIR . $file_data['name'])) { $_SESSION['nzshpcrt_cart'][$key]->file_data = array('file_name' => $file_data['name'], 'mime_type' => $mime_type); } } } } //echo("<pre>".print_r($_FILES,true)."</pre>"); //exit("<pre>".print_r($_SESSION['nzshpcrt_cart'],true)."</pre>"); foreach ((array) $_SESSION['nzshpcrt_cart'] as $item) { //exit("------><pre>".print_r((array)$_SESSION['nzshpcrt_cart'],1)."</pre>"); $in_stock = check_in_stock($item->product_id, $item->product_variations, $item->quantity); if (get_option('checkbox_variation') == '1') { $in_stock = true; } if ($in_stock == false) { $bad_input_message .= TXT_WPSC_ITEM_GONE_OUT_OF_STOCK . ""; $bad_input_message .= "\n\r"; $any_bad_inputs = true; break; } } if (get_option('custom_gateway_options') == null) { $bad_input_message .= TXT_WPSC_PROCESSING_PROBLEM . ""; $bad_input_message .= "\n\r"; $any_bad_inputs = true; } list($bad_input_message, $any_bad_inputs) = apply_filters('wpsc_additional_checkout_checks', array($bad_input_message, $any_bad_inputs)); //exit("<pre>".print_r($bad_input_message, true)."</pre>"); if ($any_bad_inputs === true) { $_SESSION['nzshpcrt_checkouterr'] = nl2br($bad_input_message); header($returnurl); exit; } $cart = $_SESSION['nzshpcrt_cart']; $_SESSION['checkoutdata'] = $_POST; if ($_POST['agree'] != 'yes') { $_SESSION['nzshpcrt_checkouterr'] = TXT_WPSC_PLEASEAGREETERMSANDCONDITIONS; header($returnurl); exit; } if ($cart == null) { $_SESSION['nzshpcrt_checkouterr'] = TXT_WPSC_NOTHINGINYOURSHOPPINGCART; header($returnurl); exit; } $sessionid = mt_rand(100, 999) . time(); if (!(is_numeric($user_ID) && $user_ID > 0)) { $user_ID = 'null'; } if (isset($_SESSION['usps_shipping']) && is_numeric($_SESSION['usps_shipping'])) { $base_shipping = $_SESSION['usps_shipping']; } else { $base_shipping = nzshpcrt_determine_base_shipping(0, $_SESSION['delivery_country']); } //clear the coupon //$_SESSION['coupon_num'] = ''; //insert the record into the purchase log table //exit("----->". $_SESSION['delivery_country']); $price = nzshpcrt_overall_total_price($_SESSION['selected_country'], false); $sql = "INSERT INTO `" . $wpdb->prefix . "purchase_logs` ( `totalprice` , `sessionid` , `date`, `billing_country`, `shipping_country`,`base_shipping`,`shipping_region`, `user_ID`, `discount_value`, `discount_data`, `find_us`, `engravetext`, `google_status`) VALUES ( '" . $wpdb->escape($price) . "', '" . $sessionid . "', '" . time() . "', '" . $_SESSION['selected_country'] . "', '" . $_SESSION['delivery_country'] . "', '" . $base_shipping . "','" . $_SESSION['selected_region'] . "' , '" . (int) $user_ID . "' , '" . (double) $_SESSION['wpsc_discount'] . "', '" . $wpdb->escape($_SESSION['coupon_num']) . "', '', '{$engrave}', ' ')"; //exit($sql); $wpdb->query($sql); $email_user_detail = ''; $log_id = $wpdb->get_var("SELECT `id` FROM `" . $wpdb->prefix . "purchase_logs` WHERE `sessionid` IN('" . $sessionid . "') LIMIT 1"); foreach ($_POST['collected_data'] as $value_id => $value) { $wpdb->query("INSERT INTO `" . $wpdb->prefix . "submited_form_data` ( `log_id` , `form_id` , `value` ) VALUES ( '" . $log_id . "', '" . $value_id . "', '" . $value . "');"); } if (function_exists("nzshpcrt_user_log")) { if ($wpdb->get_var("SHOW TABLES LIKE '" . $wpdb->prefix . "usermeta'")) { $saved_data_sql = "SELECT * FROM `" . $wpdb->prefix . "usermeta` WHERE `user_id` = '" . $user_ID . "' AND `meta_key` = 'wpshpcrt_usr_profile';"; $saved_data = $wpdb->get_row($saved_data_sql, ARRAY_A); $new_meta_data = serialize($_POST['collected_data']); if ($saved_data != null) { $wpdb->query("UPDATE `" . $wpdb->prefix . "usermeta` SET `meta_value` = '{$new_meta_data}' WHERE `user_id` IN ('{$user_ID}') AND `meta_key` IN ('wpshpcrt_usr_profile');"); } else { if (is_numeric($user_ID)) { $wpdb->query("INSERT INTO `" . $wpdb->prefix . "usermeta` ( `user_id` , `meta_key` , `meta_value` ) VALUES ( " . $user_ID . ", 'wpshpcrt_usr_profile', '{$new_meta_data}');"); } } } } $downloads = get_option('max_downloads'); $also_bought = array(); $all_donations = true; $all_no_shipping = true; foreach ($cart as $cart_item) { $row = $cart_item->product_id; $quantity = $cart_item->quantity; $variations = $cart_item->product_variations; $extras = $cart_item->extras; // serialize file data if (is_array($cart_item->file_data)) { $file_data = $wpdb->escape(serialize($cart_item->file_data)); } else { $file_data = ''; } /* creates an array of purchased items for logging further on */ if (isset($also_bought[$cart_item->product_id])) { $also_bought[$cart_item->product_id]++; } else { $also_bought[$cart_item->product_id] = 1; } $product_data = $wpdb->get_row("SELECT * FROM `" . $wpdb->prefix . "product_list` WHERE `id` = '{$row}' LIMIT 1", ARRAY_A); if ($product_data['file'] > 0) { $unique_id = sha1(uniqid(mt_rand(), true)); $wpdb->query("INSERT INTO `" . $wpdb->prefix . "download_status` ( `fileid` , `purchid` , `uniqueid`, `downloads` , `active` , `datetime` ) VALUES ( '" . $product_data['file'] . "', '" . $log_id . "', '" . $unique_id . "', '{$downloads}', '0', NOW( ));"); } if ($product_data['donation'] == 1) { $price = $cart_item->donation_price; $gst = 0; $donation = 1; } else { $price = calculate_product_price($row, $variations); if ($product_data['notax'] != 1) { $price = nzshpcrt_calculate_tax($price, $_SESSION['selected_country'], $_SESSION['selected_region']); if (get_option('base_country') == $_SESSION['selected_country']) { $country_data = $wpdb->get_row("SELECT * FROM `" . $wpdb->prefix . "currency_list` WHERE `isocode` IN('" . get_option('base_country') . "') LIMIT 1", ARRAY_A); if ($country_data['has_regions'] == 1) { if (get_option('base_region') == $_SESSION['selected_region']) { $region_data = $wpdb->get_row("SELECT `" . $wpdb->prefix . "region_tax`.* FROM `" . $wpdb->prefix . "region_tax` WHERE `" . $wpdb->prefix . "region_tax`.`country_id` IN('" . $country_data['id'] . "') AND `" . $wpdb->prefix . "region_tax`.`id` IN('" . get_option('base_region') . "') ", ARRAY_A); } $gst = $region_data['tax']; } else { $gst = $country_data['tax']; } } } else { $gst = 0; } $donation = 0; $all_donations = false; } if ($product_data['no_shipping'] != 1) { $all_no_shipping = false; } $country = $wpdb->get_results("SELECT * FROM `" . $wpdb->prefix . "submited_form_data` WHERE `log_id`='" . $log_id . "' AND `form_id` = '" . get_option('country_form_field') . "' LIMIT 1", ARRAY_A); $country = $country[0]['value']; $country_data = $wpdb->get_row("SELECT * FROM `" . $wpdb->prefix . "currency_list` WHERE `isocode` IN('" . get_option('base_country') . "') LIMIT 1", ARRAY_A); $shipping = nzshpcrt_determine_item_shipping($row, 1, $_SESSION['delivery_country']); $cartsql = "INSERT INTO `" . $wpdb->prefix . "cart_contents` ( `prodid` , `purchaseid`, `price`, `pnp`, `gst`, `quantity`, `donation`, `no_shipping`, `files` ) VALUES ('" . $row . "', '" . $log_id . "','" . $price . "','" . $shipping . "', '" . $gst . "','" . $quantity . "', '" . $donation . "', '" . $product_data['no_shipping'] . "', '{$file_data}')"; //exit($cartsql); $wpdb->query($cartsql); $cart_id = $wpdb->get_results("SELECT LAST_INSERT_ID() AS `id` FROM `" . $wpdb->prefix . "product_variations` LIMIT 1", ARRAY_A); $cart_id = $cart_id[0]['id']; $extra_var = ''; if ($variations != null) { $extra_var .= '['; $i = 0; foreach ($variations as $variation => $value) { $wpdb->query("INSERT INTO `" . $wpdb->prefix . "cart_item_variations` ( `cart_id` , `variation_id` , `value_id` ) VALUES ( '" . $cart_id . "', '" . $variation . "', '" . $value . "' );"); $i++; if ($i == 1) { $extra_var .= $value; } else { $extra_var .= "," . $value; } } } $j = 0; $extra_var .= '],['; if ($extras != null) { foreach ($extras as $extra) { $wpdb->query("INSERT INTO `" . $wpdb->prefix . "cart_item_extras` ( `cart_id` , `extra_id`) VALUES ( '" . $cart_id . "', '" . $extra . "');"); $name = $wpdb->get_var("SELECT name FROM " . $wpdb->prefix . "extras_values WHERE id={$extra}"); $j++; if ($j == 1) { $extra_var .= $name; } else { $extra_var .= "," . $name; } } $extra_var .= ']'; } /* if (function_exists('sendemailstostores')) { if ($_POST['pickupordelivery']==1){ $delivery = "Pick Up"; } else { $delivery = "Delivery"; } $chosen_store = $_POST['chosen_store']; $email_sql = "SELECT * FROM locations WHERE storename='".$chosen_store."'"; $email_data = $wpdb->get_results($email_sql,ARRAY_A); $email_message = "Order: ".$product_data['name']." with additional variations : ".$extra_var."<br>"; $email_message .= "<br>"; $email_message .= "Delivery/Pick Up:".$delivery; $email_message .= "<br>"; $email_message .= "Customer detail: <br>"; $email_message .= "Name:". $_POST['collected_data'][get_option('paypal_form_first_name')]." ".$_POST['collected_data'][get_option('paypal_form_last_name')]."<br>"; $email_message .= "Address: ".$map_data['address']."<br>"; $email_message .= "City:".$map_data['city']; sendemailstostores($email_data[0]['url'],'New Order',$email_message); }*/ /* * This code decrements the stock quantitycart_item_variations` */ if (is_array($variations)) { $variation_values = array_values($variations); } //$debug .= "<pre>".print_r($variations,true)."</pre>"; if ($product_data['quantity_limited'] == 1) { switch (count($variation_values)) { case 2: $variation_stock_data = $wpdb->get_row("SELECT * FROM `" . $wpdb->prefix . "variation_priceandstock` WHERE `product_id` = '" . $product_data['id'] . "' AND (`variation_id_1` = '" . $variation_values[0] . "' AND `variation_id_2` = '" . $variation_data[1] . "') OR (`variation_id_1` = '" . $variation_values[1] . "' AND `variation_id_2` = '" . $variation_values[0] . "') LIMIT 1", ARRAY_A); //$debug .= "<pre>".print_r($variation_stock_data,true)."</pre>"; $wpdb->query("UPDATE `" . $wpdb->prefix . "variation_priceandstock` SET `stock` = '" . ($variation_stock_data['stock'] - $quantity) . "' WHERE `id` = '" . $variation_stock_data['id'] . "' LIMIT 1", ARRAY_A); break; case 1: $variation_stock_data = $wpdb->get_row("SELECT * FROM `" . $wpdb->prefix . "variation_priceandstock` WHERE `product_id` = '" . $product_data['id'] . "' AND (`variation_id_1` = '" . $variation_values[0] . "' AND `variation_id_2` = '0') LIMIT 1", ARRAY_A); //$debug .= "<pre>".print_r($variation_stock_data,true)."</pre>"; $wpdb->query("UPDATE `" . $wpdb->prefix . "variation_priceandstock` SET `stock` = '" . ($variation_stock_data['stock'] - $quantity) . "' WHERE `id` = '" . $variation_stock_data['id'] . "' LIMIT 1", ARRAY_A); break; default: /* normal form of decrementing stock */ $wpdb->query("UPDATE `" . $wpdb->prefix . "product_list` SET `quantity`='" . ($product_data['quantity'] - $quantity) . "' WHERE `id`='" . $product_data['id'] . "' LIMIT 1"); break; } } } $unneeded_value = null; //this is only used to store the quantity for the item we are working on, so that we can get the array key $assoc_quantity = null; foreach ($also_bought as $selected_product => $unneeded_value) { foreach ($also_bought as $associated_product => $assoc_quantity) { if ($selected_product == $associated_product) { continue; //don't want to associate products with themselves } $check_assoc = $wpdb->get_var("SELECT `id` FROM `" . $wpdb->prefix . "also_bought_product` WHERE `selected_product` IN('{$selected_product}') AND `associated_product` IN('{$associated_product}') LIMIT 1"); if (isset($check_assoc) && $check_assoc > 0) { $wpdb->query("UPDATE `" . $wpdb->prefix . "also_bought_product` SET `quantity` = (`quantity` + {$assoc_quantity}) WHERE `id` = '{$check_assoc}' LIMIT 1;"); } else { $wpdb->query("INSERT INTO `" . $wpdb->prefix . "also_bought_product` ( `selected_product` , `associated_product` , `quantity` ) VALUES ( '{$selected_product}', '" . $associated_product . "', '" . $assoc_quantity . "' );"); } } } do_action('wpsc_submit_checkout', $log_id); //mail( get_option('purch_log_email'),('debug from '.date("d/m/Y H:i:s")), $debug); $curgateway = get_option('payment_gateway'); // if (get_option('custom_gateway')) { $selected_gateways = get_option('custom_gateway_options'); if (count($selected_gateways) > 1) { if (in_array($_POST['custom_gateway'], (array) $selected_gateways)) { $curgateway = $_POST['custom_gateway']; } else { $curgateway = get_option('payment_gateway'); } } else { if (count($selected_gateways) == 1) { $curgateway = array_pop($selected_gateways); } } //} else { // $curgateway = get_option('payment_gateway'); //} if (get_option('permalink_structure') != '') { $seperator = "?"; } else { $seperator = "&"; } if ($_POST['payment_method'] == 2 && get_option('payment_method') == 2 || get_option('payment_method') == 3) { foreach ($nzshpcrt_gateways as $gateway) { if ($gateway['internalname'] == 'testmode') { $gateway_used = $gateway['internalname']; $wpdb->query("UPDATE `" . $wpdb->prefix . "purchase_logs` SET `gateway` = '" . $gateway_used . "' WHERE `id` = '" . $log_id . "' LIMIT 1 ;"); $gateway['function']($seperator, $sessionid); } } } else { foreach ($nzshpcrt_gateways as $gateway) { if ($gateway['internalname'] == $curgateway) { $gateway_used = $gateway['internalname']; $wpdb->query("UPDATE `" . $wpdb->prefix . "purchase_logs` SET `gateway` = '" . $gateway_used . "' WHERE `id` = '" . $log_id . "' LIMIT 1 ;"); $gateway['function']($seperator, $sessionid); } } } $_SESSION['coupon_num'] = ''; //exit("<pre>".print_r($nzshpcrt_gateways,true)."</pre>"); } }
function gateway_authorize($seperator, $sessionid) { global $wpdb, $wpsc_cart; $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 = "<?xml version='1.0' encoding='utf-8' ?>" . "<ARBCreateSubscriptionRequest xmlns='AnetApi/xml/v1/schema/AnetApiSchema.xsd'>" . "<merchantAuthentication>" . "<name>" . $loginname . "</name>" . "<transactionKey>" . $transactionkey . "</transactionKey>" . "</merchantAuthentication>" . "<refId>Instinct</refId>" . "<subscription>" . "<name>Samplesubscription</name>" . "<paymentSchedule>" . "<interval>" . "<length>" . $length . "</length>" . "<unit>" . $unit . "</unit>" . "</interval>" . "<startDate>" . $startDate . "</startDate>" . "<totalOccurrences>" . $totalOccurrences . "</totalOccurrences>" . "<trialOccurrences>" . $trialOccurrences . "</trialOccurrences>" . "</paymentSchedule>" . "<amount>" . $amount . "</amount>" . "<trialAmount>" . $trialAmount . "</trialAmount>" . "<payment>" . "<creditCard>" . "<cardNumber>" . $cardNumber . "</cardNumber>" . "<expirationDate>" . $expirationDate . "</expirationDate>" . "<cardCode>" . $cardCode . "</cardCode>" . "</creditCard>" . "</payment>" . "<billTo>" . "<firstName>" . $firstName . "</firstName>" . "<lastName>" . $lastName . "</lastName>" . "</billTo>" . "</subscription>" . "</ARBCreateSubscriptionRequest>"; // exit("<pre>".print_r($xml,1)."</pre>"); //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}<br>"; echo " resultCode: {$resultCode} <br>"; echo " code: {$code}<br>"; echo " text: {$text}<br>"; echo " subscriptionId: {$subscriptionId} <br><br>"; } } else { echo "send failed <br>"; } //Dump the response to the screen for debugging //echo "<xmp>$response</xmp>"; //Display response SOAP exit(''); } if ($purchase_log['shipping_country'] != null) { $shipping_country = $purchase_log['shipping_country']; } if ($purchase_log['shipping_region'] != null) { $shipping_region = $purchase_log['shipping_region']; } else { $shipping_region = 0; } if ($purchase_log['billing_country'] != null) { $billing_country = $purchase_log['billing_country']; } if ($purchase_log['billing_region'] != null) { $billing_region = $purchase_log['billing_region']; $billing_region = $wpdb->get_var("SELECT code FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE id='" . $billing_region . "'"); } else { $billing_region = 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($billing_region); $authorize_data['x_Country'] = urlencode($billing_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')); // MY ADDITIONS HERE $authorize_data['x_Description'] = urlencode(get_option('authorize_form_description')); $authorize_data['x_invoice_num'] = $cart[0]['purchaseid']; $authorize_data['x_cust_id'] = $cart[0]['purchaseid']; $setstate = $_POST['collected_data'][get_option('authorize_form_country')][1]; $setstate = $wpdb->get_var("SELECT code FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE id='" . $setstate . "'"); // $authorize_data['x_State'] = urlencode($setstate); $setcountry = $_POST['collected_data'][get_option('authorize_form_country')][0]; // $authorize_data['x_Country'] = urlencode($setcountry); $authorize_data['x_ship_to_First_Name'] = urlencode($_POST['collected_data'][get_option('authorize_form_ship_first_name')]); $authorize_data['x_ship_to_Last_Name'] = urlencode($_POST['collected_data'][get_option('authorize_form_ship_last_name')]); $authorize_data['x_ship_to_Address'] = urlencode($_POST['collected_data'][get_option('authorize_form_ship_address')]); $authorize_data['x_ship_to_City'] = urlencode($_POST['collected_data'][get_option('authorize_form_ship_city')]); $authorize_data['x_ship_to_Zip'] = urlencode($_POST['collected_data'][get_option('authorize_form_ship_post_code')]); $setstate = $_POST['collected_data'][get_option('authorize_form_ship_state')]; $shipping_region = $wpdb->get_var("SELECT code FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE id='" . $shipping_region . "'"); $authorize_data['x_ship_to_State'] = urlencode($shipping_region); // $setcountry=$_POST['collected_data'][get_option('authorize_form_ship_country')]; $authorize_data['x_ship_to_Country'] = urlencode($shipping_country); $authorize_data['x_tax'] = urlencode($wpsc_cart->total_tax); if (wpsc_uses_shipping()) { $authorize_data['x_freight'] = urlencode($wpsc_cart->selected_shipping_method . '<|>' . $wpsc_cart->selected_shipping_option . '<|>' . $wpsc_cart->base_shipping); } // Extra shopping cart data for credit card receipt if (isset($cart[0])) { foreach ($cart as $k => $v) { $authorize_data['item_' . $k . '_name'] = $v['name']; $authorize_data['item_' . $k . '_qty'] = $v['quantity']; $authorize_data['item_' . $k . '_price'] = $v['price']; } } if ($x_Password != '') { $authorize_data['x_Password'] = $x_Password; } # # 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("<pre>".print_r($return,true)."</pre>"); // 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 gateway_bluepay($seperator, $sessionid) { //$transact_url = get_option('transact_url'); //exit("<pre>".print_r($_POST,true)."</pre>"); // if($_SESSION['cart_paid'] == true) // { // header("Location: ".get_option('transact_url').$seperator."sessionid=".$sessionid); // } $x_Login = urlencode(get_option('bluepay_login')); // Replace LOGIN with your login $x_Password = urlencode(get_option("bluepay_password")); // Replace PASS with your password $x_Delim_Data = urlencode("TRUE"); $x_Delim_Char = urlencode(","); $x_Encap_Char = urlencode(""); $x_Type = urlencode("AUTH_CAPTURE"); $x_ADC_Relay_Response = urlencode("FALSE"); if (get_option('bluepay_testmode') == 1) { $x_Test_Request = urlencode("TRUE"); // Remove this line of code when you are ready to go live } # # Customer Information # $x_Method = urlencode("CC"); $x_Amount = urlencode(nzshpcrt_overall_total_price($_SESSION['delivery_country'])); //exit($x_Amount); $x_First_Name = urlencode($_POST['collected_data'][get_option('bluepay_form_first_name')]); $x_Last_Name = urlencode($_POST['collected_data'][get_option('bluepay_form_last_name')]); $x_Card_Num = urlencode($_POST['card_number']); $ExpDate = urlencode($_POST['expiry']['month'] . $_POST['expiry']['year']); $x_Exp_Date = $ExpDate; $x_Address = urlencode($_POST['collected_data'][get_option('bluepay_form_address')]); $x_City = urlencode($_POST['collected_data'][get_option('bluepay_form_city')]); $State = urlencode($_POST['collected_data'][get_option('bluepay_form_state')]); $x_State = wpsc_get_state_by_id($State, 'name'); $x_Zip = urlencode($_POST['collected_data'][get_option('bluepay_form_post_code')]); $x_Email = urlencode($_POST['collected_data'][get_option('bluepay_form_email')]); $x_Email_Customer = urlencode("TRUE"); $x_Merchant_Email = urlencode(get_option('purch_log_email')); // Replace MERCHANT_EMAIL with the merchant email address $x_Card_Code = urlencode($_POST['card_code']); # # Build fields string to post # $fields = "x_Version=3.1&x_Login={$x_Login}&x_Delim_Data={$x_Delim_Data}&x_Delim_Char={$x_Delim_Char}&x_Encap_Char={$x_Encap_Char}"; $fields .= "&x_Type={$x_Type}&x_Test_Request={$x_Test_Request}&x_Method={$x_Method}&x_Amount={$x_Amount}&x_First_Name={$x_First_Name}"; $fields .= "&x_Last_Name={$x_Last_Name}&x_Card_Num={$x_Card_Num}&x_Exp_Date={$x_Exp_Date}&x_Card_Code={$x_Card_Code}&x_Address={$x_Address}&x_City={$x_City}&x_State={$x_State}&x_Zip={$x_Zip}&x_Email={$x_Email}&x_Email_Customer={$x_Email_Customer}&x_Merchant_Email={$x_Merchant_Email}&x_ADC_Relay_Response={$x_ADC_Relay_Response}"; if ($x_Password != '') { $fields .= "&x_Password={$x_Password}"; } //exit($fields); # # Start CURL session # $agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"; $ref = get_option('transact_url'); // Replace this URL with the URL of this script $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://secure.bluepay.com/interfaces/a.net"); 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, $agent); curl_setopt($ch, CURLOPT_REFERER, $ref); 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 // echo "Location: ".$transact_url.$seperator."sessionid=".$sessionid; // exit("<pre>".print_r($return,true)."</pre>"); // 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 = "&"; } //exit("<pre>".print_r($return,true)."</pre>"); switch ($details) { case 1: // Credit Card Successfully Charged //$_SESSION['cart_paid'] = true; 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]; header("Location: " . get_option('checkout_url') . $seperator . "total=" . nzshpcrt_overall_total_price($_POST['collected_data'][get_option('country_form_field')])); exit; break; } }
function gateway_paypal_multiple($seperator, $sessionid) { global $wpdb; $purchase_log_sql = "SELECT * FROM `" . $wpdb->prefix . "purchase_logs` WHERE `sessionid`= " . $sessionid . " LIMIT 1"; $purchase_log = $wpdb->get_results($purchase_log_sql, ARRAY_A); //exit(print_r($purchase_log,1)); $cart_sql = "SELECT * FROM `" . $wpdb->prefix . "cart_contents` WHERE `purchaseid`='" . $purchase_log[0]['id'] . "'"; $cart = $wpdb->get_results($cart_sql, ARRAY_A); //written by allen //exit("<pre>".print_r($cart,true)."</pre>"); $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'; // look up the currency codes and local price $currency_code = $wpdb->get_results("SELECT `code` FROM `" . $wpdb->prefix . "currency_list` WHERE `id`='" . get_option('currency_type') . "' LIMIT 1", ARRAY_A); $local_currency_code = $currency_code[0]['code']; $paypal_currency_code = get_option('paypal_curcode'); //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'] = 'NZ'; $data['bn'] = 'wp_e-commerce'; $data['no_shipping'] = '2'; 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 = nzshpcrt_overall_total_price($_SESSION['selected_country'], false, true); $discount = nzshpcrt_apply_coupon($total, $_SESSION['coupon_num']); if ($discount > 0 && $_SESSION['coupon_num'] != null) { $data['item_name_' . $i] = "Your Shopping Cart"; $data['amount_' . $i] = number_format(sprintf("%01.2f", $discount), $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 ($cart as $item) { $product_data = $wpdb->get_results("SELECT * FROM `" . $wpdb->prefix . "product_list` WHERE `id`='" . $item['prodid'] . "' LIMIT 1", ARRAY_A); $product_data = $product_data[0]; $variation_count = count($product_variations); $variation_sql = "SELECT * FROM `" . $wpdb->prefix . "cart_item_variations` WHERE `cart_id`='" . $item['id'] . "'"; $variation_data = $wpdb->get_results($variation_sql, ARRAY_A); $variation_count = count($variation_data); if ($variation_count >= 1) { $variation_list = " ("; $j = 0; foreach ($variation_data as $variation) { if ($j > 0) { $variation_list .= ", "; } $value_id = $variation['value_id']; $value_data = $wpdb->get_results("SELECT * FROM `" . $wpdb->prefix . "variation_values` WHERE `id`='" . $value_id . "' LIMIT 1", ARRAY_A); $variation_list .= $value_data[0]['name']; $j++; } $variation_list .= ")"; } else { $variation_list = ''; } $local_currency_productprice = $item['price']; $local_currency_shipping = $item['pnp']; //exit($local_currency_productprice . " " . $local_currency_code); 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); } else { $paypal_currency_productprice = $local_currency_productprice; $paypal_currency_shipping = $local_currency_shipping; } //exit("---->".$paypal_currency_shipping); $data['item_name_' . $i] = urlencode(stripslashes($product_data['name']) . $variation_list); $data['amount_' . $i] = number_format(sprintf("%01.2f", $paypal_currency_productprice), $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'] = ''; $base_shipping = $purchase_log[0]['base_shipping']; //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 (preg_match("/^[a-zA-Z]{2}\$/", $_SESSION['selected_country'])) { $data['country'] = $_SESSION['selected_country']; } 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 `" . $wpdb->prefix . "collect_data_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 `".$wpdb->prefix."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'])); } // echo "<a href='".get_option('paypal_multiple_url')."?".$output."'>Test the URL here</a>"; // exit("<pre>".print_r($data,true)."</pre>"); header("Location: " . get_option('paypal_multiple_url') . "?" . $output); exit; }
echo " <td colspan='2' style='vertical-align: middle;'>\n\r"; if ($discount > 0) { echo "" . nzshpcrt_currency_display($discount, 1) . ""; } else { echo "<font color='red'>" . TXT_WPSC_INVALID_COUPON . "</font>"; $_SESSION['coupon_num'] = ''; } echo " </td>\n\r"; echo "</tr>\n\r"; } echo "<tr class='total_price'>\n\r"; echo " <td colspan='2'>\n\r"; echo "" . TXT_WPSC_TOTALPRICE . ":"; echo " </td>\n\r"; echo " <td colspan='2' id='checkout_total' style='vertical-align: middle;'>\n\r"; echo nzshpcrt_overall_total_price($_SESSION['selected_country'], true, false, $total); echo " </td>\n\r"; echo "</tr>\n\r"; echo "</table>"; if ($_POST['coupon_num']) { $_SESSION['nzshpcrt_totalprice'] = $total_after_discount; } else { $_SESSION['nzshpcrt_totalprice'] = $total; } if (get_option('payment_gateway') == 'google') { $google_cart = unserialize($_SESSION['google_shopping_cart']); if ($_SESSION['coupon_num']) { $overall_total = nzshpcrt_overall_total_price_numeric(null, true); $discount = $overall_total - nzshpcrt_apply_coupon($overall_total, $_SESSION['coupon_num']); $total_after_discount = $overall_total - $discount; $_SESSION['wpsc_discount'] = $discount;
function nzshpcrt_shopping_basket_internals($cart, $quantity_limit = false, $no_title = false) { global $wpdb; if (get_option('permalink_structure') != '') { $seperator = "?"; } else { $seperator = "&"; } if (get_option('show_sliding_cart') == 1) { if (is_numeric($_SESSION['slider_state'])) { if ($_SESSION['slider_state'] == 0) { $collapser_image = 'plus.png'; } else { $collapser_image = 'minus.png'; } $fancy_collapser = "<a href='#' onclick='return shopping_cart_collapser()' id='fancy_collapser_link'><img src='" . WPSC_URL . "/images/{$collapser_image}' title='' alt='' id='fancy_collapser' /></a>"; } else { if ($_SESSION['nzshpcrt_cart'] == null) { $collapser_image = 'plus.png'; } else { $collapser_image = 'minus.png'; } $fancy_collapser = "<a href='#' onclick='return shopping_cart_collapser()' id='fancy_collapser_link'><img src='" . WPSC_URL . "/images/{$collapser_image}' title='' alt='' id='fancy_collapser' /></a>"; } } else { $fancy_collapser = ""; } $current_url = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; if (get_option('cart_location') == 4) { $no_title = true; } switch (get_option('cart_location')) { case 1: if ($no_title !== true) { $output .= "<h2>" . TXT_WPSC_SHOPPINGCART . " {$fancy_collapser}</h2>"; $output .= "<span id='alt_loadingindicator'><img id='alt_loadingimage' src='" . WPSC_URL . "/images/indicator.gif' alt='Loading' title='Loading' /> " . TXT_WPSC_UDPATING . "...</span></strong><br />"; } $spacing = ""; break; case 3: if ($no_title !== true) { $output .= "<strong class='cart_title'>" . TXT_WPSC_SHOPPINGCART . " {$fancy_collapser}</strong>"; } //$output .= "<a href='#' onclick='return shopping_cart_collapser()' class='cart_title' id='fancy_collapser_link'>".TXT_WPSC_SHOPPINGCART." </a>"; break; case 4: if ($no_title !== true) { if (is_array($GLOBALS['registered_sidebars'])) { $sidebar_args = end($GLOBALS['registered_sidebars']); } else { $sidebar_args['before_title'] = "<h2>"; $sidebar_args['after_title'] = "</h2>"; } $output .= $sidebar_args['before_title'] . TXT_WPSC_SHOPPINGCART . " {$fancy_collapser}" . $sidebar_args['after_title']; } break; default: if ($no_title !== true) { //$output .= "<strong class='cart_title'>".TXT_WPSC_SHOPPINGCART." $fancy_collapser</strong>"; } break; } $cart_count = 0; foreach ((array) $cart as $item) { $cart_count += $item->quantity; } $output .= "<div id='sliding_cart'>"; if ($cart != null) { if ($quantity_limit == true || $_SESSION['out_of_stock'] == true) { $output .= "<span class='items'><span class='numberitems'>" . TXT_WPSC_NUMBEROFITEMS . ": </span><span class='cartcount'>" . $cart_count . "</span></span>"; $output .= "<span class='nomore'>" . TXT_WPSC_NOMOREAVAILABLE . "</span>"; $_SESSION['out_of_stock'] = false; } else { $output .= "<span class='items'><span class='numberitems'>" . TXT_WPSC_NUMBEROFITEMS . ": </span><span class='cartcount'>" . $cart_count . "</span></span>"; } $output .= "<table class='shoppingcart'>\n\r"; $output .= "<tr><th id='thproduct'>" . TXT_WPSC_PRODUCT . "</th><th id='thqty'>" . TXT_WPSC_QUANTITY_SHORT . "</th><th id='thprice'>" . TXT_WPSC_PRICE . "</th></tr>\n\r"; $all_donations = true; $all_no_shipping = true; $tax = 0; //written by allen $merchant_id = get_option('google_id'); // Your Merchant ID $merchant_key = get_option('google_key'); // Your Merchant Key $server_type = get_option('google_server_type'); $currency = get_option('google_cur'); if (get_option('payment_gateway') == 'google') { $google_cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency); } foreach ($cart as $cart_item) { $product_id = $cart_item->product_id; $quantity = $cart_item->quantity; //echo("<pre>".print_r($cart_item->product_variations,true)."</pre>"); $product = $wpdb->get_row("SELECT * FROM `" . $wpdb->prefix . "product_list` WHERE `id` = '{$product_id}' LIMIT 1", ARRAY_A); if ($product['donation'] == 1) { if (get_option('payment_gateway') == 'google') { $google_unit_price = $cart_item->donation_price; } $price = $quantity * $cart_item->donation_price; } else { if (get_option('payment_gateway') == 'google') { $google_unit_price = calculate_product_price($product_id, $cart_item->product_variations, 'stay', $cart_item->extras); } $price = $quantity * calculate_product_price($product_id, $cart_item->product_variations, 'stay', $cart_item->extras); if ($product['notax'] != 1) { $tax += nzshpcrt_calculate_tax($price, $_SESSION['selected_country'], $_SESSION['selected_region']) - $price; } $all_donations = false; } if ($product['no_shipping'] != 1) { $all_no_shipping = false; } if ($_SESSION['delivery_country'] != null) { $total_shipping += nzshpcrt_determine_item_shipping($product['id'], $quantity, $_SESSION['delivery_country']); } $total += $price; //exit(utf8_encode('™')); $product['name'] = str_replace("™", "™", $product['name']); $product['description'] = str_replace("™", "™", $product['description']); if (get_option('payment_gateway') == 'google') { $google_item = new GoogleItem(utf8_decode($product['name']), utf8_decode($product['description']), $quantity, $google_unit_price); $google_item->SetMerchantItemId($product['id']); $google_cart->SetMerchantCalculations(get_option('siteurl'), "false", "false", "false"); //echo serialize($cart_item->product_variations); $google_item->SetMerchantPrivateItemData("some variations"); $google_cart->AddItem($google_item); } $output .= "<tr>"; if (get_option("hide_name_link") == '1') { $output .= "<td class='tdproduct'>" . $product['name'] . "</td>"; } else { $output .= "<td><a href='" . wpsc_product_url($product['id']) . "' >" . stripslashes($product['name']) . "</a></td>"; } $output .= "<td class='tdqty'>" . $quantity . "</td>"; $output .= "<td class='tdprice'>" . nzshpcrt_currency_display($price, 1) . "</td>"; $output .= "</tr>\n\r"; } //google checkout stuff. // if (get_option('payment_gateway') == 'google') { // $google_shipping = new GoogleFlatRateShipping("Flat Rate Shipping", $total_shipping); // $Gfilter = new GoogleShippingFilters(); // $google_checkout_shipping=get_option("google_shipping_country"); // $google_shipping_country_ids = implode(",",(array)$google_checkout_shipping); // if($google_shipping_country_ids != null) { // $google_shipping_country = $wpdb->get_var("SELECT isocode FROM ".$wpdb->prefix."currency_list WHERE id IN (".$google_shipping_country_ids.")"); // } // $Gfilter->AddAllowedPostalArea($google_shipping_country); // $google_shipping->AddShippingRestrictions($Gfilter); // $google_cart->AddShipping($google_shipping); // // if ($_SESSION['selected_country']=='US'){ // $tax_rule = new GoogleDefaultTaxRule(0.05); // $state_name = $wpdb->get_var("SELECT name FROM ".$wpdb->prefix."region_tax WHERE id='".$_SESSION['selected_region']."'"); // $tax_rule->SetStateAreas(array($state_name)); // $tax_rule->AddPostalArea($google_shipping_country); // $google_cart->AddDefaultTaxRules($tax_rule); // } // } //end of google checkout. $output .= "</table>"; if ($_SESSION['delivery_country'] != null) { $total_shipping = nzshpcrt_determine_base_shipping($total_shipping, $_SESSION['delivery_country']); $output .= "<span class='subtotal'><span class='subtotalhead'>" . TXT_WPSC_SUBTOTAL . ":</span>" . nzshpcrt_currency_display($total, 1) . "</span>"; if (get_option('do_not_use_shipping') != 1 && $all_donations == false && $all_no_shipping == false) { $output .= "<span class='postage'><span class='postagehead'>" . TXT_WPSC_POSTAGE . ":</span>" . nzshpcrt_currency_display($total_shipping, 1) . "</span> "; } if ($tax > 0) { $output .= "<span class='tax'><span class='taxhead'>" . TXT_WPSC_TAX . ":</span> " . nzshpcrt_currency_display($tax, 1) . "</span>"; } if ($_SESSION['coupon_num']) { $overall_total = nzshpcrt_overall_total_price_numeric($_SESSION['selected_country'], true); $discount = $overall_total - nzshpcrt_apply_coupon($overall_total, $_SESSION['coupon_num']); $total_after_discount = $overall_total - $discount; $_SESSION['wpsc_discount'] = $discount; } else { $_SESSION['wpsc_discount'] = 0; } if ($discount > 0) { $output .= "<span class='discount'><span class='discounthead'>" . TXT_WPSC_DISCOUNT . ":</span>" . nzshpcrt_currency_display($discount, 1) . "</span>"; } $output .= "<span class='total'><span class='totalhead'>" . TXT_WPSC_TOTAL . ":</span>" . nzshpcrt_overall_total_price($_SESSION['delivery_country'], true) . "</span>"; } else { if ($discount > 0) { $output .= "<span class='discount'><span class='discounthead'>" . TXT_WPSC_DISCOUNT . ":</span>" . nzshpcrt_currency_display($discount, 1) . "</span>"; } $output .= "<span class='total'><span class='totalhead'>" . TXT_WPSC_TOTAL . ":</span>" . nzshpcrt_overall_total_price($_SESSION['delivery_country'], true) . "</span>"; } if (get_option('permalink_structure') != '') { $seperator = "?"; } else { $seperator = "&"; } if ($discount > 0) { if (get_option('payment_gateway') == 'google') { $google_item = new GoogleItem(utf8_decode("Coupon Code: '" . $_SESSION['coupon_num'] . "'"), utf8_decode("A coupon redeem"), 1, -$discount); $google_item->SetMerchantPrivateItemData("Coupon Deduction"); $google_cart->AddItem($google_item); } } if (get_option('payment_gateway') == 'google') { if (!$total_shipping) { $total_shipping = 0; } $pnp = $wpdb->get_var("SELECT SUM(pnp) FROM " . $wpdb->prefix . "product_list WHERE id IN (" . $google_product_id . ")"); $local_shipping_price = nzshpcrt_determine_base_shipping($total_shipping, get_option('base_country')); $google_local_shipping = new GoogleFlatRateShipping("Local Shipping", $local_shipping_price + $pnp); $international_shipping_price = nzshpcrt_determine_base_shipping($total_shipping, get_option('base_country') . "-"); $google_international_shipping = new GoogleFlatRateShipping("International Shipping", $international_shipping_price + $pnp); $Gfilter2 = new GoogleShippingFilters(); $Gfilter = new GoogleShippingFilters(); $google_checkout_shipping = get_option("google_shipping_country"); if (!empty($google_checkout_shipping)) { $google_shipping_country_ids = implode(",", (array) $google_checkout_shipping); $google_shipping_country = $wpdb->get_results("SELECT isocode FROM " . $wpdb->prefix . "currency_list WHERE id IN (" . $google_shipping_country_ids . ")", ARRAY_A); } //exit(print_r($google_shipping_country,1)); foreach ((array) $google_shipping_country as $country) { $Gfilter->AddAllowedPostalArea($country['isocode']); $Gfilter2->AddAllowedPostalArea($country['isocode']); $Gfilter2->AddExcludedPostalArea(get_option('base_country')); if ($country['isocode'] != get_option('base_country')) { $Gfilter->AddExcludedPostalArea($country['isocode']); } } $google_local_shipping->AddShippingRestrictions($Gfilter); $google_international_shipping->AddShippingRestrictions($Gfilter2); $google_cart->AddShipping($google_local_shipping); $google_cart->AddShipping($google_international_shipping); $local_tax = $wpdb->get_var("SELECT tax from " . $wpdb->prefix . "currency_list WHERE isocode='" . get_option('base_country') . "'"); //exit($local_tax); $tax_rule = new GoogleDefaultTaxRule($local_tax / 100); if ($_SESSION['selected_country'] == 'US' && get_option('base_country') == 'US') { $state_name = $wpdb->get_var("SELECT name FROM " . $wpdb->prefix . "region_tax WHERE id='" . $_SESSION['selected_region'] . "'"); //foreach ($state_name as $state) $tax_rule->SetStateAreas(array($state_name)); } else { $tax_rule->AddPostalArea(get_option('base_country')); } $google_cart->AddDefaultTaxRules($tax_rule); $alter_tax_rule = new GoogleDefaultTaxRule(0.0); foreach ((array) $google_shipping_country as $country) { if (get_option('base_country') != $country['isocode']) { $alter_tax_rule->AddPostalArea($country['isocode']); } } if ($alter_tax_rule != '') { $google_cart->AddDefaultTaxRules($alter_tax_rule); } } $output .= "<span class='emptycart'><a href='" . get_option('product_list_url') . $seperator . "category=" . $_GET['category'] . "&cart=empty' onclick='emptycart();return false;'>" . TXT_WPSC_EMPTYYOURCART . "</a><span>"; $output .= "<span class='gocheckout'><a href='" . get_option('shopping_cart_url') . "'>" . TXT_WPSC_GOTOCHECKOUT . "</a></span>"; if (get_option('payment_gateway') == 'google') { if (get_option('google_button_size') == '0') { $google_button_size = 'BIG'; } elseif (get_option('google_button_size') == '1') { $google_button_size = 'MEDIUM'; } elseif (get_option('google_button_size') == '2') { $google_button_size = 'SMALL'; } $google_cart->SetMerchantCalculations(get_option('siteurl'), "false", "false"); $google_cart->SetRequestBuyerPhone("true"); $google_session = md5(time()); $_SESSION['google_session'] = $google_session; if (!preg_match("/\\?/", get_option('product_list_url'))) { $seperator = "?"; } else { $seperator = "&"; } $continueshoppingurl = get_option('product_list_url') . $seperator . "action=bfg&session=" . $google_session; $google_cart->SetContinueShoppingUrl($continueshoppingurl); $google_cart->SetEditCartUrl(get_option('shopping_cart_url')); $_SESSION['google_shopping_cart'] = serialize($google_cart); // $output .= $google_cart->getXML(); $output .= "<br>" . $google_cart->CheckoutButtonCode($google_button_size); } //$output .= "<a href='".get_option('product_list_url')."'>".TXT_WPSC_CONTINUESHOPPING."</a>"; } else { $output .= $spacing; $output .= "<p class='empty'>" . TXT_WPSC_YOURSHOPPINGCARTISEMPTY . ".</p>"; $output .= "<p class='visitshop'><a href='" . get_option('product_list_url') . "'>" . TXT_WPSC_VISITTHESHOP . "</a></p>"; } $output .= "</div>"; return $output; }