commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / packages / Google / demo / sampcodetest.php
1 <?php
2 /*
3 * Created on May 9, 2008
4 *
5 * To change the template for this generated file go to
6 * Window - Preferences - PHPeclipse - PHP - Code Templates
7 */
8
9 // Point to the correct directory
10 chdir("..");
11 // Include all the required files
12 require_once('library/googlecart.php');
13 require_once('library/googleitem.php');
14 require_once('library/googleshipping.php');
15 require_once('library/googletax.php');
16 UseCase2();
17
18 function UseCase2() {
19 // Create a new shopping cart object
20 $merchant_id = ""; // Your Merchant ID
21 $merchant_key = ""; // Your Merchant Key
22 $server_type = "sandbox";
23 $currency = "USD";
24 $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency);
25
26 // Add items to the cart
27 $item_1 = new GoogleItem("Dry Food Pack AA1453",
28 "A pack of highly nutritious dried food for emergency", 2, 24.99);
29 $item_1->SetTaxTableSelector("food");
30
31 $item_2 = new GoogleItem("MegaSound 2GB MP3 Player",
32 "Portable MP3 player - stores 500 songs", 1, 175.49);
33 $item_2->SetMerchantPrivateItemData(
34 new MerchantPrivateItemData(array("color" => "blue",
35 "weight" => "3.2")));
36 $item_2->SetMerchantItemId("Item#012345");
37
38 $cart->AddItem($item_1);
39 $cart->AddItem($item_2);
40
41 // Add shipping options
42 $ship_1 = new GoogleFlatRateShipping("Ground", 15);
43 $restriction_1 = new GoogleShippingFilters();
44 $restriction_1->SetAllowedWorldArea(true);
45 $ship_1->AddShippingRestrictions($restriction_1);
46
47 $ship_2 = new GooglePickup("Pick Up", 5);
48
49 $cart->AddShipping($ship_1);
50 $cart->AddShipping($ship_2);
51
52 // Add default tax rules
53 $tax_rule_1 = new GoogleDefaultTaxRule(0.17);
54 $tax_rule_1->AddPostalArea("GB", "SW*");
55 $tax_rule_1->AddPostalArea("FR");
56 $tax_rule_1->AddPostalArea("DE");
57
58 $tax_rule_2 = new GoogleDefaultTaxRule(0.10);
59 $tax_rule_2->SetWorldArea(true);
60
61 $cart->AddDefaultTaxRules($tax_rule_1);
62 $cart->AddDefaultTaxRules($tax_rule_2);
63
64 // Add alternate tax table
65 $tax_table = new GoogleAlternateTaxTable("food");
66
67 $tax_rule_1 = new GoogleAlternateTaxRule(0.05);
68 $tax_rule_1->AddPostalArea("GB");
69 $tax_rule_1->AddPostalArea("FR");
70 $tax_rule_1->AddPostalArea("DE");
71
72 $tax_rule_2 = new GoogleAlternateTaxRule(0.03);
73 $tax_rule_2->SetWorldArea(true);
74
75 $tax_table->AddAlternateTaxRules($tax_rule_1);
76 $tax_table->AddAlternateTaxRules($tax_rule_2);
77
78 $cart->AddAlternateTaxTables($tax_table);
79
80 // Add <merchant-private-data>
81 $cart->SetMerchantPrivateData(
82 new MerchantPrivateData(array( "animals" => array( "type" => "cat,dog" ))));
83
84 // Specify <edit-cart-url>
85 $cart->SetEditCartUrl("http://www.example.com/edit");
86
87 // Specify "Return to xyz" link
88 $cart->SetContinueShoppingUrl("http://www.example.com/continue");
89
90 // Request buyer's phone number
91 $cart->SetRequestBuyerPhone(true);
92
93 // Define rounding policy
94 $cart->AddRoundingPolicy("CEILING", "TOTAL");
95
96 // Display XML data
97 // echo "<pre>";
98 // echo htmlentities($cart->GetXML());
99 // echo "</pre>";
100
101 // Display a medium size button
102 echo $cart->GetXML();
103 }
104 ?>