| 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 /** | 10 /** |
| 11 * Launches the PaymentRequest UI that requests an email address and a phone | 11 * Launches the PaymentRequest UI that requests an email address and a phone |
| 12 * number and offers free shipping worldwide. | 12 * number and offers free shipping worldwide. |
| 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 = { |
| 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 }; |
| 16 var request = new PaymentRequest( | 25 var request = new PaymentRequest( |
| 17 [{supportedMethods: ['visa']}], { | 26 [{supportedMethods: ['visa', 'https://bobpay.com']}], 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 }, | |
| 26 {requestPayerName: true, requestPayerEmail: true, | 27 {requestPayerName: true, requestPayerEmail: true, |
| 27 requestPayerPhone: true, requestShipping: true}); | 28 requestPayerPhone: true, requestShipping: true}); |
| 29 |
| 30 request.addEventListener('shippingaddresschange', function(e) { |
| 31 e.updateWith(new Promise(function(resolve) { |
| 32 // No changes in price based on shipping address change. |
| 33 resolve(details); |
| 34 })); |
| 35 }); |
| 36 |
| 28 request.show() | 37 request.show() |
| 29 .then(function(resp) { | 38 .then(function(resp) { |
| 30 resp.complete('success') | 39 resp.complete('success') |
| 31 .then(function() { | 40 .then(function() { |
| 32 print( | 41 print(JSON.stringify(resp, undefined, 2)); |
| 33 resp.payerName + '<br>' + resp.payerEmail + '<br>' + | |
| 34 resp.payerPhone + '<br>' + resp.shippingOption + '<br>' + | |
| 35 JSON.stringify( | |
| 36 toDictionary(resp.shippingAddress), undefined, 2) + | |
| 37 '<br>' + resp.methodName + '<br>' + | |
| 38 JSON.stringify(resp.details, undefined, 2)); | |
| 39 }) | 42 }) |
| 40 .catch(function(error) { | 43 .catch(function(error) { |
| 41 print(error); | 44 print(error); |
| 42 }); | 45 }); |
| 43 }) | 46 }) |
| 44 .catch(function(error) { | 47 .catch(function(error) { |
| 45 print(error); | 48 print(error); |
| 46 }); | 49 }); |
| 47 } catch (error) { | 50 } catch (error) { |
| 48 print(error.message); | 51 print(error.message); |
| 49 } | 52 } |
| 50 } | 53 } |
| OLD | NEW |