Exemplo n.º 1
1
 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;
 }
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;
    //
}
Exemplo n.º 3
0
    //                          $currencies->get_value(DEFAULT_CURRENCY) * $products[$i]['final_price']);
    $Gitem->SetMerchantPrivateItemData(new MerchantPrivateItemData(array('item' => base64_encode(serialize($order_items[$i])))));
    $Gitem->SetMerchantItemId($products[$i]['id']);
    if (!empty($tt)) {
        $Gitem->SetTaxTableSelector($tt);
    }
    // Is downloadable product?
    $attr_query = "SELECT count(*) cant FROM " . TABLE_PRODUCTS . " p\n    inner join " . TABLE_PRODUCTS_ATTRIBUTES . " pa on pa.products_id = p.products_id\n    inner join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad on pad.products_attributes_id = pa.products_attributes_id\n    where pa.products_id = '" . (int) $products[$i]['id'] . "'";
    $product_download = $db->Execute($attr_query);
    // Is virtual product?
    $product_query = "select products_virtual\n                      from " . TABLE_PRODUCTS . "\n                      where products_id = '" . (int) $products[$i]['id'] . "'";
    $product_virtual = $db->Execute($product_query);
    if ($product_virtual->fields['products_virtual'] == 1 || $product_download->fields['cant'] > 0) {
        //    $Gitem->SetEmailDigitalDelivery('true');
        $digital_url = str_replace("&amp;", "&", zen_href_link('checkout_success', '', 'NONSSL'));
        $Gitem->SetURLDigitalContent($digital_url, '', $products_name . " " . $products_description . "<br />" . GOOGLECHECKOUT_STRING_EXTRA_DIGITAL_CONTENT);
    }
    $Gcart->AddItem($Gitem);
    // Stock Check
    if (STOCK_CHECK == 'true') {
        if (zen_check_stock($products[$i]['id'], $products[$i]['quantity'])) {
            $flagAnyOutOfStock = true;
        }
    }
    $product_list .= ";" . (int) $products[$i]['id'];
    if (in_array($products[$i]['category'], $resticted_categories)) {
        $Gcart->SetButtonVariant(false);
        $Gwarnings[] = GOOGLECHECKOUT_STRING_WARN_RESTRICTED_CATEGORY;
        break;
    }
}