W3cubDocs

/DOM

PaymentRequest.canMakePayment

This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.

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 QuotaExceededError 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 'show()' in that specification.
Working Draft Initial definition.

Browser Compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support No support ? ? ? ?
Feature Android Webview Chrome for Android Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile
Basic support No support 56 ? ? ? ? ?

See Also

© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/PaymentRequest/canMakePayment