OLD | NEW |
---|---|
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>Free Shipping Test</title> | 4 <title>Need Address Test</title> |
5 <meta charset="utf-8"> | 5 <meta charset="utf-8"> |
6 <meta name="viewport" content="width=device-width, initial-scale=1"> | 6 <meta name="viewport" content="width=device-width, initial-scale=1"> |
7 <style> | 7 <style> |
8 button { | 8 button { |
9 width: 100%; | 9 width: 100%; |
10 height: 5em; | 10 height: 5em; |
11 font-size: 3em; | 11 font-size: 3em; |
12 } | 12 } |
13 </style> | 13 </style> |
14 </head> | 14 </head> |
15 <body> | 15 <body> |
16 <button onclick="buy()" id="buy">Buy</button> | 16 <button onclick="buy()" id="buy">Need Address Test</button> |
17 <script> | 17 <script> |
18 function print(msg) { | 18 function print(msg) { |
19 document.open(); | 19 document.open(); |
20 document.write('<pre id="result" style="font-size: 2em;">' + msg + '</pre>'); | 20 document.write('<pre id="result" style="font-size: 2em;">' + msg + '</pre>'); |
21 document.close(); | 21 document.close(); |
22 } | 22 } |
23 function toDictionary(addr) { | 23 function toDictionary(addr) { |
24 var dict = {}; | 24 var dict = {}; |
25 dict.regionCode = addr.regionCode; | 25 dict.regionCode = addr.regionCode; |
26 dict.administrativeArea = addr.administrativeArea; | 26 dict.administrativeArea = addr.administrativeArea; |
27 dict.locality = addr.locality; | 27 dict.locality = addr.locality; |
28 dict.dependentLocality = addr.dependentLocality; | 28 dict.dependentLocality = addr.dependentLocality; |
29 dict.addressLine = addr.addressLine; | 29 dict.addressLine = addr.addressLine; |
30 dict.postalCode = addr.postalCode; | 30 dict.postalCode = addr.postalCode; |
31 dict.sortingCode = addr.sortingCode; | 31 dict.sortingCode = addr.sortingCode; |
32 dict.languageCode = addr.languageCode; | 32 dict.languageCode = addr.languageCode; |
33 dict.organization = addr.organization; | 33 dict.organization = addr.organization; |
34 dict.recipient = addr.recipient; | 34 dict.recipient = addr.recipient; |
35 return dict; | 35 return dict; |
36 } | 36 } |
37 function buy() { | 37 function buy() { |
38 try { | 38 try { |
39 var request = new PaymentRequest(['visa'], { | 39 var request = new PaymentRequest(['visa'], { |
40 'items' : [ { | 40 'items' : [ { |
41 'id' : 'total', | 41 'id' : 'total', |
42 'label' : 'Total', | 42 'label' : 'Total', |
43 'amount' : {'currencyCode' : 'USD', 'value' : '5.00'} | 43 'amount' : {'currencyCode' : 'USD', 'value' : '5.00'} |
44 } ], | |
45 'shippingOptions' : [ { | |
46 'id' : 'freeShippingOption', | |
47 'label' : 'Free global shipping', | |
48 'amount' : {'currencyCode' : 'USD', 'value' : '0'} | |
49 } ] | 44 } ] |
50 }, | 45 }, |
51 {'requestShipping' : true}); | 46 {'requestShipping' : true}); |
gone
2016/05/04 02:01:03
nit: indentation looks weird here
please use gerrit instead
2016/05/05 04:57:48
Removed integration tests from this patch.
| |
47 request.addEventListener("shippingaddresschange", function(e) { | |
48 e.updateWith(new Promise(function(resolve, reject) { | |
49 resolve({ | |
50 'items' : [ | |
51 { | |
52 'id' : 'item', | |
53 'label' : 'Item', | |
54 'amount' : {'currencyCode' : 'USD', 'value' : '5.00'} | |
55 }, | |
56 { | |
57 'id' : 'shipping', | |
58 'label' : 'Standard shipping', | |
59 'amount' : {'currencyCode' : 'USD', 'value' : '1.00'} | |
60 }, | |
61 { | |
62 'id' : 'total', | |
63 'label' : 'Total', | |
64 'amount' : {'currencyCode' : 'USD', 'value' : '6.00'} | |
65 }, | |
66 ], | |
67 'shippingOptions' : [ { | |
68 'id' : 'calculatedShippingOption', | |
69 'label' : 'Standard shipping', | |
70 'amount' : {'currencyCode' : 'USD', 'value' : '1.00'} | |
71 } ] | |
72 }); | |
73 })); | |
74 }); | |
52 request.show() | 75 request.show() |
53 .then(function(resp) { | 76 .then(function(resp) { |
54 resp.complete(true) | 77 resp.complete(true) |
55 .then(function() { | 78 .then(function() { |
56 print(request.shippingOption + '<br>' + | 79 print(request.shippingOption + '<br>' + |
57 JSON.stringify(toDictionary(request.shippingAddress), | 80 JSON.stringify(toDictionary(request.shippingAddress), |
58 undefined, 2) + | 81 undefined, 2) + |
59 '<br>' + resp.methodName + '<br>' + | 82 '<br>' + resp.methodName + '<br>' + |
60 JSON.stringify(resp.details, undefined, 2)); | 83 JSON.stringify(resp.details, undefined, 2)); |
61 }) | 84 }) |
62 .catch(function(error) { print(error.message); }); | 85 .catch(function(error) { print(error.message); }); |
63 }) | 86 }) |
64 .catch(function(error) { print(error.message); }); | 87 .catch(function(error) { print(error.message); }); |
65 } catch (error) { | 88 } catch (error) { |
66 print(error.message); | 89 print(error.message); |
67 } | 90 } |
68 } | 91 } |
69 </script> | 92 </script> |
70 </body> | 93 </body> |
71 </html> | 94 </html> |
OLD | NEW |