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.
  
  //supportedInstruments 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

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic support
Experimental
Chrome Full support 61
Disabled
Full support 61
Disabled
Disabled From version 61: this feature is behind the #web-payments preference (needs to be set to Enabled). To change preferences in Chrome, visit chrome://flags.
Edge Full support 16Firefox Full support 55
Disabled
Full support 55
Disabled
Disabled 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.
IE No support NoOpera No support NoSafari ? WebView Android No support NoChrome Android Full support 56
Disabled
Full support 56
Disabled
Disabled From version 56: this feature is behind the #web-payments preference (needs to be set to Enabled). To change preferences in Chrome, visit chrome://flags.
Edge Mobile Full support YesFirefox Android Full support 55
Disabled
Full support 55
Disabled
Disabled 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.
Opera Android No support NoSafari iOS ? Samsung Internet Android Full support 6.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
User must explicitly enable this feature.
User must explicitly enable this feature.

See Also

Document Tags and Contributors

Last updated by: timsmiths,