chromium/components/test/data/payments/payment_request_csp_check_can_make_payment.js

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/**
 * Checks canMakePayment() for the given payment method identifier.
 * @param {string} method - Payment method identifier to check.
 * @return {Promise<string>} - Either 'true', 'false', or an error message.
 */
async function checkCanMakePayment(method) {
  try {
    const request = new PaymentRequest(
      [
        {supportedMethods: method},
      ],
      {total: {label: 'Total', amount: {currency: 'USD', value: '5.00'}}});
    const result = await request.canMakePayment();
    return (result ? 'true' : 'false');
  } catch (error) {
    return error.toString();
  }
}