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'));
     }
 }
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();
}
Exemple #3
0
    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;
    }
}
//if($ot_used) {
//  $GAtaxTable_OT = new GoogleAlternateTaxTable('_OT_cero_tax');
//  $GAtaxRule = new GoogleAlternateTaxRule('0');
//  $GAtaxRule->SetWorldArea();