Checking for Apple Pay Availability

Detect if the Apple Pay JS API is available and if payments are possible.


Before displaying an Apple Pay button or creating an Apple Pay session, you must ensure that the Apple Pay JS API is available and enabled on the current device.

To check whether the Apple Pay JS API is available in the browser, verify that the window.ApplePaySession class exists:

if (window.ApplePaySession) {
   // The Apple Pay JS API is available.

Next, check whether payments are possible by calling either canMakePayments or canMakePaymentsWithActiveCard methods,

  • canMakePayments – This method verifies that the device is capable of making Apple Pay payments; it does not verify that the user has a provisioned card for use with Apple Pay on the device. You can call this method at any time.

  • canMakePaymentsWithActiveCard – This method verifies both that the device is capable of making Apple Pay payments, and that the user has at least one provisioned card. This method asynchronously contacts the Apple Pay servers as part of the verification process. You can only call this method if you want to default to Apple Pay during your checkout flow, or if you want to add an Apple Pay button to your product detail page.

The following code shows how to check that a payment method is available before displaying an Apple Pay button:

if (window.ApplePaySession) {
   var merchantIdentifier = '';
   var promise = ApplePaySession.canMakePaymentsWithActiveCard(merchantIdentifier);
   promise.then(function (canMakePayments) {
      if (canMakePayments)
         // Display Apple Pay button here.
}); }

Checking for Apple Pay Availability in China

To provide Apple Pay on the web for customers in China, you must first verify compatibility by checking the browser's user agent string. This string provides information about the customer’s device and operating system.

For the Chinese market, you need to check the user agent string to confirm that:

  • The user's device is an "iPhone" or an "iPad".

  • The device is running iOS 11.2 or later.

For example, the following shows a user agent string received from Safari on an iPhone running iOS 11.2:

Mozilla/5.0 (iPhone; CPU iPhone OS 11_2 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko)CriOS/64.0.3282.112 Mobile/15C202 Safari/604.1

After verifying the user's device type and iOS version, call canMakePayments or canMakePaymentsWithActiveCard as shown earlier, and display the Apple Pay button if the call returns true.

See Also

Apple Pay Availability


Indicates whether the device supports Apple Pay.


Indicates whether the device supports Apple Pay and whether the user has an active card in Wallet.