コード例 #1
0
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;
    //
}
コード例 #2
0
 /**
  * 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());
     }
 }
コード例 #3
0
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;
}
コード例 #4
0
ファイル: gcheckout.php プロジェクト: happyxlq/lt_svn
            $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;
    }
}
//if($ot_used) {
//  $GAtaxTable_OT = new GoogleAlternateTaxTable('_OT_cero_tax');
//  $GAtaxRule = new GoogleAlternateTaxRule('0');
//  $GAtaxRule->SetWorldArea();
//  $GAtaxTable_OT->AddAlternateTaxRules($GAtaxRule);
//  $Gcart->AddAlternateTaxTables($GAtaxTable_OT);
//}
// Out of Stock
if (STOCK_ALLOW_CHECKOUT != 'true' && $flagAnyOutOfStock == true) {
    $Gcart->SetButtonVariant(false);