OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>Free Shipping Test</title> | 4 <title>No Shipping 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 pre { | 13 pre { |
14 font-size: 2em; | 14 font-size: 2em; |
(...skipping 17 matching lines...) Expand all Loading... |
32 dict.addressLine = addr.addressLine; | 32 dict.addressLine = addr.addressLine; |
33 dict.postalCode = addr.postalCode; | 33 dict.postalCode = addr.postalCode; |
34 dict.sortingCode = addr.sortingCode; | 34 dict.sortingCode = addr.sortingCode; |
35 dict.languageCode = addr.languageCode; | 35 dict.languageCode = addr.languageCode; |
36 dict.organization = addr.organization; | 36 dict.organization = addr.organization; |
37 dict.recipient = addr.recipient; | 37 dict.recipient = addr.recipient; |
38 return dict; | 38 return dict; |
39 } | 39 } |
40 function buy() { | 40 function buy() { |
41 try { | 41 try { |
42 var request = new PaymentRequest(['visa'], { | 42 var details = { |
43 'items' : [ { | 43 'items' : [ { |
44 'id' : 'total', | 44 'id' : 'total', |
45 'label' : 'Total', | 45 'label' : 'Total', |
46 'amount' : {'currencyCode' : 'USD', 'value' : '5.00'} | 46 'amount' : {'currencyCode' : 'USD', 'value' : '5.00'} |
47 } ], | |
48 'shippingOptions' : [ { | |
49 'id' : 'freeShippingOption', | |
50 'label' : 'Free global shipping', | |
51 'amount' : {'currencyCode' : 'USD', 'value' : '0'} | |
52 } ] | 47 } ] |
53 }, | 48 }; |
54 {'requestShipping' : true}); | 49 var request = |
| 50 new PaymentRequest(['visa'], details, {'requestShipping' : true}); |
| 51 request.addEventListener("shippingaddresschange", function(e) { |
| 52 e.updateWith(new Promise(function(resolve, reject) { |
| 53 details['shippingOptions'] = [ { |
| 54 'id' : 'calculatedShippingOption', |
| 55 'label' : 'Standard shipping', |
| 56 'amount' : {'currencyCode' : 'USD', 'value' : '1.00'} |
| 57 } ]; |
| 58 resolve(details); |
| 59 })); |
| 60 }); |
55 request.show() | 61 request.show() |
56 .then(function(resp) { | 62 .then(function(resp) { |
57 resp.complete(true) | 63 resp.complete(true) |
58 .then(function() { | 64 .then(function() { |
59 print(request.shippingOption + '<br>' + | 65 print(request.shippingOption + '<br>' + |
60 JSON.stringify(toDictionary(request.shippingAddress), | 66 JSON.stringify(toDictionary(request.shippingAddress), |
61 undefined, 2) + | 67 undefined, 2) + |
62 '<br>' + resp.methodName + '<br>' + | 68 '<br>' + resp.methodName + '<br>' + |
63 JSON.stringify(resp.details, undefined, 2)); | 69 JSON.stringify(resp.details, undefined, 2)); |
64 }) | 70 }) |
65 .catch(function(error) { print(error.message); }); | 71 .catch(function(error) { print(error.message); }); |
66 }) | 72 }) |
67 .catch(function(error) { print(error.message); }); | 73 .catch(function(error) { print(error.message); }); |
68 } catch (error) { | 74 } catch (error) { |
69 print(error.message); | 75 print(error.message); |
70 } | 76 } |
71 } | 77 } |
72 </script> | 78 </script> |
73 </body> | 79 </body> |
74 </html> | 80 </html> |
OLD | NEW |