| OLD | NEW |
| (Empty) | |
| 1 /* |
| 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 |
| 4 * found in the LICENSE file. |
| 5 */ |
| 6 |
| 7 /* global PaymentRequest:false */ |
| 8 /* global toDictionary:false */ |
| 9 |
| 10 var request; |
| 11 |
| 12 /** |
| 13 * Launches the PaymentRequest UI that accepts credit cards. |
| 14 */ |
| 15 function buy() { // eslint-disable-line no-unused-vars |
| 16 try { |
| 17 request = new PaymentRequest( |
| 18 [{supportedMethods: ['visa']}], { |
| 19 total: {label: 'Total', amount: {currency: 'USD', value: '5.00'}}, |
| 20 shippingOptions: [{ |
| 21 id: 'freeShippingOption', |
| 22 label: 'Free global shipping', |
| 23 amount: {currency: 'USD', value: '0'}, |
| 24 selected: true |
| 25 }] |
| 26 }, |
| 27 {requestShipping: true}); |
| 28 request.show() |
| 29 .then(function(resp) { |
| 30 return resp.complete('success') |
| 31 }).then(function() { |
| 32 print( |
| 33 resp.shippingOption + '<br>' + |
| 34 JSON.stringify( |
| 35 toDictionary(resp.shippingAddress), undefined, 2) + |
| 36 '<br>' + resp.methodName + '<br>' + |
| 37 JSON.stringify(resp.details, undefined, 2)); |
| 38 }).catch(function(error) { |
| 39 print(error); |
| 40 }); |
| 41 } catch (error) { |
| 42 print(error.message); |
| 43 } |
| 44 } |
| 45 |
| 46 /** |
| 47 * Launches the PaymentRequest UI which accepts a supported payment method but |
| 48 * does not accept credit cards. |
| 49 */ |
| 50 function noMatching() { // eslint-disable-line no-unused-vars |
| 51 try { |
| 52 request = new PaymentRequest( |
| 53 [{supportedMethods: ['https://bobpay.com']}], { |
| 54 total: {label: 'Total', amount: {currency: 'USD', value: '5.00'}}, |
| 55 shippingOptions: [{ |
| 56 id: 'freeShippingOption', |
| 57 label: 'Free global shipping', |
| 58 amount: {currency: 'USD', value: '0'}, |
| 59 selected: true |
| 60 }] |
| 61 }, |
| 62 {requestShipping: true}); |
| 63 request.show() |
| 64 .then(function(resp) { |
| 65 return resp.complete('success'); |
| 66 }).then(function() { |
| 67 print( |
| 68 resp.shippingOption + '<br>' + |
| 69 JSON.stringify( |
| 70 toDictionary(resp.shippingAddress), undefined, 2) + |
| 71 '<br>' + resp.methodName + '<br>' + |
| 72 JSON.stringify(resp.details, undefined, 2)); |
| 73 }).catch(function(error) { |
| 74 print(error); |
| 75 }); |
| 76 } catch (error) { |
| 77 print(error.message); |
| 78 } |
| 79 } |
| 80 |
| 81 /** |
| 82 * Launches the PaymentRequest UI which accepts only an unsupported payment |
| 83 * method. |
| 84 */ |
| 85 function noSupported() { // eslint-disable-line no-unused-vars |
| 86 try { |
| 87 request = new PaymentRequest( |
| 88 [{supportedMethods: ['https://randompay.com']}], { |
| 89 total: {label: 'Total', amount: {currency: 'USD', value: '5.00'}}, |
| 90 shippingOptions: [{ |
| 91 id: 'freeShippingOption', |
| 92 label: 'Free global shipping', |
| 93 amount: {currency: 'USD', value: '0'}, |
| 94 selected: true |
| 95 }] |
| 96 }, |
| 97 {requestShipping: true}); |
| 98 request.show() |
| 99 .then(function(resp) { |
| 100 return resp.complete('success'); |
| 101 }).then(function() { |
| 102 print( |
| 103 resp.shippingOption + '<br>' + |
| 104 JSON.stringify( |
| 105 toDictionary(resp.shippingAddress), undefined, 2) + |
| 106 '<br>' + resp.methodName + '<br>' + |
| 107 JSON.stringify(resp.details, undefined, 2)); |
| 108 }).catch(function(error) { |
| 109 print(error); |
| 110 }); |
| 111 } catch (error) { |
| 112 print(error.message); |
| 113 } |
| 114 } |
| 115 |
| 116 /** |
| 117 * Aborts the current PaymentRequest. |
| 118 */ |
| 119 function abort() { // eslint-disable-line no-unused-vars |
| 120 try { |
| 121 request.abort().then(function() { |
| 122 print('Aborted'); |
| 123 }).catch(function() { |
| 124 print('Cannot abort'); |
| 125 }); |
| 126 } catch (error) { |
| 127 print(error.message); |
| 128 } |
| 129 } |
| OLD | NEW |