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 print:false */ | |
9 | |
10 var first; | |
11 var second; | |
12 | |
13 /** | |
14 * Sets the |first| variable and prints both |first| and |second| only if both | |
15 * were set. | |
16 */ | |
17 function printFirst(result) { | |
18 first = result.toString(); | |
19 if (first && second) { | |
20 print(first + ', ' + second); | |
21 } | |
22 } | |
23 | |
24 /** | |
25 * Sets the |second| variable and prints both |first| and |second| only if both | |
26 * were set. | |
27 */ | |
28 function printSecond(result) { | |
29 second = result.toString(); | |
30 if (first && second) { | |
31 print(first + ', ' + second); | |
32 } | |
33 } | |
34 | |
35 /** | |
36 * Checks for existence of Bob Pay twice. | |
37 */ | |
38 function buy() { // eslint-disable-line no-unused-vars | |
39 first = null; | |
40 second = null; | |
41 | |
42 try { | |
43 new PaymentRequest( | |
44 [{supportedMethods: ['https://bobpay.com']}], | |
45 {total: {label: 'Total', amount: {currency: 'USD', value: '5.00'}}}) | |
46 .canMakeActivePayment() | |
47 .then(function(result) { printFirst(result); }) | |
48 .catch(function(error) { printFirst(error); }); | |
49 } catch (error) { | |
50 printFirst(error); | |
51 } | |
52 | |
53 try { | |
54 new PaymentRequest( | |
55 [{supportedMethods: ['https://bobpay.com']}], | |
56 {total: {label: 'Total', amount: {currency: 'USD', value: '5.00'}}}) | |
57 .canMakeActivePayment() | |
58 .then(function(result) { printSecond(result); }) | |
59 .catch(function(error) { printSecond(error); }); | |
60 } catch (error) { | |
61 printSecond(error); | |
62 } | |
63 } | |
64 | |
65 /** | |
66 * Checks for existence of Bob Pay and AlicePay. | |
67 */ | |
68 function otherBuy() { // eslint-disable-line no-unused-vars | |
69 first = null; | |
70 second = null; | |
71 | |
72 try { | |
73 new PaymentRequest( | |
74 [{supportedMethods: ['https://bobpay.com']}], | |
75 {total: {label: 'Total', amount: {currency: 'USD', value: '5.00'}}}) | |
76 .canMakeActivePayment() | |
77 .then(function(result) { printFirst(result); }) | |
78 .catch(function(error) { printFirst(error); }); | |
79 } catch (error) { | |
80 printFirst(error); | |
81 } | |
82 | |
83 try { | |
84 new PaymentRequest( | |
85 [{supportedMethods: ['https://alicepay.com']}], | |
86 {total: {label: 'Total', amount: {currency: 'USD', value: '5.00'}}}) | |
87 .canMakeActivePayment() | |
88 .then(function(result) { printSecond(result); }) | |
89 .catch(function(error) { printSecond(error); }); | |
90 } catch (error) { | |
91 printSecond(error); | |
92 } | |
93 } | |
OLD | NEW |