7

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.

lifemoveson
  • 1,661
  • 8
  • 28
  • 55

5 Answers5

7

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.

petr.sigut
  • 111
  • 1
  • 4
4

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

Vandit Mehta
  • 2,572
  • 26
  • 41
3

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).

Frans
  • 780
  • 7
  • 20
2

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.

Craig Yu
  • 37
  • 3
1

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).

Robillo
  • 192
  • 11
  • I can confirm that WKWebView.evaluateJavaScript() is working since iOS v16 and it's Safari. In iOS v15 when evaluateJavaScript() is called before starting Apple Pay then ApplePaySession.canMakePayments() returns false. If Apple Pay is started before evaluateJavaScript() then ApplePaySession.canMakePayments() returns true and evaluateJavaScript() does not work - script is not executed but ignored. – mikep Jun 15 '23 at 13:23