Exemple #1
0
function generate_checkout_btn($item_name, $item_description, $item_qty, $item_price, $diamonds, $callback_url = NULL)
{
    // Create a new shopping cart object
    $merchant_id = MERCHANT_ID;
    // Your Merchant ID
    $merchant_key = MERCHANT_KEY;
    // Your Merchant Key
    $server_type = CHECKOUT_SERVER_TYPE;
    $currency = CHECKOUT_CURRENCY;
    $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency);
    // Create an item to be added in cart
    $item_1 = new GoogleItem($item_name, $item_description, $item_qty, $item_price);
    // Add <merchant-private-item-data>
    //$item_1->SetMerchantPrivateItemData(new MerchantPrivateItemData(array("user-id" => $_SESSION['udid'])));
    $item_1->SetMerchantPrivateItemData(new MerchantPrivateItemData(array("user-id" => $_SESSION['udid'], "diamonds" => $diamonds)));
    // Add items to the cart
    $cart->AddItem($item_1);
    // Add <merchant-private-data>
    //$cart->SetMerchantPrivateData(new MerchantPrivateData(array("user-id" => $_SESSION['userID'])));
    // Specify "Return to xyz" link
    if ($callback_url != NULL) {
        $cart->SetContinueShoppingUrl($callback_url);
    } else {
        $cart->SetContinueShoppingUrl(CHECKOUT_COUNTINUE_URL . "?success=1&amount=" . $diamonds);
    }
    // Display a small size button
    return $cart->CheckoutButtonCode("small", true, "en_US", false);
}
    function TestGoogleCartSimple()
    {
        $Gcart = new googlecart('123', 'abc', "sandbox", 'GBP');
        $Gitem = new GoogleItem('Name', 'description', '3', '12.34');
        $Gitem->SetMerchantPrivateItemData(new MerchantPrivateItemData('PrivateItemData'));
        $Gitem->SetMerchantItemId('123-4321');
        //    $Gitem->SetTaxTableSelector('TaxableGood');
        $Gcart->AddItem($Gitem);
        $this->assertEquals(trim($Gcart->getXML()), trim('<?xml version="1.0" encoding="utf-8"?>
<checkout-shopping-cart xmlns="http://checkout.google.com/schema/2">
  <shopping-cart>
    <items>
      <item>
        <item-name>Name</item-name>
        <item-description>description</item-description>
        <unit-price currency="GBP">12.34</unit-price>
        <quantity>3</quantity>
        <merchant-private-item-data>PrivateItemData</merchant-private-item-data>
        <merchant-item-id>123-4321</merchant-item-id>
      </item>
    </items>
  </shopping-cart>
  <checkout-flow-support>
    <merchant-checkout-flow-support>
    </merchant-checkout-flow-support>
  </checkout-flow-support>
</checkout-shopping-cart>'));
    }
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;
    //
}
function GoogleSubscription()
{
    echo "<h2>Google Handled Subscription Request</h2>";
    $merchant_id = "";
    // Your Merchant ID
    $merchant_key = "";
    // Your Merchant Key
    $server_type = "sandbox";
    // or production
    $currency = "USD";
    $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency);
    $item = new GoogleItem("fee", "sign up fee", 1, 12.0);
    $subscription_item = new GoogleSubscription("google", "DAILY", 30.0);
    $recurrent_item = new GoogleItem("fee", "recurring fee", 1, 30.0);
    $subscription_item->SetItem($recurrent_item);
    $item->SetSubscription($subscription_item);
    $cart->AddItem($item);
    echo $cart->CheckoutButtonCode("MEDIUM");
}
Exemple #5
0
 /**
  * @param array $params
  * @param $component
  */
 public function doRecurCheckout(&$params, $component)
 {
     $intervalUnit = CRM_Utils_Array::value('frequency_unit', $params);
     if ($intervalUnit == 'week') {
         $intervalUnit = 'WEEKLY';
     } elseif ($intervalUnit == 'year') {
         $intervalUnit = 'YEARLY';
     } elseif ($intervalUnit == 'day') {
         $intervalUnit = 'DAILY';
     } elseif ($intervalUnit == 'month') {
         $intervalUnit = 'MONTHLY';
     }
     // Merchant ID
     $merchant_id = $this->_paymentProcessor['user_name'];
     // Merchant Key
     $merchant_key = $this->_paymentProcessor['password'];
     $server_type = $this->_mode == 'test' ? 'sandbox' : '';
     $itemName = CRM_Utils_Array::value('item_name', $params);
     $description = CRM_Utils_Array::value('description', $params);
     $amount = CRM_Utils_Array::value('amount', $params);
     $installments = CRM_Utils_Array::value('installments', $params);
     $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $params['currencyID']);
     $item = new GoogleItem($itemName, $description, 1, $amount);
     $subscription_item = new GoogleSubscription("merchant", $intervalUnit, $amount, $installments);
     $item->SetSubscription($subscription_item);
     $cart->AddItem($item);
     $this->submitPostParams($params, $component, $cart);
 }
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 UseCase3()
{
    //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 = new GoogleItem("MegaSound 2GB MP3 Player", "Portable MP3 player - stores 500 songs", 1, 175.49);
    $item->SetMerchantPrivateItemData("<color>blue</color><weight>3.2</weight>");
    $cart->AddItem($item);
    // Add merchant calculations options
    $cart->SetMerchantCalculations("http://200.69.205.154/~brovagnati/tools/unitTest/demo/responsehandlerdemo.php", "false", "true", "true");
    // accept-merchant-gift-certificates
    // Add merchant-calculated-shipping option
    $ship = new GoogleMerchantCalculatedShipping("2nd Day Air", 10.0);
    // Default, fallback price
    $restriction = new GoogleShippingFilters();
    $restriction->AddAllowedPostalArea("GB");
    $restriction->AddAllowedPostalArea("US");
    $restriction->SetAllowUsPoBox(false);
    $ship->AddShippingRestrictions($restriction);
    $address_filter = new GoogleShippingFilters();
    $address_filter->AddAllowedPostalArea("GB");
    $address_filter->AddAllowedPostalArea("US");
    $address_filter->SetAllowUsPoBox(false);
    $ship->AddAddressFilters($address_filter);
    $cart->AddShipping($ship);
    // Set default tax options
    $tax_rule = new GoogleDefaultTaxRule(0.15);
    $tax_rule->SetWorldArea(true);
    $cart->AddDefaultTaxRules($tax_rule);
    $cart->AddRoundingPolicy("UP", "TOTAL");
    // Display XML data
    // echo "<pre>";
    // echo htmlentities($cart->GetXML());
    // echo "</pre>";
    // Display a disabled, small button
    echo $cart->CheckoutButtonCode("SMALL", false);
}
 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 process()
 {
     $this->order->load($this->order->getReference());
     $results = $this->modelPayment->get_orderstatus_id($this->language->get('order_status_paid_unconfirmed'), $this->language->getId());
     //$sql = "select `order_status_id` from `order_status` where `name` = '?' and `language_id` = '?'";
     //$parsed = $this->database->parse($sql, $this->language->get('order_status_paid_unconfirmed'), $this->language->getId());
     //$results = $this->database->getRow($parsed);
     if ($results) {
         // copy cart and order-total to a new GoogleCart object
         $merchantId = $this->config->get('google_merchantid');
         $merchantKey = $this->config->get('google_merchantkey');
         chdir('library/google');
         require_once 'library/googlecart.php';
         require_once 'library/googleitem.php';
         require_once 'library/googleshipping.php';
         require_once 'library/googletax.php';
         $serverType = $this->config->get('google_test') ? 'sandbox' : 'production';
         $currencyGoogle = $this->config->get('google_currency');
         $currencyCart = $this->currency->getCode();
         $totalCart = $this->order->get('total');
         if ($currencyCart != $currencyGoogle) {
             $result = $this->modelPayment->get_currency($currencyCart);
             $baseValCart = isset($result['value']) ? $result['value'] : NULL;
             $result = $this->modelPayment->get_currency($currencyGoogle);
             $baseValGoogle = isset($result['value']) ? $result['value'] : NULL;
             if ($baseValCart == NULL || $baseValGoogle == NULL) {
                 // this should never happen, we use cart's currency let GoogleCheckout return an error
                 $totalGoogle = $totalCart;
                 $currencyGoogle = $currencyCart;
             } else {
                 // convert cart's total into the currency used by Google Checkout
                 $totalGoogle = round($totalCart * $baseValCart / $baseValGoogle);
             }
         } else {
             $totalGoogle = $totalCart;
         }
         $cart = new GoogleCart($merchantId, $merchantKey, $serverType, $currencyGoogle);
         $item_1 = new GoogleItem($this->config->get('config_store'), 'order# ' . $this->order->getReference(), 1, $totalGoogle);
         $item_1->SetTaxTableSelector("including all taxes");
         $cart->AddItem($item_1);
         $tax_table = new GoogleAlternateTaxTable("including all taxes");
         $tax_rule_1 = new GoogleAlternateTaxRule(0.0);
         $tax_rule_1->SetWorldArea(true);
         $tax_table->AddAlternateTaxRules($tax_rule_1);
         $cart->AddAlternateTaxTables($tax_table);
         //			$tax_rule_1 = new GoogleDefaultTaxRule(0.175);
         //			$tax_rule_1->SetWorldArea(true);
         //			$cart->AddDefaultTaxRules($tax_rule_1);
         // Have AlegroCart process the order and remove its cart from the session.
         // AlegroCart will store it in the database with a 'Paid Unconfirmed' order status.
         $this->order->process($results['order_status_id']);
         $this->cart->clear();
         // This will do a server-to-server Google cart post and send an HTTP 302 redirect status
         // More info http://code.google.com/apis/checkout/developer/index.html#alternate_technique
         list($status, $error) = $cart->CheckoutServer2Server();
         return TRUE;
         // If it reaches this point then something went wrong
         echo "An error had ocurred: <br />HTTP Status: " . $status . ":";
         echo "<br />Error message:<br />";
         echo $error;
         echo "<br />";
         exit;
     } else {
         // I think it may be better to die here with a message as it is
         // a major configuration problem that should be found by even
         // the most basic testing and hence not impact upon a customer.
         die('Configuration error: You MUST have created an order status for "Paid Unconfirmed" for every installed language.');
         //  The following is a reasonable alternative but there is no way without making
         //  changes to checkout_failure, to get a user defined message to the that page.
         //  The message, as above, is a big help in tracking any teething problems with this code.
         //$this->response->redirect($this->url->ssl('checkout_failure'));
     }
 }
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * This is an example for Merchant handled subscriptions.  This code will generate a 
 * recurrence request.
 */
chdir("..");
require_once 'library/googlerequest.php';
require_once 'library/googleitem.php';
define('RESPONSE_HANDLER_ERROR_LOG_FILE', 'googleerror.log');
define('RESPONSE_HANDLER_LOG_FILE', 'googlemessage.log');
$merchant_id = "";
// Your Merchant ID
$merchant_key = "";
// Your Merchant Key
$server_type = "sandbox";
// change this to go live
$currency = 'USD';
// set to GBP if in the UK
$certificate_path = "";
// set your SSL certificate path
$google_order_id = "";
// set your SSL CA cert path
$Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type, $currency);
$GRequest->SetCertificatePath($certificate_path);
$item1 = new GoogleItem("recurring item", "recurring item fee", 1, 30.0);
$item1->SetCurrency($currency);
$items = array($item1);
$Grequest->SendRecurrenceRequest($google_order_id, $items);
 public static function google_redirect($description, $amount, $user_id, $invoice_payment_id, $invoice_id, $currency_id)
 {
     chdir(dirname(__FILE__));
     //'includes/plugin_paymethod_google/');
     require_once 'library/googlecart.php';
     require_once 'library/googleitem.php';
     $server_type = self::is_sandbox() ? "sandbox" : '';
     $currency = module_config::get_currency($currency_id);
     self::add_payment_data($invoice_payment_id, 'log', 'Starting payment of ' . $server_type . ' in currency ' . $currency['code']);
     $cart = new GoogleCart(self::get_merchant_id(), self::get_merchant_key(), $server_type, $currency['code']);
     $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
     //  Key/URL delivery
     self::add_payment_data($invoice_payment_id, 'log', 'Adding ' . $total_count . 'x ' . $description . ' (' . $amount . ' ' . $currency['code'] . ')');
     $item_1 = new GoogleItem($description, "", $total_count, $amount);
     // Unit price
     //$item_1->SetURLDigitalContent(module_invoice::link_receipt($invoice_payment_id),
     $item_1->SetURLDigitalContent(module_invoice::link_public_print($invoice_id), '', _l("Payment Receipt"));
     $cart->AddItem($item_1);
     $private_data = new MerchantPrivateData(array('invoice_id' => $invoice_id, 'amount' => $amount, 'currency_id' => $currency_id, 'invoice_payment_id' => $invoice_payment_id));
     $cart->SetMerchantPrivateData($private_data);
     // Specify <edit-cart-url>
     $cart->SetEditCartUrl(module_invoice::link_public($invoice_id));
     // Specify "Return to xyz" link
     $cart->SetContinueShoppingUrl(module_invoice::link_public($invoice_id));
     // Request buyer's phone number
     //$cart->SetRequestBuyerPhone(true);
     // 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;
     exit;
 }
Exemple #12
0
//print_r($order_totals);
$tax_address = zen_get_tax_locations();
$ot_used = false;
foreach ($order_totals as $order_total) {
    if (!in_array($order_total['code'], $googlepayment->ot_ignore)) {
        // Cant used this since the OT is passed as an item, and tax cant be calculated
        $tax_class_id = @constant("MODULE_ORDER_TOTAL_" . substr(strtoupper($order_total['code']), 3) . "_TAX_CLASS");
        $tax = $db->Execute("select tax_class_title \n                         from " . TABLE_TAX_CLASS . " \n                         where tax_class_id = " . makeSqlInteger($tax_class_id));
        $tt = @$tax->fields['tax_class_title'];
        if (!empty($tt) && !in_array($tax_class_id, $tax_array)) {
            $tax_array[] = $tax_class_id;
            $tax_name_array[] = $tt;
        }
        $ot_value = $order_total['value'] * (strrpos($order_total['text'], '-') === false ? 1 : -1);
        //($order_total['text']{0}=='-'?-1:1);
        $Gitem = new GoogleItem($order_total['title'], '', '1', $currencies->get_value(DEFAULT_CURRENCY) * $ot_value, 'LB', 0);
        $Gitem->SetMerchantPrivateItemData(new MerchantPrivateItemData(array('order_total' => base64_encode(serialize($order_total)))));
        //print_r($order_total);
        if (!empty($tt)) {
            $Gitem->SetTaxTableSelector($tt);
        }
        // TaxTable with 0% Rate
        //    $Gitem->SetTaxTableSelector('_OT_cero_tax');
        //  This is a hack to avoid showing shipping when cart is virtual and an OT is added
        if ($cart->get_content_type() == 'virtual') {
            $Gitem->SetEmailDigitalDelivery('true');
        }
        $Gcart->AddItem($Gitem);
        $ot_used = true;
    }
}
		/**
		 * Build the representation of the shopping cart using the google checkout objects
		 *
		 * @return void
		 **/
		private function BuildCart()
		{
			if ($this->cart === null) {
				include_once(dirname(__FILE__).'/library/googlecart.php');
				include_once(dirname(__FILE__).'/library/googleitem.php');

				$id = trim($this->GetValue('merchantid'));
				$key =trim($this->GetValue('merchanttoken'));

				$currency = $this->GetDefaultCurrencyCode();

				$this->cart = new GoogleCart($id, $key, $this->_server_type, $currency);
				$this->cart->SetMerchantPrivateData($_COOKIE['SHOP_SESSION_TOKEN']);
				$this->cart->SetEditCartUrl(GetConfig('ShopPath').'/cart.php');
				$this->cart->SetContinueShoppingUrl(GetConfig('ShopPath'));
				$this->cart->SetRequestBuyerPhone('true');

				// Add tax rules
				$this->AddTaxInformationToCart();

				// Add the analytics tracking to the cart
				$this->AddAnalyticsToCart();

				// Merchant calculations are only available for US based stores
				if ($this->GetDefaultCurrencyCode() == 'USD') {
					$this->cart->SetMerchantCalculations($this->xmlUrl, "true", "true", "true");
				} else {
					$this->cart->SetMerchantCalculations($this->xmlUrl, "false", "false", "false");
				}

				$coupon_discount = 0;
				$items_total = 0;

				$quote = getCustomerQuote();
				$items = $quote->getItems();

				foreach($items as $item) {
					$description = '';

					if(!$this->canSellItem($item))
					{
						$this->buttonVariant = false;
						return;
					}

					if($item->getVariationId() > 0) {
						$options = $item->getVariationOptions();
						foreach($options as $name => $value) {
							$description .= $name.': '.$value.', ';
						}
						$description = rtrim($description, ', ');
					}

					$googleItem = new GoogleItem(
						$item->getName(),
						$description,
						$item->getQuantity(),
						$item->getPrice(false),
						$item->getWeight()
					);

					if($item->getTaxClassId()) {
						$googleItem->setTaxTableSelector($item->getTaxClassId());
					}

					// If this item is a digital item or gift certificate then mark it as email delivery
					if($item->getType() == PT_DIGITAL || $item->getType() == PT_GIFTCERTIFICATE) {
						$googleItem->setEmailDigitalDelivery(true);
					}

					$this->cart->AddItem($googleItem);

					// does this item have gift wrapping? Add it as a line item
					$giftWrapping = $item->getGiftWrapping();
					if($giftWrapping) {
						$googleItem = new GoogleItem(
							'Gift Wrapping: '.$giftWrapping['wrapname'],
							$giftWrapping['wrapmessage'],
							$item->getQuantity(),
							$item->getWrappingCost()
						);
						$this->cart->AddItem($googleItem);
					}
				}

				// Send across any applied gift certificates from the store
				// Disabled - Gift certificate amounts need to be dynamic to
				// account for changes in tax, shipping and discounts which
				// can all change on the google check out page. This method
				// only allows us to send a static value. Gift certificates
				// must be re-applied on the google checkout page.
				/*
				$giftCertificates = $quote->getAppliedGiftCertificates();
				if(!empty($giftCertificates)) {
					foreach($giftCertificates as $giftCertificate) {
						$giftCertificateName = getLang('GiftCertificate').' ('.$giftCertificate['code'].')';
						$googleItem = new GoogleItem(
							$giftCertificateName, '', 1, $giftCertificate['used'] * -1
						);
						$googleItem->setEmailDigitalDelivery(true);
						$this->cart->addItem($googleItem);
					}
				}*/

				// send across applied coupons
				$coupons = $quote->getAppliedCoupons();
				if(!empty($coupons)) {
					foreach($coupons as $coupon) {
						$googleItem = new Googleitem(
							getLang('Coupon').' ('.$coupon['code'].')', '', 1,
							$coupon['totalDiscount'] * -1
						);

						// free or discounted shipping coupon, add a zero cost item
						// handle shipping rate adjustment via merchant callback later
						if ($coupon['discountType'] == 3 || $coupon['discountType'] == 4) {
							$desc = getLang('GoogleCheckoutDiscountShippingCoupon', $coupon);
							$googleItem = new Googleitem($desc, '', 1, 0);
						}

						$itemData = array(
							'type' => 'coupon',
							'code' => $coupon['code']);

						$googleItem->setMerchantPrivateItemData(json_encode($itemData));
						$this->cart->addItem($googleItem);
					}
				}

				// is there a subtotal discount? (discount rule. eg $X off for orders over $Y)
				if($quote->getDiscountAmount() > 0) {
					$googleItem = new GoogleItem(
						getLang('GoogleCheckoutDiscountOther'), '', 1,
						$quote->getDiscountAmount() * -1
					);
					$googleItem->setEmailDigitalDelivery(true);
					$this->cart->addItem($googleItem);
				}

				if(!$quote->isDigital()) {
					$this->AddShippingInformationToCart();
				}
				else {
					$this->AddDigitalShippingInformationToCart();
				}

				$this->DebugLog($this->cart->GetXML());
			}
		}
Exemple #14
0
     $international_shipping_price = nzshpcrt_determine_base_shipping(0, get_option('base_country') . "-");
     $google_international_shipping = $international_shipping_price + $pnp * $_POST["quantity"];
     $google_cart->shipping_arr[0]->price = $google_local_shipping;
     $google_cart->shipping_arr[1]->price = $google_international_shipping;
     $google_cart->item_arr[$_POST["key"]]->quantity = $_POST["quantity"];
 }
 $state_name = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "region_tax WHERE country_id='136'", ARRAY_A);
 // 	echo "<pre>".print_r($tax_rate,1)."</pre>";
 foreach ($state_name as $state) {
     // 		$tax_rate = $wpdb->get_results("SELECT tax FROM ".$wpdb->prefix."region_tax WHERE id='".$state['id']."'",ARRAY_A);
     $tax_rule = new GoogleDefaultTaxRule($state['tax'] / 100);
     $tax_rule->SetStateAreas($state['code']);
     $google_cart->AddDefaultTaxRules($tax_rule);
 }
 if ($discount > 0) {
     $google_item = new GoogleItem(utf8_decode("Coupon Code: '" . $_SESSION['coupon_num'] . "'"), utf8_decode("A coupon redeem"), 1, -$discount);
     // Unit price
     //echo serialize($cart_item->product_variations);
     $google_item->SetMerchantPrivateItemData("Coupon Deduction");
     $google_cart->AddItem($google_item);
 }
 //exit("---><pre>".print_r($_SESSION,1)."</pre>");
 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';
     }
 }
 /**
  * Build the representation of the shopping cart using the google checkout objects
  *
  * @return void
  **/
 private function BuildCart()
 {
     if ($this->cart === null) {
         include_once dirname(__FILE__) . '/library/googlecart.php';
         include_once dirname(__FILE__) . '/library/googleitem.php';
         $id = $this->GetValue('merchantid');
         $key = $this->GetValue('merchanttoken');
         $currency = $this->GetDefaultCurrencyCode();
         $this->cart = new GoogleCart($id, $key, $this->_server_type, $currency);
         $this->cart->SetMerchantPrivateData($_COOKIE['SHOP_SESSION_TOKEN']);
         $this->cart->SetEditCartUrl($GLOBALS['ShopPathSSL'] . '/cart.php');
         $this->cart->SetContinueShoppingUrl($GLOBALS['ShopPath']);
         $this->cart->SetRequestBuyerPhone('true');
         // Add tax rules
         $this->AddTaxInformationToCart();
         // Add the analytics tracking to the cart
         $this->AddAnalyticsToCart();
         // Merchant calculations are only available for US based stores
         if ($this->GetDefaultCurrencyCode() == 'USD') {
             $this->cart->SetMerchantCalculations($this->xmlUrl, "true", "true", "true");
         } else {
             $this->cart->SetMerchantCalculations($this->xmlUrl, "false", "false", "false");
         }
         $coupon_discount = 0;
         $items_total = 0;
         $GLOBALS['ISC_CLASS_CART'] = GetClass('ISC_CART');
         $items = $GLOBALS['ISC_CLASS_CART']->api->GetProductsInCart();
         /*
         $cprint = print_r($items, true);     
         $q      = "INSERT INTO isc_orderlogs (`ordervalue`) VALUES ('$cprint')";
         $r      = $GLOBALS["ISC_CLASS_DB"]->Query($q);
         */
         foreach ($items as $item) {
             $item_price = $item['product_price'];
             if (GetConfig('TaxTypeSelected') == 2) {
                 // The product price is already 100% + tax rate, so we need to get it back to what
                 // it was before tax was applied
                 $item_price = $item_price / (100 + GetConfig('DefaultTaxRate')) * 100;
             }
             if (isset($item['discount_price'])) {
                 $coupon_discount += ($item['product_price'] - $item['discount_price']) * $item['quantity'];
                 //* $item['quantity'] Added by Simha to calculate discount for all quantity of the products
             }
             $items_total += $item_price * $item['quantity'];
             // Gift certificates won't have a weight set
             if (!isset($item['data']['prodweight'])) {
                 $item['data']['prodweight'] = 0;
             }
             // Build a description using the product variation data
             $description = "";
             if (isset($item['options']) && !empty($item['options'])) {
                 foreach ($item['options'] as $name => $value) {
                     if ($description != "") {
                         $description .= ", ";
                     }
                     $description .= $name . ": " . $value;
                 }
             }
             $google_item = new GoogleItem($item['product_name'], $description, $item['quantity'], $item_price, $item['data']['prodweight']);
             if ($item['data']['prodtype'] == PT_DIGITAL || $item['data']['prodtype'] == PT_GIFTCERTIFICATE) {
                 $google_item->SetEmailDigitalDelivery(true);
             }
             $this->cart->AddItem($google_item);
             /* To add complementary product to Google checkout -- Baskaran*/
             if ($item['compitem'] == 1) {
                 for ($y = 0; $y < count($item['complementary']); $y++) {
                     if ($item['product_id'] == $item['complementary'][$y]['comp_mainproductid']) {
                         $compprodname = $item['complementary'][$y]['comp_product_name'];
                         $compprodprice = $item['complementary'][$y]['comp_original_price'];
                         $compqty = $item['complementary'][$y]['quantity'];
                         $description = "Complementary Product";
                         $weight = 1;
                         $complementary_google_item = new GoogleItem($compprodname, $description, $compqty, $compprodprice, $weight);
                         if ($item['data']['prodtype'] == PT_DIGITAL || $item['data']['prodtype'] == PT_GIFTCERTIFICATE) {
                             $complementary_google_item->SetEmailDigitalDelivery(true);
                         }
                         $this->cart->AddItem($complementary_google_item);
                     }
                 }
             }
             /* Code Ends */
             // does this item have gift wrapping?
             if (isset($item['wrapping'])) {
                 $wrapping = $item['wrapping'];
                 $wrap_price = $wrapping['wrapprice'];
                 if (GetConfig('TaxTypeSelected') == 2) {
                     // The product price is already 100% + tax rate, so we need to get it back to what
                     // it was before tax was applied
                     $wrap_price = $wrap_price / (100 + GetConfig('DefaultTaxRate')) * 100;
                 }
                 $google_item = new GoogleItem("Gift Wrapping: " . $wrapping['wrapname'], $wrapping['wrapmessage'], $item['quantity'], $wrap_price);
                 $this->cart->AddItem($google_item);
             }
         }
         if (isset($_SESSION['CART']['GIFTCERTIFICATES']) && is_array($_SESSION['CART']['GIFTCERTIFICATES'])) {
             foreach ($_SESSION['CART']['GIFTCERTIFICATES'] as $giftcert) {
                 $giftcertname = GetLang('GiftCertificate') . ' (' . $giftcert['giftcertcode'] . ')';
                 $google_item = new GoogleItem($giftcertname, '', 1, min($giftcert['giftcertbalance'], $items_total) * -1);
                 $google_item->SetEmailDigitalDelivery(true);
                 $this->cart->AddItem($google_item);
             }
         }
         if ($coupon_discount > 0) {
             $google_item = new GoogleItem(GetLang('GoogleCheckoutDiscountFromCoupons'), '', 1, $coupon_discount * -1);
             $google_item->SetEmailDigitalDelivery(true);
             $this->cart->AddItem($google_item);
         }
         $GLOBALS['ISC_CLASS_CHECKOUT'] = GetClass('ISC_CHECKOUT');
         $orderSummary = $GLOBALS['ISC_CLASS_CHECKOUT']->CalculateOrderSummary();
         // Add shipping information
         if ($orderSummary['digitalOrder'] == 0) {
             $this->AddShippingInformationToCart();
         } else {
             $this->AddDigitalShippingInformationToCart();
         }
         $this->DebugLog($this->cart->GetXML());
     }
 }
function showCart()
{
    session_start();
    $user = $_SESSION['userid'];
    $cart = $_SESSION[$user . 'cart'];
    //No payment Checkout
    //----------------------------------
    $genericCart = new GenericCart();
    //----------------------------------
    //Google Checkout
    //----------------------------------
    $config_file = "checkout/google_checkout/google.conf";
    $comment = "#";
    $fp = fopen($config_file, "r");
    while (!feof($fp)) {
        $line = trim(fgets($fp));
        if ($line && !ereg("^{$comment}", $line)) {
            list($option, $value) = split("=", $line, 2);
            $config_values[$option] = $value;
        }
    }
    fclose($fp);
    $merchant_id = $config_values['CONFIG_MERCHANT_ID'];
    $merchant_key = $config_values['CONFIG_MERCHANT_KEY'];
    $server_type = $config_values['CONFIG_SERVER_TYPE'];
    $currency = $config_values['CONFIG_CURRENCY'];
    $editCartURL = $config_values['CONFIG_EDIT_URL'];
    $continueShoppingURL = $config_values['CONFIG_CONTINUE_URL'];
    $googlecart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency);
    $googlecart->SetEditCartUrl($editCartURL);
    $googlecart->SetContinueShoppingUrl($continueShoppingURL);
    //----------------------------------
    if ($cart) {
        $items = explode(',', $cart);
        $contents = array();
        foreach ($items as $item) {
            $contents[$item] = isset($contents[$item]) ? $contents[$item] + 1 : 1;
        }
        $formattedShopCartItems = array();
        $result = array();
        foreach ($contents as $i => $qty) {
            $type = substr($i, 0, 1);
            $id = substr($i, 2);
            $item = refactored_db_getItem($id);
            $subtotal = $item['price'] * $qty;
            $scitem = array($item['name'], $item['description'], $item['price'], $qty, $i, $subtotal, $item['id'], $type);
            array_push($formattedShopCartItems, $scitem);
            //No payment Checkout
            //----------------------------------
            if (!$item['billable']) {
                $genericItem = new GenericItem($item['name'], $item['description'], $qty, 0);
                // Unit price
                $genericCart->AddItem($genericItem);
            }
            //----------------------------------
            //Google Checkout
            //----------------------------------
            if ($item['billable']) {
                $googleitem = new GoogleItem($item['name'], $item['description'], $qty, $item['price']);
                // Unit price
                $googleitem->SetMerchantItemId($item['id']);
                //TODO:Change email to order email
                $googleitem->SetEmailDigitalDelivery("*****@*****.**");
                $googlecart->AddItem($googleitem);
            }
            //----------------------------------
        }
    }
    //Checkout Buttons
    $output[] = '<div id="checkoutButtonsContainer">';
    $buttonsCount = 0;
    if (count($genericCart->item_arr)) {
        $buttonsCount++;
        $output[] = $genericCart->CheckoutButtonCode();
    }
    if (count($googlecart->item_arr)) {
        $buttonsCount++;
        $output[] = $googlecart->CheckoutButtonCode("SMALL");
        $output[] = "<div class='ui-state-error' style='padding: 0pt 0.7em; float:left; width:30em;'><p><span class='ui-icon ui-icon-alert' style='float: left; margin-right: 0.3em;'></span>Please when you process the order with Google Checkout, <strong>DO NOT</strong> choose the option 'Keep my e-mail address confidential' because your order will be lost.</p></div>";
    }
    $output[] = '</div>';
    $shoppingCart = $formattedShopCartItems;
    $checkoutButtons = join('', $output);
    $response = array("shoppingCart" => json_encode($formattedShopCartItems), "checkoutButtons" => $checkoutButtons, "buttonsCount" => $buttonsCount);
    $_SESSION[$user . 'cart'] = $cart;
    return $response;
}
 foreach ($orderItemsSuccess as $ois) {
     $Gresponse->log->LogResponse("id " . $ois["id"] . " - success: " . $ois["success"]);
     //If item could not be saved in web service, it should be deleted form the order summary
     if (!$ois["success"]) {
         //cancel order item
         db_cancelOrderItem($dborder->id, $ois["id"]);
         //get item from database
         $dbItem = db_getItem($ois["id"]);
         $Gresponse->log->LogResponse("Get Order Item " . $dbItem->id . " from " . $dborder->ordernumber);
         //get item details
         $dbOrderItem = db_getOrderItem($dborder->ordernumber, $dbItem->id);
         $Gresponse->log->LogResponse("Creating Google item " . $dbItem->name);
         $Gresponse->log->LogResponse("quantity: " . $dbOrderItem->quantity);
         $Gresponse->log->LogResponse("price: " . $dbItem->price);
         //create a google item
         $gitem = new GoogleItem($dbItem->name, $dbItem->description, $dbOrderItem->quantity, $dbItem->price);
         // Unit price
         $refundAmount += $dbOrderItem->quantity * $dbItem->price;
         $Gresponse->log->LogResponse("refund subtotal: " . $refundAmount);
         //set item unique id
         $Gresponse->log->LogResponse("Set Merchant Id" . $dbItem->id);
         $gitem->SetMerchantItemId($dbItem->id);
         array_push($itemsToCancel, $gitem);
     }
 }
 if (count($itemsToCancel) > 0) {
     //Compare total quantity of order items with cancel items to update order status
     $orderItems = db_getOrderItems($dborder->id);
     $Gresponse->log->LogResponse("From " . count($orderItems) . " items, " . count($itemsToCancel) . " will be cancelled");
     $response = $Grequest->SendRefundOrder($dborder->ordernumber, $refundAmount, "Items could not be processed in Quota System. The most common reason " . "is that there were not enough resources to satisfy this request", "Contact the administrator for further details.");
     $response = $Grequest->SendCancelItems($dborder->ordernumber, $itemsToCancel, "Items could not be processed in Quota System. The most common reason " . "is that there were not enough resources to satisfy this request");
function nzshpcrt_shopping_basket_internals($cart, $quantity_limit = false, $no_title = false)
{
    global $wpdb;
    if (get_option('permalink_structure') != '') {
        $seperator = "?";
    } else {
        $seperator = "&amp;";
    }
    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('&trade;'));
            $product['name'] = str_replace("™", "&trade;", $product['name']);
            $product['description'] = str_replace("™", "&trade;", $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> &nbsp;&nbsp;" . 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 = "&amp;";
        }
        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'] . "&amp;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;
}