谷歌钱包inapp付款:未捕获ReferenceError:goog未定义。 google.payments vs goog.payments [英] google wallet inapp payments: Uncaught ReferenceError: goog is not defined. google.payments vs goog.payments

查看:222
本文介绍了谷歌钱包inapp付款:未捕获ReferenceError:goog未定义。 google.payments vs goog.payments的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自谷歌io 2012以来,我们一直在使用谷歌钱包inapp-payments。

we've been using google wallet inapp-payments since google io 2012.

最近我们看到这个错误:

Recently we see this error:

未捕获的ReferenceError:未定义goog

Uncaught ReferenceError: goog is not defined

代码非常简单:

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
  google.load('payments', '1.0', {

    'packages': ['production_config']

  })

然后我们使用jquery document.ready回调来调用goog.payments.inapp.buy,但似乎goog对象是不是那时创造的。这似乎是一种竞争条件。购买功能只需调用goog.payments.inapp.buy

Then we use the jquery document.ready callback to call goog.payments.inapp.buy, but it seems that the goog object is not created by then. This seems to be a race condition. purchase function simply calls goog.payments.inapp.buy

 $(document).ready(function() {
      purchase('Item1'); //function to call goog.payments.inapp.buy
       });

这也令人困惑,因为此页面 https://sandbox.google.com/checkout/customer/gadget/inapp/demo.html 显示购买的电话是:

It is also confusing because this page https://sandbox.google.com/checkout/customer/gadget/inapp/demo.html shows the call to buy is:

google.payments.inapp.buy

此页面 https:/ /developers.google.com/in-app-payments/docs/tutorial#3 显示购买的电话是:

while this page https://developers.google.com/in-app-payments/docs/tutorial#3 shows the call to buy is:

goog.payments.inapp.buy


推荐答案

之后一些额外的搜索(也是因为编写问题的过程)已经找到了一个解决方案:

After some additional searching (also because of the process of writing the question) a solution has been found:

参见 https://developers.google.com/in-app-payments/docs/tutorial#3


重要:如果API库未加载,则对buy()的调用将失败
。您可以使用Google Loader回调选项在步骤3中指定onClick
处理程序上的按钮来避免此问题。对于使用google.load()使用可选设置的
详细信息,请参阅Google
Loader开发人员指南。

Important: If the API library hasn't loaded, the call to buy() will fail. You can avoid this problem by specifying the button onClick handler in step 3, using the Google Loader callback option. For details on using optional settings with google.load(), see the Google Loader Developer's Guide.

使用google.load调用的回调非常重要,以避免竞争条件。

It is important to use the callback of the google.load call in order to avoid race conditions.

google.load('payments', '1.0', {
  'packages': ['production_config']

  ,"callback": function() {
          // wait for goog object to exist before using it.
          //goog.payments.inapp.buy(...);
   }
  }

这篇关于谷歌钱包inapp付款:未捕获ReferenceError:goog未定义。 google.payments vs goog.payments的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆