本文介绍了谷歌钱包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
       });

这也令人困惑,因为此页面显示购买的电话是:

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

此页面显示购买的电话是:

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:

参见

使用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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 16:02