google wallet inapp payments: Uncaught ReferenceError: goog is not defined. google.payments vs goog.payments

风流意气都作罢 提交于 2019-12-10 12:15:58

问题


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

Recently we see this error:

Uncaught ReferenceError: goog is not defined

The code is very simple:

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

    'packages': ['production_config']

  })

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

回答1:


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

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

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.

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(...);
   }
  }


来源:https://stackoverflow.com/questions/13769248/google-wallet-inapp-payments-uncaught-referenceerror-goog-is-not-defined-goog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!