使用 iOS WKWebview 的 Google Pay

时间:2021-08-01 17:34:00

标签: ios wkwebview google-pay

我们开发了原生 iOS 应用程序。现在尝试将 Google Pay 与 iOS 应用程序集成。 我们的应用程序存在于 11 个国家/地区。最初,我们想为任何列出的国家/地区做 POC,但不想从印度开始。

我们正在尝试遵循在网站上集成 Google Pay API 的教程。因此尝试加载 iOS WKWebView 中教程中给出的 Html 代码( 教程链接https://developers.google.com/pay/api/web/guides/tutorial )

上面链接中给出的 html 代码适用于我的 Mac 笔记本电脑上的 mac 桌面 Safari 浏览器。它在浏览器中显示“使用 G Pay 购买”按钮。同样点击它,我可以看到签证测试卡。但是当在 WKWebView 中加载相同的 Html 时,它最初无法显示 GPay 按钮。

它最初在上述教程的第 6 步失败(确定是否准备好使用 Google Pay API 支付)

我调试发现paymentsClient.isReadyToPay 返回false。文档说,上述函数,即 isReadyToPay() 确定当前设备和浏览器(在我们的例子中为 WKWebView)是否支持指定付款方式的 Google Pay API。

为了克服这一点, 我们使用了 https://myip.ms/view/comp_browsers/13092/Safari_14.html

中列出的 Safari 浏览器的用户代理字符串

我们使用了 WKWebViewConfiguration 的 applicationNameForUserAgent 属性。参考上面链接中的表格,我们在此配置中为 WKWebView 使用了用户代理字符串。

按钮开始出现,但其文字仍未变成'Buy With G Pay'。它只是显示'GPay .....' 在 Safari 浏览器中,按钮文本会立即更改。

查询:

在更改按钮文本时,iOS WKWebview 中哪些 JS 代码必须失败?

1 个答案:

答案 0 :(得分:0)

更新:

以上问题已解决。

使用 iOS WKWebView,我可以在使用我的 gmail id 签名时看到测试卡,该 ID 添加到在测试卡套件 (https://groups.google.com/forum/#!forum/googlepay-test-mode-stub-data) 中指定的用户组 https://developers.google.com/pay/api/android/guides/resources/test-card-suite

但现在无法生成令牌。 因此我决定在 Safari 浏览器上测试它。我在 Safari 和 Chrome 浏览器中打开 HTML 文件进行测试。

HTML 代码在 Chrome 浏览器中工作并生成付款令牌。但是在Safari浏览器中尝试使用相同的Html时,无法生成支付令牌数据。

以下代码中的某些日志语句未在 Safari 中打印:

function onGooglePaymentButtonClicked() 
{
  const paymentDataRequest = getGooglePaymentDataRequest();
  paymentDataRequest.transactionInfo = getGoogleTransactionInfo();

  const paymentsClient = getGooglePaymentsClient();
  console.log("loadPaymentData here came");
  paymentsClient.loadPaymentData(paymentDataRequest)
      .then(function(paymentData)
 {
        // handle the response
        console.log("here came");
        processPayment(paymentData);
      })
      .catch(function(err) {
        // show error in developer console for debugging
        console.log("here came exception");
        console.error(err);
      });
}

console.log("here come") 没有打印出来。

console.log("here come exception") 也没有打印出来。

在 Safari 浏览器中找不到 loadPaymentData JS 函数的问题。 一旦在 Safari 浏览器中成功,我将在 iOS WKWebView 中尝试。