function convert($amt) { if (empty($this->rate)) { $this->rate = 1; $paypal_currency_code = $this->get_paypal_currency_code(); $local_currency_code = $this->get_local_currency_code(); if ($local_currency_code != $paypal_currency_code) { $curr = new CURRENCYCONVERTER(); $this->rate = $curr->convert(1, $paypal_currency_code, $local_currency_code); } } return $this->format_price($amt * $this->rate); }
private function _formatTable($services, $currency = false) { /* The checkout template expects the array to be in a certain * format. This function will iterate through the provided * services array and format it for use. During the loop * we take advantage of the loop and translate the currency * if necessary based off of what UPS tells us they are giving us * for currency and what is set for the main currency in the settings * area */ $converter = null; if ($currency) { $converter = new CURRENCYCONVERTER(); } $finalTable = array(); foreach (array_keys($services) as $service) { if ($currency != false && $currency != $services[$service][0]) { $temp = $services[$service][1]; $services[$service][1] = $converter->convert($services[$service][1], $currency, $services[$service][0]); } $finalTable[$service] = $services[$service][1]; } return $finalTable; }
function gateway_paypal_multiple($seperator, $sessionid) { global $wpdb, $wpsc_cart; $purchase_log = $wpdb->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("<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'; //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`='" . 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'; if (get_option('address_override') == 1) { $data['address_override'] = '1'; } if ((int) (bool) get_option('paypal_ship') == '1') { $data['no_shipping'] = '0'; $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 ((double) $item['price'] == 0) { continue; } $variation_count = count($product_variations); $local_currency_productprice = $item['price']; $local_currency_shipping = $item['pnp'] / $item['quantity']; 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($wpsc_cart->calculate_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 = $wpsc_cart->calculate_base_shipping(); $tax_price = $item['tax_charged']; } //exit("<pre>".print_r(, true).'</pre>'); $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')] != '') { if (!is_array($_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"; $data = apply_filters('wpsc_paypal_standard_post_data', $data); $datacount = count($data); $num = 0; // exit('<pre>'.print_r($data,true).'</pre>'); 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¤cy_code=' . urlencode($data['currency_code']) . '&lc=' . urlencode($data['lc']) . '&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 "<a href='" . get_option('paypal_multiple_url') . "?" . $output . "'>Test the URL here</a>"; echo "<pre>" . print_r($data, true) . "</pre>"; // echo "<pre>".print_r($_POST,true)."</pre>"; exit; } header("Location: " . get_option('paypal_multiple_url') . "?" . $output); exit; }
function gateway_chronopay($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); $cart_sql = "SELECT * FROM `" . $wpdb->prefix . "cart_contents` WHERE `purchaseid`='" . $purchase_log[0]['id'] . "'"; $cart = $wpdb->get_results($cart_sql, ARRAY_A); // Chronopay post variables $chronopay_url = get_option('chronopay_url'); $data['product_id'] = get_option('chronopay_product_id'); $data['product_name'] = get_option('chronopay_product_name'); $data['product_price_currency'] = get_option('chronopay_curcode'); $data['language'] = get_option('chronopay_language'); $data['cb_url'] = get_option('siteurl') . "/?chronopay_callback=true"; $data['cb_type'] = 'P'; $data['decline_url'] = get_option('siteurl') . "/?chronopay_callback=true"; $data['cs1'] = $sessionid; $data['cs2'] = 'chronopay'; $salt = get_option('chronopay_salt'); $data['cs3'] = md5($salt . md5($sessionid . $salt)); // placed in here for security so that the return call can be validated as 'real' // User details if ($_POST['collected_data'][get_option('chronopay_form_first_name')] != '') { $data['f_name'] = $_POST['collected_data'][get_option('chronopay_form_first_name')]; } if ($_POST['collected_data'][get_option('chronopay_form_last_name')] != "") { $data['s_name'] = $_POST['collected_data'][get_option('chronopay_form_last_name')]; } if ($_POST['collected_data'][get_option('chronopay_form_address')] != '') { $data['street'] = str_replace("\n", ', ', $_POST['collected_data'][get_option('chronopay_form_address')]); } if ($_POST['collected_data'][get_option('chronopay_form_city')] != '') { $data['city'] = $_POST['collected_data'][get_option('chronopay_form_city')]; } if (preg_match("/^[a-zA-Z]{2}\$/", $_SESSION['selected_country'])) { $data['country'] = $_SESSION['selected_country']; } // 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')]; } // Get Currency details abd 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']; $chronopay_currency_code = get_option('chronopay_curcode'); // Chronopay only processes in the set currency. This is USD or EUR dependent on what the Chornopay account is set up with. // This must match the Chronopay settings set up in wordpress. Convert to the chronopay currency and calculate total. $curr = new CURRENCYCONVERTER(); $decimal_places = 2; $total_price = 0; $i = 1; $all_donations = true; $all_no_shipping = true; 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['venue_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 = nzshpcrt_determine_item_shipping($item['prodid'], 1, $_SESSION['delivery_country']); if ($chronopay_currency_code != $local_currency_code) { $chronopay_currency_productprice = $curr->convert($local_currency_productprice, $chronopay_currency_code, $local_currency_code); $chronopay_currency_shipping = $curr->convert($local_currency_shipping, $chronopay_currency_code, $local_currency_code); } else { $chronopay_currency_productprice = $local_currency_productprice; $chronopay_currency_shipping = $local_currency_shipping; } $data['item_name_' . $i] = $product_data['name'] . $variation_list; $data['amount_' . $i] = number_format(sprintf("%01.2f", $chronopay_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($chronopay_currency_shipping, $decimal_places, '.', ''); $data['shipping2_' . $i] = number_format($chronopay_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; } $total_price = $total_price + $data['amount_' . $i] * $data['quantity_' . $i]; if ($all_no_shipping != false) { $total_price = $total_price + $data['shipping_' . $i] + $data['shipping2_' . $i]; } $i++; } $base_shipping = nzshpcrt_determine_base_shipping(0, $_SESSION['delivery_country']); if ($base_shipping > 0 && $all_donations == false && $all_no_shipping == false) { if ($chronopay_currency_code != $local_currency_code) { $base_shipping = $curr->convert($base_shipping, $chronopay_currency_code, $local_currency_code); } $data['handling_cart'] = number_format($base_shipping, $decimal_places, '.', ''); $total_price += number_format($base_shipping, $decimal_places, '.', ''); } $data['product_price'] = $total_price; // Create Form to post to Chronopay $output = "\n\t\t<form id=\"chronopay_form\" name=\"chronopay_form\" method=\"post\" action=\"{$chronopay_url}\">\n"; foreach ($data as $n => $v) { $output .= "\t\t\t<input type=\"hidden\" name=\"{$n}\" value=\"{$v}\" />\n"; } $output .= "\t\t\t<input type=\"submit\" value=\"Continue to ChronoPay\" />\n\t\t</form>\n\t"; // echo form.. if (get_option('chronopay_debug') == 1) { echo "DEBUG MODE ON!!<br/>"; echo "The following form is created and would be posted to Chronopay for processing. Press submit to continue:<br/>"; echo "<pre>" . htmlspecialchars($output) . "</pre>"; } echo $output; if (get_option('chronopay_debug') == 0) { echo "<script language=\"javascript\" type=\"text/javascript\">document.getElementById('chronopay_form').submit();</script>"; } exit; }
function Usecase($seperator, $sessionid, $fromcheckout) { global $wpdb, $wpsc_cart; $purchase_log_sql = "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= " . $sessionid . " LIMIT 1"; $purchase_log = $wpdb->get_results($purchase_log_sql, ARRAY_A); $cart_sql = "SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`='" . $purchase_log[0]['id'] . "'"; $wp_cart = $wpdb->get_results($cart_sql, ARRAY_A); $merchant_id = get_option('google_id'); $merchant_key = get_option('google_key'); $server_type = get_option('google_server_type'); $currency = get_option('google_cur'); $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency); $transact_url = get_option('transact_url'); $returnURL = $transact_url . $seperator . "sessionid=" . $sessionid . "&gateway=google"; $cart->SetContinueShoppingUrl($returnURL); $cart->SetEditCartUrl(get_option('shopping_cart_url')); $no = 1; //exit("<pre>".print_r($wpsc_cart,true)."</pre>"); //new item code $no = 0; // $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency); // foreach($wpsc_cart->cart_items as $item){ //google prohibited items not implemented $curr = new CURRENCYCONVERTER(); $currency_code = $wpdb->get_results("SELECT `code` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `id`='" . get_option('currency_type') . "' LIMIT 1", ARRAY_A); $local_currency_code = $currency_code[0]['code']; // exit('<pre>'.print_r($_REQUEST,true).'</pre>'); $google_curr = get_option('google_cur'); while (wpsc_have_cart_items()) { wpsc_the_cart_item(); if ($google_curr != $local_currency_code) { $google_currency_productprice = $curr->convert(wpsc_cart_item_price(false) / wpsc_cart_item_quantity(), $google_curr, $local_currency_code); $google_currency_shipping = $curr->convert($wpsc_cart->selected_shipping_amount, $google_curr, $local_currency_code); } else { $google_currency_productprice = wpsc_cart_item_price(false) / wpsc_cart_item_quantity() + wpsc_cart_item_shipping(false); $google_currency_shipping = $wpsc_cart->selected_shipping_amount; } // exit('<pre>'.print_r(wpsc_cart_item_name(),true).'</pre>'); $cartitem["{$no}"] = new GoogleItem(wpsc_cart_item_name(), '', wpsc_cart_item_quantity(), $google_currency_productprice); $cart->AddItem($cartitem["{$no}"]); $no++; } //If there are coupons applied add coupon as a product with negative price if ($wpsc_cart->coupons_amount > 0) { if ($google_curr != $local_currency_code) { $google_currency_productprice = $curr->convert($wpsc_cart->coupons_amount, $google_curr, $local_currency_code); } else { $google_currency_productprice = $wpsc_cart->coupons_amount; } $cartitem[$no] = new GoogleItem('Discount', 'Discount Price', 1, '-' . $google_currency_productprice); // Unit price $cart->AddItem($cartitem[$no]); } // } // Add shipping options if (wpsc_uses_shipping() && $google_currency_shipping > 0) { $Gfilter = new GoogleShippingFilters(); $google_checkout_shipping = get_option("google_shipping_country"); $googleshippingcountries = count($google_checkout_shipping); //exit('<pre>'.print_r($googleshipping, true).'</pre>'); if ($googleshippingcountries == 242) { $Gfilter->SetAllowedWorldArea(true); } else { if (is_array($google_checkout_shipping)) { $google_shipping_country_ids = implode(",", $google_checkout_shipping); } $google_shipping_country = $wpdb->get_col("SELECT `isocode` FROM " . WPSC_TABLE_CURRENCY_LIST . " WHERE id IN (" . $google_shipping_country_ids . ")"); foreach ($google_shipping_country as $isocode) { //exit($isocode); $Gfilter->AddAllowedPostalArea($isocode); if ($isocode == 'US') { $Gfilter->SetAllowedCountryArea('ALL'); } } } $Gfilter->SetAllowUsPoBox(false); $ship_1 = new GoogleFlatRateShipping('Flat Rate Shipping', $google_currency_shipping); $ship_1->AddShippingRestrictions($Gfilter); $cart->AddShipping($ship_1); } //wpsc_google_shipping_quotes(); // Add tax rules //if ($_SESSION['wpsc_selected_country']=='US'){ //set default tax //exit('<pre>'.print_r($_SESSION,true).'</pre>'); $sql = "SELECT `name`, `tax` FROM " . WPSC_TABLE_REGION_TAX . " WHERE id='" . $_SESSION['wpsc_selected_region'] . "'"; //exit('<pre>'.print_r($sql, true).'</pre>'); $state_name = $wpdb->get_row($sql, ARRAY_A); //exit('<pre>'.print_r($state_name, true).'</pre>'); $defaultTax = $state_name['tax'] / 100; $tax_rule = new GoogleDefaultTaxRule($defaultTax); $sql = "SELECT `code` FROM " . WPSC_TABLE_REGION_TAX . " WHERE `country_id`='136' AND `tax` = " . $state_name['tax']; $states = $wpdb->get_col($sql); //exit('<pre>'.print_r($states, true).'</pre>'); $tax_rule->SetStateAreas((array) $states); $cart->AddDefaultTaxRules($tax_rule); //get alternative tax rates $sql = "SELECT DISTINCT `tax` FROM " . WPSC_TABLE_REGION_TAX . " WHERE `tax` != 0 AND `tax` !=" . $state_name['tax'] . " AND `country_id`='136' ORDER BY `tax`"; $othertax = $wpdb->get_col($sql); $i = 1; //exit('<pre>'.print_r($othertax, true).'</pre>'); foreach ($othertax as $altTax) { $sql = "SELECT `code` FROM " . WPSC_TABLE_REGION_TAX . " WHERE `country_id`='136' AND `tax`=" . $altTax; $alt = $wpdb->get_col($sql); $altTax = $altTax / 100; $alt_google_tax = new GoogleDefaultTaxRule($altTax); $alt_google_tax->SetStateAreas($alt); //$g = new GoogleAlternateTaxTable('Alt Tax'.$i); //$g->AddAlternateTaxRules($alt_google_tax); $cart->AddDefaultTaxRules($alt_google_tax); // exit(print_r($alt,true)); $i++; } //} 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'; } // Display Google Checkout button //echo '<pre>'.print_r($cart, true).'</pre>'; //unset($_SESSION['wpsc_sessionid']); //if($fromCheckout){ echo $cart->CheckoutButtonCode($google_button_size); //} }
function gateway_paypal_multiple($seperator, $sessionid) { global $wpdb; $purchase_log_sql = "SELECT * FROM `wp_purchase_logs` WHERE `sessionid`= " . $sessionid . " LIMIT 1"; $purchase_log = $wpdb->get_results($purchase_log_sql, ARRAY_A); $cart_sql = "SELECT * FROM `wp_cart_contents` WHERE `purchaseid`='" . $purchase_log[0]['id'] . "'"; $cart = $wpdb->get_results($cart_sql, ARRAY_A); $transact_url = get_option('transact_url'); //$transact_url = "http://cartoonbank.ru/?page_id=32"; // paypal connection variables // ales $data['business'] = get_option('paypal_multiple_business'); //$data['business'] = "*****@*****.**"; // ales $data['business'] = "*****@*****.**"; // $data['return'] = $transact_url . $seperator . "sessionid=" . $sessionid . "&gateway=paypal"; $data['cancel_return'] = $transact_url; $data['notify_url'] = $transact_url; $data['rm'] = '2'; //$data['image'] = 'src=\"http://www.paypal.com/en_US/i/btn/x-click-but01.gif\" name=\"submit\" alt=\"Make payments with PayPal - its fast, free and secure!\"'; // ales // look up the currency codes and local price //$currency_code = $wpdb->get_results("SELECT `code` FROM `wp_currency_list` WHERE `id`='".get_option(currency_type)."' LIMIT 1",ARRAY_A); //$local_currency_code = $currency_code[0]['code']; $local_currency_code = "RUB"; //ales $paypal_currency_code = get_option('paypal_curcode'); //$paypal_currency_code = "USD"; $paypal_currency_code = "RUB"; // 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['Ic'] = 'US'; $data['Ic'] = 'RU'; $data['bn'] = 'toolkit-php'; $data['no_shipping'] = '1'; $data['no_note'] = '1'; switch ($paypal_currency_code) { case "JPY": $decimal_places = 0; break; case "HUF": $decimal_places = 0; break; default: $decimal_places = 2; } $i = 1; foreach ($cart as $item) { $sql = "SELECT * FROM `wp_product_list` WHERE `id`='" . $item['prodid'] . "' LIMIT 1"; //SELECT * FROM `wp_product_list` WHERE `id`='5900' LIMIT 1 //pokazh($sql); $product_data = $wpdb->get_results($sql, ARRAY_A); $product_data = $product_data[0]; //exit("<pre>" . print_r($item,true) ."</pre>"); /* $variation_count = count($product_variations); $variation_sql = "SELECT * FROM `wp_cart_item_variations` WHERE `cart_id`='".$item['id']."'"; $variation_data = $wpdb->get_results($variation_sql,ARRAY_A); //exit("<pre>" . print_r($variation_data,true) ."</pre>"); $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['venue_id']; $value_data = $wpdb->get_results("SELECT * FROM `wp_variation_values` WHERE `id`='".$value_id."' LIMIT 1",ARRAY_A); $variation_list .= $value_data[0]['name']; $j++; } $variation_list .= ")"; } else { $variation_list = ''; } */ /* if($product_data['special']==1) { $price_modifier = $product_data['special_price']; } else { $price_modifier = 0; } */ ///$local_currency_productprice = ($product_data['price'] - $price_modifier) * get_option('gst_rate'); if (isset($_POST['disc'])) { $discount = $_POST['disc']; } else { $discount = 0; } //echo("<pre>" . print_r($item,true) ."</pre>"); $local_currency_productprice = ceil($item['price'] * (100 - $discount) / 100); //pokazh($discount); //pokazh($local_currency_productprice); //$local_currency_shipping = nzshpcrt_determine_item_shipping($item['prodid'], $item['quantity'], $_SESSION['selected_country']); 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("bad"); } else { $paypal_currency_productprice = $local_currency_productprice; //$paypal_currency_shipping = $local_currency_shipping; //exit("good"); } $data['item_name_' . $i] = $product_data['name']; //.$variation_list; $data['amount_' . $i] = number_format(sprintf("%01.2f", $paypal_currency_productprice), $decimal_places, '.', ''); //$data['amount_'.$i] = '10'; // ales $data['quantity_' . $i] = $item['quantity']; $data['item_number_' . $i] = $product_data['id']; //exit($paypal_currency_shipping); $data['shipping_' . $i] = ''; //number_format($paypal_currency_shipping,$decimal_places,'.',''); $data['handling_' . $i] = ''; $i++; } $data['tax'] = ''; /* $base_shipping = nzshpcrt_determine_base_shipping(0, $_SESSION['selected_country']); if($base_shipping > 0) { $data['item_name_'.$i] = "Shipping"; $data['amount_'.$i] = number_format(0,$decimal_places,'.',''); $data['quantity_'.$i] = 1; $data['item_number_'.$i] = 0; $data['shipping_'.$i] = number_format($base_shipping,$decimal_places,'.',''); $data['handling_'.$i] = ''; } */ $data['custom'] = ''; $data['invoice'] = $sessionid; // User details /* $data['first_name'] = $_POST['firstname']; $data['last_name'] = $_POST['lastname']; */ $address_data = $wpdb->get_results("SELECT `id`,`type` FROM `wp_collect_data_forms` WHERE `type` IN ('address','delivery_address') AND `active` = '1'", ARRAY_A); foreach ((array) $address_data as $address) { $data['address1'] = $_POST['collected_data'][$address['id']]; if ($address['type'] == 'delivery_address') { break; } } $city_data = $wpdb->get_results("SELECT `id`,`type` FROM `wp_collect_data_forms` WHERE `type` IN ('city','delivery_city') AND `active` = '1'", ARRAY_A); foreach ((array) $city_data as $city) { $data['city'] = $_POST['collected_data'][$city['id']]; if ($city['type'] == 'delivery_city') { break; } } $country_data = $wpdb->get_results("SELECT `id`,`type` FROM `wp_collect_data_forms` WHERE `type` IN ('country','delivery_country') AND `active` = '1'", ARRAY_A); foreach ((array) $country_data as $country) { $data['country'] = $_POST['collected_data'][$country['id']]; if ($address['type'] == 'delivery_country') { break; } } //$data['country'] = $_POST['address']; // Change suggested by waxfeet@gmail.com, if email to be sent is not there, dont send an email address /*if($_POST['collected_data'][get_option('email_form_field')] != 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; $output = ""; foreach ($data as $key => $value) { $amp = '&'; $num++; if ($num == $datacount) { $amp = ''; } //$output .= $key.'='.urlencode($value).$amp; $output .= $key . '=' . urlencode($value) . $amp; } /* echo("<pre>" . print_r($_POST,true) ."</pre>"); echo("<pre>" . print_r($_SESSION,true) ."</pre>"); exit("<pre>" . print_r($data,true) ."</pre>"); */ //header("Content-Type: text/html; charset=utf-8"); header("Location: " . get_option('paypal_multiple_url') . "?" . $output); exit; }
/** * construct value array method, converts the data gathered by the base class code to something acceptable to the gateway * @access public */ function construct_value_array() { global $wpdb; //$collected_gateway_data $paypal_vars = array(); // Store settings to be sent to paypal $paypal_vars += array('business' => get_option('paypal_multiple_business'), 'return' => add_query_arg('sessionid', $this->cart_data['session_id'], $this->cart_data['transaction_results_url']), 'cancel_return' => $this->cart_data['transaction_results_url'], 'notify_url' => add_query_arg('gateway', 'wpsc_merchant_paypal_standard', $this->cart_data['notification_url']), 'rm' => '2', 'currency_code' => $this->cart_data['store_currency'], 'lc' => $this->cart_data['store_currency'], 'bn' => $this->cart_data['software_name'], 'no_note' => '1', 'charset' => 'utf-8'); //used to send shipping if ((int) (bool) get_option('paypal_ship') == 1) { $paypal_vars += array('address_override' => '1', 'no_shipping' => '0'); } // User settings to be sent to paypal $paypal_vars += array('email' => $this->cart_data['email_address'], 'first_name' => $this->cart_data['shipping_address']['first_name'], 'last_name' => $this->cart_data['shipping_address']['last_name'], 'address1' => $this->cart_data['shipping_address']['address'], 'city' => $this->cart_data['shipping_address']['city'], 'country' => $this->cart_data['shipping_address']['country'], 'zip' => $this->cart_data['shipping_address']['post_code']); if ($this->cart_data['shipping_address']['state'] != '') { $paypal_vars += array('state' => $this->cart_data['shipping_address']['state']); } // Order settings to be sent to paypal $paypal_vars += array('invoice' => $this->cart_data['session_id']); if ($this->cart_data['is_subscription'] == true) { $reprocessed_cart_data['shopping_cart'] = array('is_used' => false, 'price' => 0, 'length' => 1, 'unit' => 'd', 'times_to_rebill' => 1); $reprocessed_cart_data['subscription'] = array('is_used' => false, 'price' => 0, 'length' => 1, 'unit' => 'D', 'times_to_rebill' => 1); foreach ($this->cart_items as $cart_row) { if ($cart_row['is_recurring'] == true) { $reprocessed_cart_data['subscription']['is_used'] = true; $reprocessed_cart_data['subscription']['price'] = $cart_row['price']; $reprocessed_cart_data['subscription']['length'] = $cart_row['recurring_data']['rebill_interval']['length']; $reprocessed_cart_data['subscription']['unit'] = strtoupper($cart_row['recurring_data']['rebill_interval']['unit']); $reprocessed_cart_data['subscription']['times_to_rebill'] = $cart_row['recurring_data']['times_to_rebill']; } else { $item_cost = $cart_row['price'] + $cart_row['shipping'] + $cart_row['tax'] + $cart_row['quantity']; if ($item_cost > 0) { $reprocessed_cart_data['shopping_cart']['price'] += $item_cost; $reprocessed_cart_data['shopping_cart']['is_used'] = true; } } $paypal_vars += array("item_name" => __('Your Subscription', 'wpsc'), "src" => "1"); // this can be false, we don't need to have additional items in the cart if ($reprocessed_cart_data['shopping_cart']['is_used'] == true) { $paypal_vars += array("a1" => $this->format_price($reprocessed_cart_data['shopping_cart']['price']), "p1" => $reprocessed_cart_data['shopping_cart']['length'], "t1" => $reprocessed_cart_data['shopping_cart']['unit']); } //we need at least one subscription product, if we are in thise piece of code and this is not true, something is rather wrong if ($reprocessed_cart_data['subscription']['is_used'] == true) { $paypal_vars += array("a3" => $this->format_price($reprocessed_cart_data['subscription']['price']), "p3" => $reprocessed_cart_data['subscription']['length'], "t3" => $reprocessed_cart_data['subscription']['unit']); // If the srt value for the number of times to rebill is not greater than 1, paypal won't accept the transaction. if ($reprocessed_cart_data['subscription']['times_to_rebill'] > 1) { $paypal_vars += array("srt" => $reprocessed_cart_data['subscription']['times_to_rebill']); } } } } else { // Stick the cart item values together here $i = 1; if (!$this->cart_data['has_discounts']) { foreach ($this->cart_items as $cart_row) { $paypal_vars += array("item_name_{$i}" => $cart_row['name'], "amount_{$i}" => $this->format_price($cart_row['price']), "tax_{$i}" => $this->format_price($cart_row['tax']), "quantity_{$i}" => $cart_row['quantity'], "item_number_{$i}" => $cart_row['product_id'], "shipping_{$i}" => $this->format_price($cart_row['shipping'] / $cart_row['quantity']), "shipping2_{$i}" => $this->format_price($cart_row['shipping'] / $cart_row['quantity']), "handling_{$i}" => ''); ++$i; } //set base shipping $paypal_vars += array("handling_cart" => $this->cart_data['base_shipping']); } else { $decimal_places = 2; $currency_code = $wpdb->get_var("SELECT `code` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `id`='" . get_option('currency_type') . "' LIMIT 1"); $local_currency_code = $currency_code; $paypal_currency_code = get_option('paypal_curcode'); if (empty($paypal_currency_code)) { $paypal_currency_code = 'US'; } $curr = new CURRENCYCONVERTER(); if ($paypal_currency_code != $local_currency_code) { $paypal_currency_productprice = $curr->convert($this->cart_data['total_price'], $paypal_currency_code, $local_currency_code); } else { $paypal_currency_productprice = $this->cart_data['total_price']; } $paypal_vars['item_name_' . $i] = "Your Shopping Cart"; $paypal_vars['amount_' . $i] = number_format(sprintf("%01.2f", $paypal_currency_productprice), $decimal_places, '.', ''); $paypal_vars['quantity_' . $i] = 1; $paypal_vars['shipping_' . $i] = 0; $paypal_vars['shipping2_' . $i] = 0; $paypal_vars['handling_' . $i] = 0; } } // Payment Type settings to be sent to paypal if ($this->cart_data['is_subscription'] == true) { $paypal_vars += array('cmd' => '_xclick-subscriptions'); } else { $paypal_vars += array('upload' => '1', 'cmd' => '_ext-enter', 'redirect_cmd' => '_cart'); } $this->collected_gateway_data = $paypal_vars; }
function paypal_certified_currencyconverter() { global $wpdb; $currency_code = $wpdb->get_results("SELECT `code` FROM `" . WPSC_TABLE_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'); 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(); if ($paypal_currency_code != $local_currency_code) { $paypal_currency_productprice = $curr->convert($_SESSION['paypalAmount'], $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); } else { $paypal_currency_productprice = $_SESSION['paypalAmount']; $paypal_currency_shipping = $local_currency_shipping; $base_shipping = $purchase_log['base_shipping']; } switch ($paypal_currency_code) { case "JPY": $decimal_places = 0; break; case "HUF": $decimal_places = 0; default: $decimal_places = 2; break; } //echo "$paypal_currency_code|$local_currency_code"; $_SESSION['paypalAmount'] = number_format(sprintf("%01.2f", $paypal_currency_productprice), $decimal_places, '.', ''); }
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; }
/** * construct value array method, converts the data gathered by the base class code to something acceptable to the gateway * @access private * @param boolean $aggregate Whether to aggregate the cart data or not. Defaults to false. * @return array $paypal_vars The paypal vars */ function _construct_value_array($aggregate = false) { global $wpdb; $paypal_vars = array(); $add_tax = true; if (get_option('wpec_taxes_inprice') == 'inclusive') { $add_tax = false; } // Store settings to be sent to paypal $paypal_vars += array('business' => get_option('paypal_multiple_business'), 'return' => add_query_arg('sessionid', $this->cart_data['session_id'], $this->cart_data['transaction_results_url']), 'cancel_return' => $this->cart_data['transaction_results_url'], 'rm' => '2', 'currency_code' => $this->cart_data['store_currency'], 'lc' => $this->cart_data['store_currency'], 'bn' => $this->cart_data['software_name'], 'no_note' => '1', 'charset' => 'utf-8'); // IPN data if (get_option('paypal_ipn') == 1) { $notify_url = $this->cart_data['notification_url']; $notify_url = add_query_arg('gateway', 'wpsc_merchant_paypal_standard', $notify_url); $notify_url = apply_filters('wpsc_paypal_standard_notify_url', $notify_url); $paypal_vars += array('notify_url' => $notify_url); } // Shipping if ((bool) get_option('paypal_ship')) { $paypal_vars += array('address_override' => '1', 'no_shipping' => '0'); } // Customer details $paypal_vars += array('email' => $this->cart_data['email_address'], 'first_name' => $this->cart_data['shipping_address']['first_name'], 'last_name' => $this->cart_data['shipping_address']['last_name'], 'address1' => $this->cart_data['shipping_address']['address'], 'city' => $this->cart_data['shipping_address']['city'], 'country' => $this->cart_data['shipping_address']['country'], 'zip' => $this->cart_data['shipping_address']['post_code']); if ($this->cart_data['shipping_address']['state'] != '') { $paypal_vars += array('state' => $this->cart_data['shipping_address']['state']); } // Order settings to be sent to paypal $paypal_vars += array('invoice' => $this->cart_data['session_id']); // Two cases: // - We're dealing with a subscription // - We're dealing with a normal cart if ($this->cart_data['is_subscription']) { $paypal_vars += array('cmd' => '_xclick-subscriptions'); $reprocessed_cart_data['shopping_cart'] = array('is_used' => false, 'price' => 0, 'length' => 1, 'unit' => 'd', 'times_to_rebill' => 1); $reprocessed_cart_data['subscription'] = array('is_used' => false, 'price' => 0, 'length' => 1, 'unit' => 'D', 'times_to_rebill' => 1); foreach ($this->cart_items as $cart_row) { if ($cart_row['is_recurring']) { $reprocessed_cart_data['subscription']['is_used'] = true; $reprocessed_cart_data['subscription']['price'] = $cart_row['price']; $reprocessed_cart_data['subscription']['length'] = $cart_row['recurring_data']['rebill_interval']['length']; $reprocessed_cart_data['subscription']['unit'] = strtoupper($cart_row['recurring_data']['rebill_interval']['unit']); $reprocessed_cart_data['subscription']['times_to_rebill'] = $cart_row['recurring_data']['times_to_rebill']; } else { $item_cost = $cart_row['price'] + $cart_row['shipping'] + $cart_row['tax'] + $cart_row['quantity']; if ($item_cost > 0) { $reprocessed_cart_data['shopping_cart']['price'] += $item_cost; $reprocessed_cart_data['shopping_cart']['is_used'] = true; } } $paypal_vars += array('item_name' => __('Your Subscription', 'wpsc'), 'src' => '1'); // This can be false, we don't need to have additional items in the cart/ if ($reprocessed_cart_data['shopping_cart']['is_used']) { $paypal_vars += array("a1" => $this->format_price($reprocessed_cart_data['shopping_cart']['price']), "p1" => $reprocessed_cart_data['shopping_cart']['length'], "t1" => $reprocessed_cart_data['shopping_cart']['unit']); } // We need at least one subscription product, // If this is not true, something is rather wrong. if ($reprocessed_cart_data['subscription']['is_used']) { $paypal_vars += array("a3" => $this->format_price($reprocessed_cart_data['subscription']['price']), "p3" => $reprocessed_cart_data['subscription']['length'], "t3" => $reprocessed_cart_data['subscription']['unit']); // If the srt value for the number of times to rebill is not greater than 1, // paypal won't accept the transaction. if ($reprocessed_cart_data['subscription']['times_to_rebill'] > 1) { $paypal_vars += array('srt' => $reprocessed_cart_data['subscription']['times_to_rebill']); } } } // end foreach cart item } else { $paypal_vars += array('upload' => '1', 'cmd' => '_ext-enter', 'redirect_cmd' => '_cart'); $handling = $this->cart_data['base_shipping']; if ($add_tax) { $handling += $this->cart_data['cart_tax']; } // Set base shipping $paypal_vars += array('handling_cart' => $handling); // Stick the cart item values together here $i = 1; if (!$this->cart_data['has_discounts'] && !$aggregate) { foreach ($this->cart_items as $cart_row) { $paypal_vars += array("item_name_{$i}" => $cart_row['name'], "amount_{$i}" => $this->format_price($cart_row['price']), "tax_{$i}" => $add_tax ? $this->format_price($cart_row['tax']) : 0, "quantity_{$i}" => $cart_row['quantity'], "item_number_{$i}" => $cart_row['product_id'], "shipping_{$i}" => $this->format_price($cart_row['shipping'] / $cart_row['quantity']), "shipping2_{$i}" => $this->format_price($cart_row['shipping'] / $cart_row['quantity']), "handling_{$i}" => ''); ++$i; } } else { // Work out discounts where applicable $currency_code = $wpdb->get_var("\n\t\t\t\t\tSELECT `code`\n\t\t\t\t\tFROM `" . WPSC_TABLE_CURRENCY_LIST . "`\n\t\t\t\t\tWHERE `id`='" . get_option('currency_type') . "'\n\t\t\t\t\tLIMIT 1\n\t\t\t\t"); $local_currency_code = $currency_code; $paypal_currency_code = get_option('paypal_curcode', 'USD'); if ($paypal_currency_code != $local_currency_code) { $curr = new CURRENCYCONVERTER(); $paypal_currency_productprice = $curr->convert($this->cart_data['total_price'], $paypal_currency_code, $local_currency_code); } else { $paypal_currency_productprice = $this->cart_data['total_price']; } $paypal_vars['item_name_' . $i] = "Your Shopping Cart"; $paypal_vars['amount_' . $i] = $this->format_price($paypal_currency_productprice, $local_currency_code) - $paypal_vars['handling_cart']; $paypal_vars['quantity_' . $i] = 1; $paypal_vars['shipping_' . $i] = 0; $paypal_vars['shipping2_' . $i] = 0; $paypal_vars['handling_' . $i] = 0; } } return $paypal_vars; }
function paypal_express_currencyconverter() { global $wpdb; $currency_code = $wpdb->get_var("SELECT `code` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `id`='" . get_option('currency_type') . "' LIMIT 1"); $local_currency_code = $currency_code; $paypal_currency_code = get_option('paypal_curcode'); if ($paypal_currency_code == '') { $paypal_currency_code = 'US'; } $curr = new CURRENCYCONVERTER(); if ($paypal_currency_code != $local_currency_code) { $paypal_currency_productprice = $curr->convert($_SESSION['paypalAmount'], $paypal_currency_code, $local_currency_code); $paypal_currency_shipping = $curr->convert($local_currency_shipping, $paypal_currency_code, $local_currency_code); $base_shipping = $curr->convert($purchase_log['base_shipping'], $paypal_currency_code, $local_currency_code); } else { $paypal_currency_productprice = $_SESSION['paypalAmount']; $paypal_currency_shipping = $local_currency_shipping; $base_shipping = $purchase_log['base_shipping']; } switch ($paypal_currency_code) { case "JPY": $decimal_places = 0; break; case "HUF": $decimal_places = 0; break; default: $decimal_places = 2; break; } $_SESSION['paypalAmount'] = number_format(sprintf("%01.2f", $paypal_currency_productprice), $decimal_places, '.', ''); }
function Usecase($separator, $sessionid, $fromcheckout) { global $wpdb, $wpsc_cart; $purchase_log_sql = $wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid` = %s LIMIT 1", $sessionid); $purchase_log = $wpdb->get_results($purchase_log_sql, ARRAY_A); $cart_sql = $wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid` = %d", $purchase_log[0]['id']); $wp_cart = $wpdb->get_results($cart_sql, ARRAY_A); $merchant_id = get_option('google_id'); $merchant_key = get_option('google_key'); $server_type = get_option('google_server_type'); $currency = get_option('google_cur'); $transact_url = get_option('transact_url'); $returnURL = $transact_url . $separator . "sessionid=" . $sessionid . "&gateway=google"; $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency); $cart->SetContinueShoppingUrl($returnURL); $cart->SetEditCartUrl(get_option('shopping_cart_url')); //google prohibited items not implemented $currency_converter = new CURRENCYCONVERTER(); $currency_code = $wpdb->get_results("SELECT `code` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `id`='" . get_option('currency_type') . "' LIMIT 1", ARRAY_A); $local_currency_code = $currency_code[0]['code']; $google_curr = get_option('google_cur'); $currentcy_rate = 1; if ($google_curr != $local_currency_code) { $currentcy_rate = $currency_converter->convert(1, $local_currency_code, $google_curr); } while (wpsc_have_cart_items()) { wpsc_the_cart_item(); $google_currency_productprice = $currentcy_rate * (wpsc_cart_item_price(false) / wpsc_cart_item_quantity()); $cart_item = new GoogleItem(wpsc_cart_item_name(), '', wpsc_cart_item_quantity(), $google_currency_productprice); $cart->AddItem($cart_item); } //If there are coupons applied add coupon as a product with negative price if ($wpsc_cart->coupons_amount > 0) { $google_currency_productprice = $currentcy_rate * $wpsc_cart->coupons_amount; $coupon = new GoogleItem('Discount', 'Discount Price', 1, '-' . $google_currency_productprice); $cart->AddItem($coupon); } $shipping_country = $purchase_log[0]['shipping_country']; $shipping_region = $purchase_log[0]['shipping_region']; if ($shipping_country == "UK") { $shipping_country = "GB"; } // Add shipping options if (wpsc_uses_shipping()) { $shipping_name = ucfirst($wpsc_cart->selected_shipping_method) . " - " . $wpsc_cart->selected_shipping_option; if ($shipping_name == "") { $shipping_name = "Calculated"; } $shipping = new GoogleFlatRateShipping($shipping_name, $wpsc_cart->calculate_total_shipping() * $currentcy_rate); if (!empty($shipping_country)) { $shipping_filter = new GoogleShippingFilters(); if (!empty($shipping_region) && is_numeric($shipping_region)) { $shipping_filter->AddAllowedPostalArea($shipping_country, wpsc_get_state_by_id($shipping_region, "code")); $shipping_filter->AddAllowedStateArea(wpsc_get_state_by_id($shipping_region, "code")); } else { $shipping_filter->AddAllowedPostalArea($shipping_country); } $shipping->AddShippingRestrictions($shipping_filter); } $cart->AddShipping($shipping); } // Add tax rules if (!empty($shipping_country)) { $tax_rule = new GoogleDefaultTaxRule(wpsc_cart_tax(false) / $wpsc_cart->calculate_subtotal()); $tax_rule->AddPostalArea($shipping_country); $cart->AddDefaultTaxRules($tax_rule); } // Display Google Checkout button 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'; } echo $cart->CheckoutButtonCode($google_button_size); }