Detect if the Apple Pay JS API is available and if payments are possible.
- Apple Pay JS
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 class exists:
can– 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.
can– 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.
Make Payments With Active Card
The following code shows how to check that a payment method is available before displaying an Apple Pay button:
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 "
i" or an "
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: