How to accept Apple Pay with Stripe JS inside WKWebView?

Published

I’m trying to load up a webpage which uses Stripe.js inside a WKWebView on iOS (using Xamarin.Forms).

Everything works fine (can take card payments), except for Apple Pay: paymentRequest.canMakePayment() always returns null.

The same webpage inside a SFSafariViewController works fine, so the issue seems to be related to restrictions inside WKWebView.
However, according to https://webkit.org/blog/9674/new-webkit-features-in-safari-13/ this should now be supported and indeed the same WKWebView also loads up the official Apple Pay demo page (https://applepaydemo.apple.com/) with no issues.

It would seem that the problem is eventually with how Stripe.js works under the hood (perhaps with regards to script injection).

My custom renderer in Xamarin looks like this:

        WKWebView wkWebView;
        protected override void OnElementChanged(ElementChangedEventArgs<NativeWebView> e)
        {
            base.OnElementChanged(e);

            if (Control == null)
            {
                var config = new WKWebViewConfiguration();
                wkWebView = new WKWebView(Frame, config);
                wkWebView.WeakNavigationDelegate = new WebNavigationDelegate();
                SetNativeControl(wkWebView);
            }

            if (e.NewElement != null)
                Control.LoadRequest(new NSUrlRequest(new NSUrl(Element.Url)));
        }

And the JS in the webpage (taken from the Stripe Element samples):

            //set up payment request
            var paymentRequest = stripe.paymentRequest({
                country: 'GB',
                currency: 'gbp',
                total: {
                    label: 'sample order',
                    amount: 100,
                },
                requestPayerName: true,
                requestPayerEmail: true,
            });

            paymentRequest.canMakePayment().then(function (result) {
                // result is always false!
                ...
            });

Are there perhaps additional settings that can be added to the WKWebView to make this work?

Source: Xamarin.ios Questions

Published
Categorised as Uncategorised Tagged , , ,

Answers

Leave a Reply

Your email address will not be published. Required fields are marked *

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq