OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 The Chromium Authors. All rights reserved. | 2 * Copyright 2016 The Chromium Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 /* global PaymentRequest:false */ | 7 /* global PaymentRequest:false */ |
8 /* global toDictionary:false */ | |
9 /* global print:false */ | 8 /* global print:false */ |
10 | 9 |
11 /** | 10 /** |
12 * Launches the PaymentRequest UI that offers free shipping worldwide. | 11 * Launches the PaymentRequest UI with shipping options, but does not request a |
| 12 * shipping address. |
13 */ | 13 */ |
14 function buy() { // eslint-disable-line no-unused-vars | 14 function buy() { // eslint-disable-line no-unused-vars |
15 try { | 15 try { |
16 var details = { | 16 var details = { |
17 total: {label: 'Total', amount: {currency: 'USD', value: '5.00'}}, | 17 total: {label: 'Total', amount: {currency: 'USD', value: '5.00'}}, |
18 shippingOptions: [{ | 18 shippingOptions: [{ |
19 id: 'freeShippingOption', | 19 id: 'freeShippingOption', |
20 label: 'Free global shipping', | 20 label: 'Free global shipping', |
21 amount: {currency: 'USD', value: '0'}, | 21 amount: {currency: 'USD', value: '0'}, |
22 selected: true | 22 selected: true |
23 }] | 23 }] |
24 }; | 24 }; |
25 var request = new PaymentRequest( | 25 var request = new PaymentRequest([{supportedMethods: ['visa']}], details); |
26 [{supportedMethods: ['visa']}], details, | |
27 {requestShipping: true}); | |
28 request.addEventListener('shippingaddresschange', function(e) { | |
29 e.updateWith(new Promise(function(resolve) { | |
30 // No changes in price based on shipping address change. | |
31 resolve(details); | |
32 })); | |
33 }); | |
34 request.show() | 26 request.show() |
35 .then(function(resp) { | 27 .then(function(resp) { |
36 resp.complete('success') | 28 resp.complete('success') |
37 .then(function() { | 29 .then(function() { |
38 print( | 30 print(resp.methodName + '<br>' + |
39 resp.shippingOption + '<br>' + | |
40 JSON.stringify( | |
41 toDictionary(resp.shippingAddress), undefined, 2) + | |
42 '<br>' + resp.methodName + '<br>' + | |
43 JSON.stringify(resp.details, undefined, 2)); | 31 JSON.stringify(resp.details, undefined, 2)); |
44 }) | 32 }) |
45 .catch(function(error) { | 33 .catch(function(error) { |
46 print(error); | 34 print(error); |
47 }); | 35 }); |
48 }) | 36 }) |
49 .catch(function(error) { | 37 .catch(function(error) { |
50 print(error); | 38 print(error); |
51 }); | 39 }); |
52 } catch (error) { | 40 } catch (error) { |
53 print(error.message); | 41 print(error.message); |
54 } | 42 } |
55 } | 43 } |
OLD | NEW |