| 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 */ | 8 /* global toDictionary:false */ |
| 9 /* global print:false */ |
| 9 | 10 |
| 10 /** | 11 /** |
| 11 * Launches the PaymentRequest UI that offers free shipping worldwide. | 12 * Launches the PaymentRequest UI that offers free shipping worldwide. |
| 12 */ | 13 */ |
| 13 function buy() { // eslint-disable-line no-unused-vars | 14 function buy() { // eslint-disable-line no-unused-vars |
| 14 try { | 15 try { |
| 16 var details = { |
| 17 total: {label: 'Total', amount: {currency: 'USD', value: '5.00'}}, |
| 18 shippingOptions: [{ |
| 19 id: 'freeShippingOption', |
| 20 label: 'Free global shipping', |
| 21 amount: {currency: 'USD', value: '0'}, |
| 22 selected: true |
| 23 }] |
| 24 }; |
| 15 var request = new PaymentRequest( | 25 var request = new PaymentRequest( |
| 16 [{supportedMethods: ['visa']}], { | 26 [{supportedMethods: ['visa']}], details, |
| 17 total: {label: 'Total', amount: {currency: 'USD', value: '5.00'}}, | |
| 18 shippingOptions: [{ | |
| 19 id: 'freeShippingOption', | |
| 20 label: 'Free global shipping', | |
| 21 amount: {currency: 'USD', value: '0'}, | |
| 22 selected: true | |
| 23 }] | |
| 24 }, | |
| 25 {requestShipping: true}); | 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 }); |
| 26 request.show() | 34 request.show() |
| 27 .then(function(resp) { | 35 .then(function(resp) { |
| 28 resp.complete('success') | 36 resp.complete('success') |
| 29 .then(function() { | 37 .then(function() { |
| 30 print( | 38 print( |
| 31 resp.shippingOption + '<br>' + | 39 resp.shippingOption + '<br>' + |
| 32 JSON.stringify( | 40 JSON.stringify( |
| 33 toDictionary(resp.shippingAddress), undefined, 2) + | 41 toDictionary(resp.shippingAddress), undefined, 2) + |
| 34 '<br>' + resp.methodName + '<br>' + | 42 '<br>' + resp.methodName + '<br>' + |
| 35 JSON.stringify(resp.details, undefined, 2)); | 43 JSON.stringify(resp.details, undefined, 2)); |
| 36 }) | 44 }) |
| 37 .catch(function(error) { | 45 .catch(function(error) { |
| 38 print(error); | 46 print(error); |
| 39 }); | 47 }); |
| 40 }) | 48 }) |
| 41 .catch(function(error) { | 49 .catch(function(error) { |
| 42 print(error); | 50 print(error); |
| 43 }); | 51 }); |
| 44 } catch (error) { | 52 } catch (error) { |
| 45 print(error.message); | 53 print(error.message); |
| 46 } | 54 } |
| 47 } | 55 } |
| OLD | NEW |