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 | |
|
Bernhard Bauer
2016/08/04 08:14:38
Out of curiosity: Where do we run a JS linting ste
please use gerrit instead
2016/08/04 19:08:56
I run this manually in my editor. You can also run
| |
| 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') | |
|
Bernhard Bauer
2016/08/04 08:14:38
If you return this from the callback, you can chai
sebsg
2016/08/04 20:47:49
Nice! I'll fix that for the other js files too: cr
| |
| 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); | |
|
Bernhard Bauer
2016/08/04 08:14:38
Maybe for a future CL: You could try to use window
sebsg
2016/08/04 20:47:50
I'll try that: crbug.com/634463
| |
| 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) { | |
|
Bernhard Bauer
2016/08/04 08:14:38
Would a `=>`-style function work here as well?
please use gerrit instead
2016/08/04 17:16:49
These test files will eventually be used on iOS, w
sebsg
2016/08/04 20:47:50
Removed the => completely.
| |
| 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 an unsupported payment | |
| 91 * method. | |
| 92 */ | |
| 93 function noSupported() { // eslint-disable-line no-unused-vars | |
| 94 try { | |
| 95 var request = new PaymentRequest( | |
| 96 [{supportedMethods: ['https://randompay.com']}], { | |
| 97 total: {label: 'Total', amount: {currency: 'USD', value: '5.00'}}, | |
| 98 shippingOptions: [{ | |
| 99 id: 'freeShippingOption', | |
| 100 label: 'Free global shipping', | |
| 101 amount: {currency: 'USD', value: '0'}, | |
| 102 selected: true | |
| 103 }] | |
| 104 }, | |
| 105 {requestShipping: true}); | |
| 106 request.show() | |
| 107 .then(function(resp) { | |
| 108 resp.complete('success') | |
| 109 .then(function() { | |
| 110 print( | |
| 111 resp.shippingOption + '<br>' + | |
| 112 JSON.stringify( | |
| 113 toDictionary(resp.shippingAddress), undefined, 2) + | |
| 114 '<br>' + resp.methodName + '<br>' + | |
| 115 JSON.stringify(resp.details, undefined, 2)); | |
| 116 }) | |
| 117 .catch(function(error) { | |
| 118 print(error); | |
| 119 }); | |
| 120 }) | |
| 121 .catch(function(error) { | |
| 122 print(error); | |
| 123 }); | |
| 124 } catch (error) { | |
| 125 print(error.message); | |
| 126 } | |
| 127 } | |
| 128 | |
| 129 /** | |
| 130 * Aborts the current PaymentRequest. | |
| 131 */ | |
| 132 function abort() { // eslint-disable-line no-unused-vars | |
| 133 try { | |
| 134 request.abort().then(() => { | |
|
Bernhard Bauer
2016/08/04 08:14:38
Is this method actually called? What does |request
sebsg
2016/08/04 20:47:49
I tried adding "use strict" but I didn't get any w
Bernhard Bauer
2016/08/05 08:56:12
Oh right, I think even strict mode would only catc
| |
| 135 print('Aborted'); | |
| 136 }).catch(() => { | |
| 137 print('Cannot abort'); | |
| 138 }); | |
| 139 } catch (error) { | |
| 140 print(error.message); | |
| 141 } | |
| 142 } | |
| OLD | NEW |