commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / packages / Google / demo / cartdemo.php
1 <?php
2
3 /**
4 * Copyright (C) 2007 Google Inc.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 // Point to the correct directory
20 chdir("..");
21 // Include all the required files
22 require_once('library/googlecart.php');
23 require_once('library/googleitem.php');
24 require_once('library/googleshipping.php');
25 require_once('library/googletax.php');
26
27 // Invoke any of the provided use cases
28 // UseCase1();
29 // UseCase2();
30 // UseCase3();
31 Usecase();
32 DigitalUsecase();
33 CarrierCalcUsecase();
34
35 function Usecase() {
36 echo "<h2>Standard Checkout Request</h2>";
37 $merchant_id = ""; // Your Merchant ID
38 $merchant_key = ""; // Your Merchant Key
39 $server_type = "sandbox";
40 $currency = "USD";
41 $cart = new GoogleCart($merchant_id, $merchant_key, $server_type,
42 $currency);
43 $total_count = 12;
44
45 $item_1 = new GoogleItem("item name", // Item name
46 "item desc", // Item description
47 $total_count, // Quantity
48 10); // Unit price
49 $cart->AddItem($item_1);
50
51 // Add shipping options
52 if($total_count < 3){
53 $ship_1 = new GoogleFlatRateShipping("USPS Priority Mail", 4.55);
54 }else{
55 $ship_1 = new GoogleFlatRateShipping("USPS Priority Mail", 6.2);
56 }
57 $Gfilter = new GoogleShippingFilters();
58 $Gfilter->SetAllowedCountryArea('CONTINENTAL_48');
59
60 $ship_1->AddShippingRestrictions($Gfilter);
61
62 $cart->AddShipping($ship_1);
63
64 // Add tax rules
65 $tax_rule = new GoogleDefaultTaxRule(0.05);
66 $tax_rule->SetStateAreas(array("MA"));
67 $cart->AddDefaultTaxRules($tax_rule);
68
69 // Specify <edit-cart-url>
70 $cart->SetEditCartUrl("https://www.example.com/cart/");
71
72 // Specify "Return to xyz" link
73 $cart->SetContinueShoppingUrl("https://www.example.com/goods/");
74
75 // Request buyer's phone number
76 $cart->SetRequestBuyerPhone(true);
77
78 // Display Google Checkout button
79 echo $cart->CheckoutButtonCode("SMALL");
80 }
81
82 // The idea of this usecase is to show how to implement Server2Server
83 // Checkout API Requests
84 // http://code.google.com/apis/checkout/developer/index.html#alternate_technique
85 // It will only display the GC button, and when you click on it it will redirect
86 // to a script ('digitalCart.php') that will create the cart, send it to google
87 // Checkout and redirect the buyer to the corresponding page
88 function DigitalUsecase() {
89 echo "<h2>Server 2 Server Checkout Request</h2>";
90 $merchant_id = ""; // Your Merchant ID
91 $merchant_key = ""; // Your Merchant Key
92 $server_type = "sandbox";
93 $currency = "USD";
94 $cart = new GoogleCart($merchant_id, $merchant_key, $server_type,$currency);
95
96 echo $cart->CheckoutServer2ServerButton('digitalCart.php');
97 }
98
99 function CarrierCalcUsecase() {
100 echo "<h2>Carrier Calculation Checkout Request</h2>";
101 // Create a new shopping cart object
102 $merchant_id = ""; // Your Merchant ID
103 $merchant_key = ""; // Your Merchant Key
104 $server_type = "sandbox";
105 $currency = "USD";
106 $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency);
107
108 // Add items to the cart
109 $item_1 = new GoogleItem("MegaSound 2GB MP3 Player", // Item name
110 "Portable MP3 player - stores 500 songs", // Item description
111 2, // Quantity
112 175.49,// Unit price
113 'LB',
114 15); //weigth
115 $item_1->SetMerchantItemId('MS_2GB');
116 $item_2 = new GoogleItem("AA Rechargeable Battery Pack",
117 "Battery pack containing four AA rechargeable batteries",
118 1 , // Quantity
119 11.59,// Unit price
120 'LB',
121 10); //weigth
122 $item_2->SetMerchantItemId('AAR_BP');
123 $cart->AddItem($item_1);
124 $cart->AddItem($item_2);
125
126 $ship_from = new GoogleShipFrom('Store_origin',
127 'Miami',
128 'US',
129 '33102',
130 'FL');
131 $GSPackage = new GoogleShippingPackage($ship_from,1,2,3,'IN');
132 $Gshipping = new GoogleCarrierCalculatedShipping('Carrier_shipping');
133 $Gshipping->addShippingPackage($GSPackage);
134
135 $CCSoption = new GoogleCarrierCalculatedShippingOption("10.99", "FedEx", "Ground", "0.99");
136 $Gshipping->addCarrierCalculatedShippingOptions($CCSoption);
137 $CCSoption = new GoogleCarrierCalculatedShippingOption("22.99", "FedEx", "Express Saver");
138 $Gshipping->addCarrierCalculatedShippingOptions($CCSoption);
139 $CCSoption = new GoogleCarrierCalculatedShippingOption("24.99", "FedEx", "2Day", "0", "10", 'REGULAR_PICKUP');
140 $Gshipping->addCarrierCalculatedShippingOptions($CCSoption);
141
142 $CCSoption = new GoogleCarrierCalculatedShippingOption("11.99", "UPS", "Ground", "0.99", "5", 'REGULAR_PICKUP');
143 $Gshipping->addCarrierCalculatedShippingOptions($CCSoption);
144 $CCSoption = new GoogleCarrierCalculatedShippingOption("18.99", "UPS", "3 Day Select");
145 $Gshipping->addCarrierCalculatedShippingOptions($CCSoption);
146 $CCSoption = new GoogleCarrierCalculatedShippingOption("20.99", "UPS", "Next Day Air", "0", "10", 'REGULAR_PICKUP');
147 $Gshipping->addCarrierCalculatedShippingOptions($CCSoption);
148
149 $CCSoption = new GoogleCarrierCalculatedShippingOption("9.99", "USPS", "Media Mail", "0", "2", 'REGULAR_PICKUP');
150 $Gshipping->addCarrierCalculatedShippingOptions($CCSoption);
151 $CCSoption = new GoogleCarrierCalculatedShippingOption("15.99", "USPS", "Parcel Post");
152 $Gshipping->addCarrierCalculatedShippingOptions($CCSoption);
153 $CCSoption = new GoogleCarrierCalculatedShippingOption("18.99", "USPS", "Express Mail", "2.99", "10", 'REGULAR_PICKUP');
154 $Gshipping->addCarrierCalculatedShippingOptions($CCSoption);
155
156 $cart->AddShipping($Gshipping);
157
158 $ship_1 = new GoogleFlatRateShipping("Flat Rate", 5.0);
159 $restriction_1 = new GoogleShippingFilters();
160 $restriction_1->SetAllowedCountryArea("CONTINENTAL_48");
161 $ship_1->AddShippingRestrictions($restriction_1);
162 $cart->AddShipping($ship_1);
163
164 // Add US tax rules
165 $tax_rule_1 = new GoogleDefaultTaxRule(0.0825);
166 $tax_rule_1->SetStateAreas(array("CA", "NY"));
167 $cart->AddDefaultTaxRules($tax_rule_1);
168
169 // Add International tax rules
170 $tax_rule_2 = new GoogleDefaultTaxRule(0.15);
171 $tax_rule_2->AddPostalArea("GB");
172 $tax_rule_2->AddPostalArea("FR");
173 $tax_rule_2->AddPostalArea("DE");
174 $cart->AddDefaultTaxRules($tax_rule_2);
175
176 // Define rounding policy
177 $cart->AddRoundingPolicy("HALF_UP", "PER_LINE");
178
179 // Display XML data
180 // echo "<pre>";
181 // echo htmlentities($cart->GetXML());
182 // echo "</pre>";
183
184 // Display Google Checkout button
185 echo $cart->CheckoutButtonCode("LARGE");
186 }
187
188 function UseCase1() {
189 // Create a new shopping cart object
190 $merchant_id = ""; // Your Merchant ID
191 $merchant_key = ""; // Your Merchant Key
192 $server_type = "sandbox";
193 $currency = "USD";
194 $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency);
195
196 // Add items to the cart
197 $item_1 = new GoogleItem("MegaSound 2GB MP3 Player", // Item name
198 "Portable MP3 player - stores 500 songs", // Item description
199 1, // Quantity
200 175.49); // Unit price
201 $item_2 = new GoogleItem("AA Rechargeable Battery Pack",
202 "Battery pack containing four AA rechargeable batteries",
203 1 , // Quantity
204 11.59); // Unit price
205 $cart->AddItem($item_1);
206 $cart->AddItem($item_2);
207
208 // Add US shipping options
209 $ship_1 = new GoogleFlatRateShipping("UPS Ground", 5.0);
210 $restriction_1 = new GoogleShippingFilters();
211 $restriction_1->SetAllowedCountryArea("CONTINENTAL_48");
212 $ship_1->AddShippingRestrictions($restriction_1);
213
214 $ship_2 = new GoogleFlatRateShipping("UPS 2nd Day", 10.0);
215 $restriction_2 = new GoogleShippingFilters();
216 $restriction_2->SetAllowedStateAreas(array('fl', "CA", "AZ", "CO", "WA", "OR"));
217 $ship_2->AddShippingRestrictions($restriction_2);
218
219 // Add international shipping options
220 $ship_3 = new GoogleFlatRateShipping("Canada 3 Business Days", 5.0);
221 $restriction_3 = new GoogleShippingFilters();
222 $restriction_3->AddAllowedPostalArea("CA");
223 $restriction_3->SetAllowUsPoBox(false);
224 $ship_3->AddShippingRestrictions($restriction_3);
225
226 $ship_4 = new GoogleFlatRateShipping("Europe 3 Business Days", 10.0);
227 $restriction_4 = new GoogleShippingFilters();
228 $restriction_4->AddAllowedPostalArea("GB", "SW*");
229 $ship_4->AddShippingRestrictions($restriction_4);
230
231 $cart->AddShipping($ship_1);
232 $cart->AddShipping($ship_2);
233 $cart->AddShipping($ship_3);
234 $cart->AddShipping($ship_4);
235
236 // Add US tax rules
237 $tax_rule_1 = new GoogleDefaultTaxRule(0.0825);
238 $tax_rule_1->SetStateAreas(array("CA", "NY"));
239 $cart->AddDefaultTaxRules($tax_rule_1);
240
241 // Add International tax rules
242 $tax_rule_2 = new GoogleDefaultTaxRule(0.15);
243 $tax_rule_2->AddPostalArea("GB");
244 $tax_rule_2->AddPostalArea("FR");
245 $tax_rule_2->AddPostalArea("DE");
246 $cart->AddDefaultTaxRules($tax_rule_2);
247
248 // Define rounding policy
249 $cart->AddRoundingPolicy("HALF_UP", "PER_LINE");
250
251 // Display XML data
252 // echo "<pre>";
253 // echo htmlentities($cart->GetXML());
254 // echo "</pre>";
255
256 // Display Google Checkout button
257 echo $cart->CheckoutButtonCode("LARGE");
258 }
259
260 function UseCase2() {
261 // Create a new shopping cart object
262 $merchant_id = ""; // Your Merchant ID
263 $merchant_key = ""; // Your Merchant Key
264 $server_type = "sandbox";
265 $currency = "USD";
266 $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency);
267
268 // Add items to the cart
269 $item_1 = new GoogleItem("Dry Food Pack AA1453",
270 "A pack of highly nutritious dried food for emergency", 2, 24.99);
271 $item_1->SetTaxTableSelector("food");
272
273 $item_2 = new GoogleItem("MegaSound 2GB MP3 Player",
274 "Portable MP3 player - stores 500 songs", 1, 175.49);
275 $item_2->SetMerchantPrivateItemData(
276 new MerchantPrivateItemData(array("color" => "blue",
277 "weight" => "3.2")));
278 $item_2->SetMerchantItemId("Item#012345");
279
280 $cart->AddItem($item_1);
281 $cart->AddItem($item_2);
282
283 // Add shipping options
284 $ship_1 = new GoogleFlatRateShipping("Ground", 15);
285 $restriction_1 = new GoogleShippingFilters();
286 $restriction_1->SetAllowedWorldArea(true);
287 $ship_1->AddShippingRestrictions($restriction_1);
288
289 $ship_2 = new GooglePickup("Pick Up", 5);
290
291 $cart->AddShipping($ship_1);
292 $cart->AddShipping($ship_2);
293
294 // Add default tax rules
295 $tax_rule_1 = new GoogleDefaultTaxRule(0.17);
296 $tax_rule_1->AddPostalArea("GB", "SW*");
297 $tax_rule_1->AddPostalArea("FR");
298 $tax_rule_1->AddPostalArea("DE");
299
300 $tax_rule_2 = new GoogleDefaultTaxRule(0.10);
301 $tax_rule_2->SetWorldArea(true);
302
303 $cart->AddDefaultTaxRules($tax_rule_1);
304 $cart->AddDefaultTaxRules($tax_rule_2);
305
306 // Add alternate tax table
307 $tax_table = new GoogleAlternateTaxTable("food");
308
309 $tax_rule_1 = new GoogleAlternateTaxRule(0.05);
310 $tax_rule_1->AddPostalArea("GB");
311 $tax_rule_1->AddPostalArea("FR");
312 $tax_rule_1->AddPostalArea("DE");
313
314 $tax_rule_2 = new GoogleAlternateTaxRule(0.03);
315 $tax_rule_2->SetWorldArea(true);
316
317 $tax_table->AddAlternateTaxRules($tax_rule_1);
318 $tax_table->AddAlternateTaxRules($tax_rule_2);
319
320 $cart->AddAlternateTaxTables($tax_table);
321
322 // Add <merchant-private-data>
323 $cart->SetMerchantPrivateData(
324 new MerchantPrivateData(array("cart-id" => "ABC123")));
325
326 // Specify <edit-cart-url>
327 $cart->SetEditCartUrl("http://www.example.com/edit");
328
329 // Specify "Return to xyz" link
330 $cart->SetContinueShoppingUrl("http://www.example.com/continue");
331
332 // Request buyer's phone number
333 $cart->SetRequestBuyerPhone(true);
334
335 // Define rounding policy
336 $cart->AddRoundingPolicy("CEILING", "TOTAL");
337
338 // Display XML data
339 // echo "<pre>";
340 // echo htmlentities($cart->GetXML());
341 // echo "</pre>";
342
343 // Display a medium size button
344 echo $cart->CheckoutButtonCode("MEDIUM");
345 }
346
347 function UseCase3() {
348 //Create a new shopping cart object
349 $merchant_id = ""; // Your Merchant ID
350 $merchant_key = ""; // Your Merchant Key
351 $server_type = "sandbox";
352 $currency = "USD";
353 $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency);
354
355 // Add items to the cart
356 $item = new GoogleItem("MegaSound 2GB MP3 Player",
357 "Portable MP3 player - stores 500 songs", 1, 175.49);
358 $item->SetMerchantPrivateItemData("<color>blue</color><weight>3.2</weight>");
359 $cart->AddItem($item);
360
361 // Add merchant calculations options
362 $cart->SetMerchantCalculations(
363 "http://200.69.205.154/~brovagnati/tools/unitTest/demo/responsehandlerdemo.php", // merchant-calculations-url
364 "false", // merchant-calculated tax
365 "true", // accept-merchant-coupons
366 "true"); // accept-merchant-gift-certificates
367
368 // Add merchant-calculated-shipping option
369 $ship = new GoogleMerchantCalculatedShipping("2nd Day Air", // Shippping method
370 10.00); // Default, fallback price
371
372 $restriction = new GoogleShippingFilters();
373 $restriction->AddAllowedPostalArea("GB");
374 $restriction->AddAllowedPostalArea("US");
375 $restriction->SetAllowUsPoBox(false);
376 $ship->AddShippingRestrictions($restriction);
377
378 $address_filter = new GoogleShippingFilters();
379 $address_filter->AddAllowedPostalArea("GB");
380 $address_filter->AddAllowedPostalArea("US");
381 $address_filter->SetAllowUsPoBox(false);
382 $ship->AddAddressFilters($address_filter);
383
384 $cart->AddShipping($ship);
385
386 // Set default tax options
387 $tax_rule = new GoogleDefaultTaxRule(0.15);
388 $tax_rule->SetWorldArea(true);
389 $cart->AddDefaultTaxRules($tax_rule);
390
391 $cart->AddRoundingPolicy("UP", "TOTAL");
392
393 // Display XML data
394 // echo "<pre>";
395 // echo htmlentities($cart->GetXML());
396 // echo "</pre>";
397
398 // Display a disabled, small button
399 echo $cart->CheckoutButtonCode("SMALL", false);
400 }
401
402 ?>