public function initContent() { $this->display_column_left = false; include_once _PS_MODULE_DIR_ . 'gcheckout/gcheckout.php'; include_once _PS_MODULE_DIR_ . 'gcheckout/library/googlecart.php'; include_once _PS_MODULE_DIR_ . 'gcheckout/library/googleitem.php'; include_once _PS_MODULE_DIR_ . 'gcheckout/library/googleshipping.php'; parent::initContent(); $gcheckout = new GCheckout(); /*if (_PS_VERSION_ >= '1.5' && !Context::getContext()->customer->isLogged(true)) Tools::redirect('index.php?co:q:q:qntroller=authentication&back=order.php'); else if (_PS_VERSION_ < '1.5' && !$cookie->isLogged(true)) Tools::redirect('authentication.php?back=order.php'); else if (!$gcheckout->context->cart->getOrderTotal(true, Cart::BOTH)) Tools::displayError('Error: Empty cart');*/ // Prepare payment $currency = $gcheckout->getCurrency($this->context->cart->id_currency); if ($this->context->cart->id_currency != $currency->id) { $this->context->cart->id_currency = (int) $currency->id; $this->context->cookie->id_currency = (int) $this->context->cart->id_currency; $this->context->cart->update(); //Tools::redirect('modules/'.$this->name.'/payment.php'); Tools::redirect($link->getModuleLink('gcheckout', 'payment')); } $googleCart = new GoogleCart(Configuration::get('GCHECKOUT_MERCHANT_ID'), Configuration::get('GCHECKOUT_MERCHANT_KEY'), Configuration::get('GCHECKOUT_MODE'), $currency->iso_code); foreach ($this->context->cart->getProducts() as $product) { $googleCart->AddItem(new GoogleItem(utf8_decode($product['name'] . ((isset($product['attributes']) and !empty($product['attributes'])) ? ' - ' . $product['attributes'] : '')), utf8_decode($product['description_short']), (int) $product['cart_quantity'], $product['price_wt'], strtoupper(Configuration::get('PS_WEIGHT_UNIT')), (double) $product['weight'])); } if ($wrapping = $this->context->cart->getOrderTotal(true, Cart::ONLY_WRAPPING)) { $googleCart->AddItem(new GoogleItem(utf8_decode($this->l('Wrapping')), '', 1, $wrapping)); } if (_PS_VERSION_ < '1.5') { foreach ($this->context->cart->getDiscounts() as $voucher) { $googleCart->AddItem(new GoogleItem(utf8_decode($voucher['name']), utf8_decode($voucher['description']), 1, '-' . $voucher['value_real'])); } } else { foreach ($this->context->cart->getCartRules() as $cart_tule) { $googleCart->AddItem(new GoogleItem(utf8_decode($cart_tule['code']), utf8_decode($cart_tule['name']), 1, '-' . $cart_tule['value_real'])); } } if (!Configuration::get('GCHECKOUT_NO_SHIPPING')) { $carrier = new Carrier((int) $this->context->cart->id_carrier, $this->context->language->id); $googleCart->AddShipping(new GoogleFlatRateShipping(utf8_decode($carrier->name), $this->context->cart->getOrderShippingCost($this->context->cart->id_carrier))); } $googleCart->SetEditCartUrl(Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'order.php'); $googleCart->SetContinueShoppingUrl(Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'order-confirmation.php'); $googleCart->SetRequestBuyerPhone(false); $googleCart->SetMerchantPrivateData($this->context->cart->id . '|' . $this->context->cart->secure_key); $total = $this->context->cart->getOrderTotal(); $this->context->smarty->assign(array('googleCheckoutExtraForm' => $googleCart->CheckoutButtonCode(), 'total' => $total, 'googleTotal' => $total, 'GC_Link' => $this->context->link->getPageLink('order', true, NULL))); $this->setTemplate('confirm.tpl'); }
function hookPayment($params) { if (!$this->active) { return; } global $smarty; require_once 'library/googlecart.php'; require_once 'library/googleitem.php'; require_once 'library/googleshipping.php'; $currency = $this->getCurrency(); $googleCart = new GoogleCart(Configuration::get('GCHECKOUT_MERCHANT_ID'), Configuration::get('GCHECKOUT_MERCHANT_KEY'), Configuration::get('GCHECKOUT_MODE'), $currency->iso_code); foreach ($params['cart']->getProducts() as $product) { $googleCart->AddItem(new GoogleItem(utf8_decode($product['name']), utf8_decode($product['description_short']), intval($product['quantity']), Tools::convertPrice($product['price_wt'], $currency))); } if ($wrapping = $params['cart']->getOrderTotal(true, 6)) { $googleCart->AddItem(new GoogleItem(utf8_decode($this->l('Wrapping')), '', 1, Tools::convertPrice($wrapping, $currency))); } foreach ($params['cart']->getDiscounts() as $voucher) { $googleCart->AddItem(new GoogleItem(utf8_decode($voucher['name']), utf8_decode($voucher['description']), 1, '-' . Tools::convertPrice($voucher['value_real'], $currency))); } $googleCart->AddShipping(new GooglePickUp($this->l('Shipping costs'), Tools::convertPrice($params['cart']->getOrderShippingCost($params['cart']->id_carrier), $currency))); $googleCart->SetEditCartUrl(Tools::getHttpHost(true, true) . __PS_BASE_URI__ . 'order.php'); $googleCart->SetContinueShoppingUrl(Tools::getHttpHost(true, true) . __PS_BASE_URI__ . 'order-confirmation.php'); $googleCart->SetRequestBuyerPhone(false); $googleCart->SetMerchantPrivateData($params['cart']->id); $smarty->assign('CheckoutButtonCode', $googleCart->CheckoutButtonCode($this->l('Pay with GoogleCheckout'), 'LARGE')); $smarty->assign('ModulePath', $this->_path); return $this->display(__FILE__, 'payment.tpl'); }
function Usecase() { $merchant_id = ""; // Your Merchant ID $merchant_key = ""; // Your Merchant Key $server_type = "sandbox"; $currency = "USD"; $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency); $total_count = 1; $certificate_path = ""; // set your SSL CA cert path // Check this URL for more info about the two types of digital Delivery // http://code.google.com/apis/checkout/developer/Google_Checkout_Digital_Delivery.html // Key/URL delivery $item_1 = new GoogleItem("Download Digital Item1", "With S/N", $total_count, 10.99); // Unit price $item_1->SetURLDigitalContent('http://example.com/download.php?id=15', 'S/N: 123.123123-3213', "Download Item1"); $cart->AddItem($item_1); // Email delivery $item_2 = new GoogleItem("Email Digital Item2", "An email will be sent by the merchant", $total_count, 9.19); // Unit price $item_2->SetEmailDigitalDelivery('true'); $cart->AddItem($item_2); // Add tax rules $tax_rule = new GoogleDefaultTaxRule(0.05); $tax_rule->SetStateAreas(array("MA", "FL", "CA")); $cart->AddDefaultTaxRules($tax_rule); // Specify <edit-cart-url> $cart->SetEditCartUrl("https://www.example.com/cart/"); // Specify "Return to xyz" link $cart->SetContinueShoppingUrl("https://www.example.com/goods/"); // Request buyer's phone number $cart->SetRequestBuyerPhone(true); // Add analytics data to the cart if its setted if (isset($_POST['analyticsdata']) && !empty($_POST['analyticsdata'])) { $cart->SetAnalyticsData($_POST['analyticsdata']); } // This will do a server-2-server cart post and send an HTTP 302 redirect status // This is the best way to do it if implementing digital delivery // More info http://code.google.com/apis/checkout/developer/index.html#alternate_technique list($status, $error) = $cart->CheckoutServer2Server('', $certificate_path); // if i reach this point, something was wrong echo "An error had ocurred: <br />HTTP Status: " . $status . ":"; echo "<br />Error message:<br />"; echo $error; // }
public function preparePayment() { require_once dirname(__FILE__) . '/library/googlecart.php'; require_once dirname(__FILE__) . '/library/googleitem.php'; require_once dirname(__FILE__) . '/library/googleshipping.php'; $currency = $this->getCurrency($this->context->cart->id_currency); if ($this->context->cart->id_currency != $currency->id) { $this->context->cart->id_currency = (int) $currency->id; $this->context->cookie->id_currency = (int) $this->context->cart->id_currency; $this->context->cart->update(); Tools::redirect('modules/' . $this->name . '/payment.php'); } $googleCart = new GoogleCart(Configuration::get('GCHECKOUT_MERCHANT_ID'), Configuration::get('GCHECKOUT_MERCHANT_KEY'), Configuration::get('GCHECKOUT_MODE'), $currency->iso_code); foreach ($this->context->cart->getProducts() as $product) { $googleCart->AddItem(new GoogleItem(utf8_decode($product['name'] . ((isset($product['attributes']) and !empty($product['attributes'])) ? ' - ' . $product['attributes'] : '')), utf8_decode($product['description_short']), (int) $product['cart_quantity'], $product['price_wt'], strtoupper(Configuration::get('PS_WEIGHT_UNIT')), (double) $product['weight'])); } if ($wrapping = $this->context->cart->getOrderTotal(true, Cart::ONLY_WRAPPING)) { $googleCart->AddItem(new GoogleItem(utf8_decode($this->l('Wrapping')), '', 1, $wrapping)); } if (_PS_VERSION_ < '1.5') { foreach ($this->context->cart->getDiscounts() as $voucher) { $googleCart->AddItem(new GoogleItem(utf8_decode($voucher['name']), utf8_decode($voucher['description']), 1, '-' . $voucher['value_real'])); } } else { foreach ($this->context->cart->getCartRules() as $cart_tule) { $googleCart->AddItem(new GoogleItem(utf8_decode($cart_tule['code']), utf8_decode($cart_tule['name']), 1, '-' . $cart_tule['value_real'])); } } if (!Configuration::get('GCHECKOUT_NO_SHIPPING')) { $carrier = new Carrier((int) $this->context->cart->id_carrier, $this->context->language->id); $googleCart->AddShipping(new GoogleFlatRateShipping(utf8_decode($carrier->name), $this->context->cart->getOrderShippingCost($this->context->cart->id_carrier))); } $googleCart->SetEditCartUrl(Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'order.php'); $googleCart->SetContinueShoppingUrl(Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'order-confirmation.php'); $googleCart->SetRequestBuyerPhone(false); $googleCart->SetMerchantPrivateData($this->context->cart->id . '|' . $this->context->cart->secure_key); $total = $this->context->cart->getOrderTotal(); $this->context->smarty->assign(array('googleCheckoutExtraForm' => $googleCart->CheckoutButtonCode($this->l('Pay with GoogleCheckout'), 'LARGE'), 'total' => $total, 'googleTotal' => $total, 'GC_Link' => _PS_VERSION_ >= '1.5' ? $this->context->link->getPageLink('order', true, NULL) : $this->context->link->getPageLink('order.php', true))); }
function UseCase3() { //Create a new shopping cart object $merchant_id = ""; //Your Merchant ID $merchant_key = ""; //Your Merchant Key $server_type = "sandbox"; $cart = new GoogleCart($merchant_id, $merchant_key, $server_type); //Add items to the cart $item1 = new GoogleItem("Dry Food Pack AA1453", " pack of highly nutritious dried food for emergency", 1, 35); $item2 = new GoogleItem("MegaSound 2GB MP3 Player", "Portable MP3 player - stores 500 songs", 1, 178); $item3 = new GoogleItem("AA Rechargeable Battery Pack", "Battery pack containing four AA rechargeable batteries", 1, 12); $cart->AddItem($item1); $cart->AddItem($item2); $cart->AddItem($item3); //Set request buyer phone $cart->SetRequestBuyerPhone("true"); //Add merchant calculations options $cart->SetMerchantCalculations("https://www.example.com/shopping/merchantCalc", "true", "true", "true"); $ship = new GoogleShipping("merchant-calc", "merchant-calculated", 5, "USD", "ALL"); $ship->SetAllowedStateAreas(array("NY", "CA")); $cart->AddShipping($ship); $tax_rule = new GoogleTaxRule("default", 0.2); $tax_rule->SetStateAreas(array("CA", "NY")); $tax_table = new GoogleTaxTable("default"); $tax_table->AddTaxRules($tax_rule); $cart->AddTaxTables($tax_table); //Display XML data echo htmlentities($cart->GetXML()); //Display a disabled, small button with a white background echo $cart->CheckoutButtonCode("small", "white", "disabled"); }
function UseCase2() { // Create a new shopping cart object $merchant_id = ""; // Your Merchant ID $merchant_key = ""; // Your Merchant Key $server_type = "sandbox"; $currency = "USD"; $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency); // Add items to the cart $item_1 = new GoogleItem("Dry Food Pack AA1453", "A pack of highly nutritious dried food for emergency", 2, 24.99); $item_1->SetTaxTableSelector("food"); $item_2 = new GoogleItem("MegaSound 2GB MP3 Player", "Portable MP3 player - stores 500 songs", 1, 175.49); $item_2->SetMerchantPrivateItemData(new MerchantPrivateItemData(array("color" => "blue", "weight" => "3.2"))); $item_2->SetMerchantItemId("Item#012345"); $cart->AddItem($item_1); $cart->AddItem($item_2); // Add shipping options $ship_1 = new GoogleFlatRateShipping("Ground", 15); $restriction_1 = new GoogleShippingFilters(); $restriction_1->SetAllowedWorldArea(true); $ship_1->AddShippingRestrictions($restriction_1); $ship_2 = new GooglePickup("Pick Up", 5); $cart->AddShipping($ship_1); $cart->AddShipping($ship_2); // Add default tax rules $tax_rule_1 = new GoogleDefaultTaxRule(0.17); $tax_rule_1->AddPostalArea("GB", "SW*"); $tax_rule_1->AddPostalArea("FR"); $tax_rule_1->AddPostalArea("DE"); $tax_rule_2 = new GoogleDefaultTaxRule(0.1); $tax_rule_2->SetWorldArea(true); $cart->AddDefaultTaxRules($tax_rule_1); $cart->AddDefaultTaxRules($tax_rule_2); // Add alternate tax table $tax_table = new GoogleAlternateTaxTable("food"); $tax_rule_1 = new GoogleAlternateTaxRule(0.05); $tax_rule_1->AddPostalArea("GB"); $tax_rule_1->AddPostalArea("FR"); $tax_rule_1->AddPostalArea("DE"); $tax_rule_2 = new GoogleAlternateTaxRule(0.03); $tax_rule_2->SetWorldArea(true); $tax_table->AddAlternateTaxRules($tax_rule_1); $tax_table->AddAlternateTaxRules($tax_rule_2); $cart->AddAlternateTaxTables($tax_table); // Add <merchant-private-data> $cart->SetMerchantPrivateData(new MerchantPrivateData(array("animals" => array("type" => "cat,dog")))); // Specify <edit-cart-url> $cart->SetEditCartUrl("http://www.example.com/edit"); // Specify "Return to xyz" link $cart->SetContinueShoppingUrl("http://www.example.com/continue"); // Request buyer's phone number $cart->SetRequestBuyerPhone(true); // Define rounding policy $cart->AddRoundingPolicy("CEILING", "TOTAL"); // Display XML data // echo "<pre>"; // echo htmlentities($cart->GetXML()); // echo "</pre>"; // Display a medium size button echo $cart->GetXML(); }
function googlecheckout() { if ($this->input->post('googlesubmit')) { $this->load->model('payment_model'); $paymentGateways_google = $this->payment_model->getPaymentSettings(); $payment_amount = $this->input->post('item_price_1'); $tr_id = $this->input->post('trans'); $this->session->set_userdata('tr_id', $tr_id); $merchant_id = $paymentGateways_google['gch']['mail_id']; // Your Merchant ID $merchant_key = $paymentGateways_google['gch']['url']; // Your Merchant Key if ($paymentGateways_google['gch']['url_status'] == 0) { $server_type = "sandbox"; } else { $server_type = "Live"; } $currency = "USD"; $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency); $total_count = 1; // Check this URL for more info about the two types of digital Delivery // http://code.google.com/apis/checkout/developer/Google_Checkout_Digital_Delivery.html //Get the language details $item_1 = new GoogleItem($this->config->item('site_name') . 'Account Deposit', ' Account Deposit ', '1', $payment_amount); // Unit price // $item_1->SetURLDigitalContent('http://example.com/download.php?id=15','S/N: 123.123123-3213', "Download Item1"); $cart->AddItem($item_1); $cart->SetMerchantPrivateData(new MerchantPrivateData(array("transaction-id" => $tr_id))); // Specify "Return to xyz" link $cart->SetContinueShoppingUrl(site_url('payment/checkoutSuccess')); // Request buyer's phone number $cart->SetRequestBuyerPhone(true); // Add analytics data to the cart if its setted if (isset($_POST['analyticsdata']) && !empty($_POST['analyticsdata'])) { $cart->SetAnalyticsData($_POST['analyticsdata']); } // This will do a server-2-server cart post and send an HTTP 302 redirect status // This is the best way to do it if implementing digital delivery // More info http://code.google.com/apis/checkout/developer/index.html#alternate_technique list($status, $error) = $cart->CheckoutServer2Server(); // if i reach this point, something was wrong echo "An error had ocurred: <br />HTTP Status: " . $status . ":"; echo "<br />Error message:<br />"; echo $error; // } }
/** * Generate the Google Checkout button link **/ public function generate_googlecheckout_form($order_id) { global $woocommerce; require_once GOOGLE_CHECKOUT_LIB . 'googlecart.php'; require_once GOOGLE_CHECKOUT_LIB . 'googleitem.php'; require_once GOOGLE_CHECKOUT_LIB . 'googleshipping.php'; require_once GOOGLE_CHECKOUT_LIB . 'googletax.php'; $order = new WC_Order($order_id); $shipping_name = explode(' ', $order->shipping_method); // Check if this is a test purchase if ($this->testmode == 'yes') { $server_type = "sandbox"; } else { $server_type = "checkout"; } $merchant_id = $this->merchant_id; // Your Merchant ID $merchant_key = $this->merchant_key; // Your Merchant Key $currency = get_option('woocommerce_currency'); $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency); // Specify <edit-cart-url> $cart->SetEditCartUrl(get_permalink(get_option('woocommerce_cart_page_id'))); // Specify "Return to xyz" link $cart->SetContinueShoppingUrl(add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink(get_option('woocommerce_thanks_page_id'))))); // Order key $cart->SetMerchantPrivateData(new MerchantPrivateData(array("cart-id" => $order->id))); // Request buyer's phone number $cart->SetRequestBuyerPhone(true); // Default tax - for shipping, if used if ($order->order_shipping_tax > 0) { // We manually calculate the shipping tax percentage here $calculated_shipping_tax_percentage = $order->order_shipping_tax / $order->order_shipping; $tax_rule_for_shipping = new GoogleDefaultTaxRule($calculated_shipping_tax_percentage, 'true'); $tax_rule_for_shipping->SetWorldArea(true); $cart->AddDefaultTaxRules($tax_rule_for_shipping); } // Shipping Cost if ($order->order_shipping > 0) { $ship_1 = new GoogleFlatRateShipping($order->shipping_method, number_format($order->order_shipping, 2)); $restriction_1 = new GoogleShippingFilters(); $restriction_1->SetAllowedWorldArea(true); $ship_1->AddShippingRestrictions($restriction_1); $cart->AddShipping($ship_1); } // Cart Contents $item_loop = 0; $myvat = array(); if (sizeof($order->get_items()) > 0) { foreach ($order->get_items() as $item) { $_product = new WC_Product($item['id']); if ($_product->exists() && $item['qty']) { $item_loop++; // Change tax format from 25.00 to 0.25 $item_tax_percentage = number_format($order->get_item_tax($item, false) / $order->get_item_total($item, false, false) * 100, 2, '.', ''); $item_vat = $item_tax_percentage / 100; $myvat[$item_loop] = $item_vat; ${"item_" . $item_loop} = new GoogleItem($item['name'], "", $item['qty'], $order->get_item_total($item, false, false)); // Name the alternate-tax-table $vat_name = "vat" . $item_vat; ${"item_" . $item_loop}->SetMerchantItemId($item['id']); ${"item_" . $item_loop}->SetTaxTableSelector($vat_name); $cart->AddItem(${"item_" . $item_loop}); } } } // Discount if ($order->order_discount > 0) { $item_loop++; ${"item_" . $item_loop} = new GoogleItem(__('Discount', 'woothemes'), "", "1", -$order->order_discount); ${"item_" . $item_loop}->SetTaxTableSelector("no_tax"); $cart->AddItem(${"item_" . $item_loop}); } // Tax // Loops through all tax classes that has been added to the cart and add these as Alternate tax tables to google Checkout. $taxrule_loop = 1; $no_duplicate_vat = array_unique($myvat); foreach ($no_duplicate_vat as $value) { // Name the alternate-tax-table $vat_name = "vat" . $value; $tax_table = new GoogleAlternateTaxTable($vat_name); ${"tax_rule_" . $taxrule_loop} = new GoogleAlternateTaxRule($value); ${"tax_rule_" . $taxrule_loop}->SetWorldArea(true); $tax_table->AddAlternateTaxRules(${"tax_rule_" . $taxrule_loop}); $cart->AddAlternateTaxTables($tax_table); $taxrule_loop++; } // The form return $cart->CheckoutButtonCode("SMALL") . '<script type="text/javascript"> jQuery(function(){ jQuery("body").block( { message: "<img src=\\"' . $woocommerce->plugin_url() . '/assets/images/ajax-loader.gif\\" alt=\\"Redirecting...\\" />' . __('Thank you for your order. We are now redirecting you to Google Checkout to make payment.', 'woothemes') . '", overlayCSS: { background: "#fff", opacity: 0.6 }, css: { padding: 20, textAlign: "center", color: "#555", border: "3px solid #aaa", backgroundColor:"#fff", cursor: "wait", lineHeight: "32px" } }); jQuery("#submit_googlecheckout_payment_form").click(); }); </script>'; }
function process_button() { global $osC_ShoppingCart, $osC_Tax, $osC_Language, $osC_Currencies, $osC_Session; require_once 'includes/classes/product.php'; require_once 'ext/googlecheckout/googlecart.php'; require_once 'ext/googlecheckout/googleitem.php'; require_once 'ext/googlecheckout/googleshipping.php'; $cart = new GoogleCart(MODULE_PAYMENT_GCHECKOUT_MERCHANT_ID, MODULE_PAYMENT_GCHECKOUT_MERCHANT_KEY, MODULE_PAYMENT_GCHECKOUT_SERVER, MODULE_PAYMENT_GCHECKOUT_CURRENCY); //transfer the whole cart if (MODULE_PAYMENT_GCHECKOUT_TRANSFER_CART == '1') { //products $products = $osC_ShoppingCart->getProducts(); foreach ($products as $product) { $name = $product['name']; //gift certificate if ($product['type'] == PRODUCT_TYPE_GIFT_CERTIFICATE) { $name .= "\n" . ' - ' . $osC_Language->get('senders_name') . ': ' . $product['gc_data']['senders_name']; if ($product['gc_data']['type'] == GIFT_CERTIFICATE_TYPE_EMAIL) { $name .= "\n" . ' - ' . $osC_Language->get('senders_email') . ': ' . $product['gc_data']['senders_email']; } $name .= "\n" . ' - ' . $osC_Language->get('recipients_name') . ': ' . $product['gc_data']['recipients_name']; if ($product['gc_data']['type'] == GIFT_CERTIFICATE_TYPE_EMAIL) { $name .= "\n" . ' - ' . $osC_Language->get('recipients_email') . ': ' . $product['gc_data']['recipients_email']; } $name .= "\n" . ' - ' . $osC_Language->get('message') . ': ' . $product['gc_data']['message']; } //variants $variants_array = array(); if ($osC_ShoppingCart->hasVariants($product['id'])) { foreach ($osC_ShoppingCart->getVariants($product['id']) as $variants) { $variants_array[$variants['groups_id']] = $variants['variants_values_id']; $name .= "\n" . ' - ' . $variants['groups_name'] . ': ' . $variants['values_name']; } } //get tax $tax = $osC_Tax->getTaxRate($product['tax_class_id'], $osC_ShoppingCart->getTaxingAddress('country_id'), $osC_ShoppingCart->getTaxingAddress('zone_id')); if (DISPLAY_PRICE_WITH_TAX == '1') { $price = $osC_Currencies->addTaxRateToPrice($product['final_price'], $tax); } else { $price = $product['final_price'] + osc_round($product['final_price'] * ($tax / 100), $osC_Currencies->currencies[DEFAULT_CURRENCY]['decimal_places']); } $osC_Product = new osC_Product($product['id']); $gitem = new GoogleItem($name, $osC_Product->getDescription(), intval($product['quantity']), $price); $gitem->SetMerchantPrivateItemData(new MerchantPrivateItemData(array('item' => base64_encode(serialize($product))))); $gitem->SetMerchantItemId($product['id']); $cart->AddItem($gitem); } //add order totals modules into gcheckout cart as item such as: coupon, gift certificate, low order fee //exclude modules: sub_total, tax, total and shipping module $shipping_cost = 0; foreach ($osC_ShoppingCart->getOrderTotals() as $total) { if (!in_array($total['code'], $this->_ignore_order_totals) && strstr($total['code'], 'shipping') === FALSE) { $gitem = new GoogleItem($total['title'], '', '1', $total['value'] + $total['tax']); $gitem->SetMerchantPrivateItemData(new MerchantPrivateItemData(array('order_total' => base64_encode(serialize($total))))); $cart->AddItem($gitem); } else { if (strstr($total['code'], 'shipping') !== FALSE) { $shipping_cost = $total['value'] + $total['tax']; } } } //shipping method $cart->AddShipping(new GooglePickUp($osC_ShoppingCart->getShippingMethod('title'), $shipping_cost)); } else { $gitem = new GoogleItem(STORE_NAME, '', 1, $osC_ShoppingCart->getTotal()); $gitem->SetMerchantPrivateItemData(new MerchantPrivateItemData(array('item' => base64_encode(serialize(STORE_NAME))))); $cart->AddItem($gitem); } //continue shopping url $cart->SetContinueShoppingUrl(osc_href_link(FILENAME_CHECKOUT, 'process', 'NOSSL', null, null, true)); //edit cart url $cart->SetEditCartUrl(osc_href_link(FILENAME_CHECKOUT, '', 'NOSSL', null, null, true)); // Request buyer's phone number $cart->SetRequestBuyerPhone(false); $private_data = $osC_Session->getID() . ';' . $osC_Session->getName(); $cart->SetMerchantPrivateData(new MerchantPrivateData(array('orders_id' => $this->_order_id, 'session-data' => $private_data))); // Display Google Checkout button return $cart->CheckoutButtonCode(); }
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; }