PaymentRequest.canMakePayment()

Secure context
This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The PaymentRequest.canMakePayment() method of the PaymentRequest interface indicates whether the PaymentRequest object can make a payment before calling show(). It returns a Promise resolves to true if the user agent supports any of the payment methods supplied to the constructor, and false otherwise. if this method is called too often, the spec allows the user agents to return a promise rejected with a DOMException.

Syntax

PaymentRequest.canMakePayment()
    .then( boolean => { ... })
    .catch( error => { ... })

Returns

A Promise to a Boolean that resolves to true if the user agent supports any of the payment methods supplied in the PaymentRequest constructor.

Parameters

None

Examples

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

function initPaymentRequest(onSuccess, onFailure) {

  //Code excerpted.
  
  //supportedInstrucments includes Android Pay and credit cards.
  let request = new PaymentRequest(supportedInstruments, details);

  if (request.canMakePayment) {
    request.canMakePayment().then(function(result) {
      if (result) {
        onSuccess(request);
      } else {
        onFailure('Cannot make payment');
      }
    }).catch(function(err) {
      onSuccess(request, err);
    });
  } else {
    onSuccess(
      request, 'This browser does not support "can make payment" query');
  }
}

Specifications

Specification Status Comment
Payment Request API
The definition of 'canMakePayment()' in that specification.
Candidate Recommendation Initial definition.

Browser Compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support6116551 No No ?
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support No56 Yes551 No ?6.0

1. From version 55: this feature is behind the dom.payments.request.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.

See Also

Document Tags and Contributors

 Contributors to this page: fscholz, jpmedley, ithinkihaveacat, chrisdavidmills, bunnybooboo
 Last updated by: fscholz,