ApplePay on WKWebview

11.5k Views Asked by At

I am trying to load ApplePay popup on WKWebView. I did my initial leg work by implementing it but it does not load up.

Is there something extra I need to implement to make it work ? There is no proper documentation on apple regarding apple pay either.

5

There are 5 best solutions below

0
On

The above iOS 13 restriction is lifted with iOS 16:

https://developer.apple.com/documentation/safari-release-notes/safari-16-release-notes

Apple Pay New Features: Added support for allowing scripts to be injected into WKWebView that have used Apple Pay (and vice versa).

0
On

I think you need to use SFSafariViewController.

iOS 10. Apple Pay JavaScript is supported on all iOS devices with a Secure Element. It is supported both in Safari and in SFSafariViewControllerobjects.

1
On

Seems that there might be solution: https://webkit.org/blog/9674/new-webkit-features-in-safari-13/

Apple Pay in WKWebView In iOS 13, webpages loaded in WKWebView can now accept Apple Pay. In order to protect the security of Apple Pay transactions in WKWebView, Apple Pay cannot be used alongside of script injection APIs such as WKUserScript or evaluateJavaScript(_:completionHandler:).

If these APIs are invoked before a webpage uses Apple Pay, Apple Pay will be disabled. If a webpage uses Apple Pay before evaluateJavaScript(_:completionHandler:) is invoked, the completion handler will be called with a non-nil NSError. These restrictions are reset every time the top frame is navigated.

1
On

Even with script injection, Apple Pay on WKWebView seems to be allowed on safari version 16+.

https://developer.apple.com/documentation/safari-release-notes/safari-16-release-notes

Apple Pay New Features: Added support for allowing scripts to be injected into WKWebView that have used Apple Pay (and vice versa).

0
On

Apple Pay is only supported in SFSafariViewController, and not in UIWebView nor WKWebview.