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