| 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 | 9 |
| 10 var request; | 10 var request; |
| 11 | 11 |
| 12 /** | 12 /** |
| 13 * Launches the PaymentRequest UI that accepts credit cards. | 13 * Launches the PaymentRequest UI that accepts credit cards. |
| 14 */ | 14 */ |
| 15 function ccBuy() { // eslint-disable-line no-unused-vars | 15 function ccBuy() { // eslint-disable-line no-unused-vars |
| 16 try { | 16 try { |
| 17 var details = { |
| 18 total: {label: 'Total', amount: {currency: 'USD', value: '5.00'}}, |
| 19 shippingOptions: [{ |
| 20 id: 'freeShippingOption', |
| 21 label: 'Free global shipping', |
| 22 amount: {currency: 'USD', value: '0'}, |
| 23 selected: true |
| 24 }] |
| 25 }; |
| 17 request = new PaymentRequest( | 26 request = new PaymentRequest( |
| 18 [{supportedMethods: ['visa']}], { | 27 [{supportedMethods: ['visa']}], { |
| 19 total: {label: 'Total', amount: {currency: 'USD', value: '5.00'}}, | 28 total: {label: 'Total', amount: {currency: 'USD', value: '5.00'}}, |
| 20 shippingOptions: [{ | 29 shippingOptions: [{ |
| 21 id: 'freeShippingOption', | 30 id: 'freeShippingOption', |
| 22 label: 'Free global shipping', | 31 label: 'Free global shipping', |
| 23 amount: {currency: 'USD', value: '0'}, | 32 amount: {currency: 'USD', value: '0'}, |
| 24 selected: true | 33 selected: true |
| 25 }] | 34 }] |
| 26 }, | 35 }, |
| 27 {requestShipping: true}); | 36 {requestShipping: true}); |
| 28 request.show() | 37 request.show() |
| 29 .then(function(resp) { | 38 .then(function(resp) { |
| 30 return resp.complete('success') | 39 return resp.complete('success') |
| 31 }).then(function() { | 40 }).then(function() { |
| 32 print( | 41 print( |
| 33 resp.shippingOption + '<br>' + | 42 resp.shippingOption + '<br>' + |
| 34 JSON.stringify( | 43 JSON.stringify( |
| 35 toDictionary(resp.shippingAddress), undefined, 2) + | 44 toDictionary(resp.shippingAddress), undefined, 2) + |
| 36 '<br>' + resp.methodName + '<br>' + | 45 '<br>' + resp.methodName + '<br>' + |
| 37 JSON.stringify(resp.details, undefined, 2)); | 46 JSON.stringify(resp.details, undefined, 2)); |
| 38 }).catch(function(error) { | 47 }).catch(function(error) { |
| 39 print(error); | 48 print(error); |
| 40 }); | 49 }); |
| 50 request.addEventListener('shippingaddresschange', function(e) { |
| 51 e.updateWith(new Promise(function(resolve) { |
| 52 // No changes in price based on shipping address change. |
| 53 resolve(details); |
| 54 })); |
| 55 }) |
| 41 } catch (error) { | 56 } catch (error) { |
| 42 print(error.message); | 57 print(error.message); |
| 43 } | 58 } |
| 44 } | 59 } |
| 45 | 60 |
| 46 /** | 61 /** |
| 47 * Launches the PaymentRequest UI which accepts only Android Pay. | 62 * Launches the PaymentRequest UI which accepts only Android Pay. |
| 48 */ | 63 */ |
| 49 function androidPayBuy() { // eslint-disable-line no-unused-vars | 64 function androidPayBuy() { // eslint-disable-line no-unused-vars |
| 50 try { | 65 try { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 try { | 134 try { |
| 120 request.abort().then(function() { | 135 request.abort().then(function() { |
| 121 print('Aborted'); | 136 print('Aborted'); |
| 122 }).catch(function() { | 137 }).catch(function() { |
| 123 print('Cannot abort'); | 138 print('Cannot abort'); |
| 124 }); | 139 }); |
| 125 } catch (error) { | 140 } catch (error) { |
| 126 print(error.message); | 141 print(error.message); |
| 127 } | 142 } |
| 128 } | 143 } |
| OLD | NEW |