Available in🇮🇳 India
Apple Pay is supported inside WKWebView since iOS 11.3, but availability depends on the context in which the WebView is running.
Where Apple Pay Works
Where Apple Pay Works
Best Practice: Apple Pay with iFrames
As a best practice, if you want to show Apple Pay in an iframe element when the shopper is using Safari as their browser:
- For shoppers on Safari 17 later: add the
allowattribute to the iframe to let the iframe communicate correctly with Apple Pay APIs:<iframe allow="payment"> </iframe> - Safari 17 is available on iOS 17 and later, and macOS 12 and later.
- For shoppers on Safari 16 or earlier: match the iframe origin and your top-level origin. The protocols, hosts (full domain name), and ports, when specified, must be the same for both pages.
Where Apple Pay Does Not Work
Where Apple Pay Does Not Work
Requirements for WKWebView
Requirements for WKWebView
For Apple Pay to work in your app’s WKWebView, ensure the following:
- Apple Pay entitlement: The host app must have
com.apple.developer.apple-paycapability enabled in Xcode. Without this,ApplePaySessionwill be undefined in the WebView’s JavaScript context. - iOS 11.3+: Minimum OS version for Apple Pay JS API version 3 in WKWebView.
- HTTPS: The page loaded in the WebView must be served over HTTPS.
- Domain verification: The domain served in the WebView must be registered and verified. Refer to the Apple Pay Web Component Integration guide.
- Card in Apple Wallet: The user must have at least one card added to Apple Wallet with face id, touch id or passcode enabled.
Handy TipThere are no WebView-specific restrictions in this SDK. The same eligibility checks the device support, business configuration and card network availability, apply in both Safari and WKWebView. If all prerequisites above are met, Apple Pay will work in a WKWebView exactly as it does in Safari.
Integrate in a Native iOS Checkout
If your app has a native checkout screen and you want to embed the Apple Pay button at a specific position and size, follow the steps given below.Step 1: Add Apple Pay Capability
Step 1: Add Apple Pay Capability
In Xcode, select your target → Signing & Capabilities → + Capability → Apple Pay. Add your business identifier.
Step 2: Host the Payment Page on Your Verified Domain
Step 2: Host the Payment Page on Your Verified Domain
Create a lightweight HTML page on the same domain you registered for Apple Pay verification. The app’s WKWebView will load this URL directly, this ensures The page reads
window.location.hostname matches your verified domain, which is required for business validation.HTML
JavaScript
key, order_id, contact, width and height from query parameters, so the native app controls all configuration without changing the hosted HTML.Step 3: Create a WKWebView and Load the Hosted Page
Step 3: Create a WKWebView and Load the Hosted Page
Bash
Sizing
Sizing
The button size is controlled in two places, keep them in sync:
The WebView acts as a transparent window into your native layout. Set
isOpaque = false and backgroundColor = .clear so only the Apple Pay button is visible.Why Host the Page Instead of Using Inline HTML?
Why Host the Page Instead of Using Inline HTML?
The SDK sends
window.location.hostname as the initiativeContextUrl during Apple Pay business validation. When HTML is loaded via loadHTMLString, the hostname may not match your verified domain, causing business validation to fail. Loading a real URL on your verified domain avoids this entirely.