Google Pay with WKWebview

Hi,

We developed Native iOS application. Now trying to integrate Google pay.

I am trying to use Tutorial for integrating Google Pay API on website. So trying to load the Html code given at tutorial inside WKWebView ( Tutorial link : https://developers.google.com/pay/api/web/guides/tutorial )

The html code given at above link works inside desktop Safari browser on my Mac laptop. It shows Buy with G Pay button in browser . But when same Html is loaded inside WKWebView, it fails to show GPay button.

It fails at Step-6 of above tutorial ( Determine readiness to pay with the Google Pay API )

I debugged and found that paymentsClient.isReadyToPay returns false. Documentation says that above function i.e., isReadyToPay()  determines if the Google Pay API is supported by the current device and browser ( in our case WKWebView) for specified payment methods.

It indicates that WKWebView can not be used for Google Pay API.

Queries :

1. Please let us know, whether we should look for some other way to implement Google Pay in iOS Native app.

Has anyone succeeded in implementing Google Pay in iOS Native app using WKWebView?

2. Looking at the success of Safari browser, we thought of using SFSafariViewController . But it needs http url . But how can we get it ? We can keep my html file in app sandbox, but it will give me sandbox url and not http url.

Answered by asarmalkar in 683401022

A further update :

We used user agent string listed at https://myip.ms/view/comp_browsers/13092/Safari_14.html

We used  applicationNameForUserAgent property of WKWebViewConfiguration. Referring the table at above link, we used user agent string in this configuration for WKWebView. The button started appearing but its text is still not turning to 'Buy With G Pay '. It is just showing GPay .....

User agent string I used is : "Mozilla/5.0 (iPhone; CPU iPhone OS 14_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 EdgiOS/46.3.13 Mobile/15E148 Safari/605.1.15".

In Safari browser, the button initially takes same appearance as seen in iOS WkWebView but then button text automatically changes and then becomes ' Buy With G Pay '. Looks like something additional happening in Safari browser which needs to be found out.

Accepted Answer

A further update :

We used user agent string listed at https://myip.ms/view/comp_browsers/13092/Safari_14.html

We used  applicationNameForUserAgent property of WKWebViewConfiguration. Referring the table at above link, we used user agent string in this configuration for WKWebView. The button started appearing but its text is still not turning to 'Buy With G Pay '. It is just showing GPay .....

User agent string I used is : "Mozilla/5.0 (iPhone; CPU iPhone OS 14_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 EdgiOS/46.3.13 Mobile/15E148 Safari/605.1.15".

In Safari browser, the button initially takes same appearance as seen in iOS WkWebView but then button text automatically changes and then becomes ' Buy With G Pay '. Looks like something additional happening in Safari browser which needs to be found out.

It works.

Google Pay with WKWebview
 
 
Q