PaymentRequest: canMakePayment() method - Web APIs | MDN

Syntax

Parameters

None.

Return value

A Promise to a boolean value that resolves to true if the user agent supports any of the payment methods supplied when instantiating the request using the PaymentRequest constructor. If the payment can't be processed, the promise receives a value of false.

Note: If you call this too often, the browser may reject the returned promise with a DOMException.

Examples

In the following example, is excerpted from a demo that asynchronously builds a PaymentRequest object for both Apple Pay and Example Pay. It wraps the call to canMakePayment() in feature detection, and calls an appropriate callback depending on the resolution of the Promise.

js

async function initPaymentRequest() {
  const details = {
    total: {
      label: "Total",
      amount: {
        currency: "USD",
        value: "0.00",
      },
    },
  };

  const supportsApplePay = new PaymentRequest(
    [{ supportedMethods: "https://apple.com/apple-pay" }],
    details,
  ).canMakePayment();

  // Supports Apple Pay?
  if (await supportsApplePay) {
    // show Apple Pay logo, for instance
    return;
  }

  // Otherwise, let's see if we can use Example Pay
  const supportsExamplePay = await new PaymentRequest(
    [{ supportedMethods: "https://example.com/pay" }],
    details,
  ).canMakePayment();

  if (supportsExamplePay) {
    // show Example Pay support
    return;
  }

  // Otherwise, make payments using HTML form element
}

Specifications

Specification
Payment Request API
# dom-paymentrequest-canmakepayment

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.