Skip to main content
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.
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 allow attribute 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.
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-pay capability enabled in Xcode. Without this, ApplePaySession will 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.
In Xcode, select your target → Signing & Capabilities+ CapabilityApple Pay. Add your business identifier.
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 window.location.hostname matches your verified domain, which is required for business validation.
HTML
JavaScript
The page reads key, order_id, contact, width and height from query parameters, so the native app controls all configuration without changing the hosted HTML.
Bash
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.
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.
Apple Pay Web Component Integration