Google Chrome:支付API在交易成功时返回购买失败

时间:2016-06-26 21:05:44

标签: javascript google-chrome-extension google-api in-app-purchase

我正在使用付款API在Chrome扩展程序内进行应用内购买。

我可以发起购买,它可以运行并激活交易,但回调转到onPurchaseFailed而不是onPurchase。

清单:

"offline_enabled": true,
"name": "__MSG_name__",
"description": "__MSG_description__",
"manifest_version": 2,
"version": "1.1.2",
"default_locale": "en",
"icons": {
    "128": "style/128_on.png"
},
"background": {
    "persistent": true,
    "scripts": [ "js/jquery.min.js","js/bg.js" ]
},
"browser_action": {
   "default_title": "__MSG_name__",
   "default_icon": "style/128_off.png",
   "default_popup": "popup.html"
},
"key": "...",
"oauth2": {
"client_id": "...",
"scopes": [ "https://www.googleapis.com/auth/chromewebstore.readonly" ]
},
"permissions": [ "*://*/*", "activeTab", "tabCapture", "tabs" ]

API购买方法:

google.payments.inapp.buy({
    parameters: {'env': "prod"},
    'sku': sku,
    'success': onPurchase,
    'failure': onPurchaseFailed
});

我得到了:

onPurchaseFailed Object{
  checkoutOrderId:"10370910..."
  response:Object{
    errorType:"PURCHASE_CANCELED"}
}

许可证已激活:

google.payments.inapp.getPurchases({
  'parameters': {'env': 'prod'},
  'success': onLicenseUpdate,
  'failure': onLicenseUpdateFail
});

返回:

createdTime: //some number
itemId: //some string
kind:"chromewebstore#payment"
sku: //some string
state:"ACTIVE"

我怀疑这是因为购买窗口在关闭时发送取消消息,这会触发onPurchaseFailed回调。如何处理?

1 个答案:

答案 0 :(得分:1)

我找到的唯一方法是检查故障回拨时的付款