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