Chrome扩展中的应用内购买无法使用。

3

In-App购买界面出现以下错误:

In-App购买截图

错误信息如下:

发生了意外的错误。请稍后再试。关闭

而且,你可以看到一半的界面也是黑色的。

Buy.js:

  /*GOOGLE's CODE
...
*/



 /*CODE FOR IN-APP PURCHASES*/


var prodButPrefix = "btnProdID-";
var statusDiv;

function init() {
  console.log("App Init");
  statusDiv = $("#status");
  //  getProductList();

}

$("#div1").click(function() {
  checkIfBought("package2016");
});


/*****************************************************************************
* Get the list of purchased products from the Chrome Web Store
*****************************************************************************/
var purchased = false;
function getLicenses() {
  console.log("google.payments.inapp.getPurchases");
  console.log("Retreiving list of purchased products...");
  google.payments.inapp.getPurchases({
    'parameters': {env: "prod"},
    'success': onLicenseUpdate,
    'failure': onLicenseUpdateFailed
  });
}

function checkIfBought(sku_init){
  getLicenses();
  function getLicenses() {
    console.log("google.payments.inapp.getPurchases");
    console.log("Retreiving list of purchased products...");
    google.payments.inapp.getPurchases({
      'parameters': {env: "prod"},
      'success': onLicenseUpdate,
      'failure': onLicenseUpdateFailed
    });
  }

  function onLicenseUpdate(response) {
    console.log("onLicenseUpdate", response);
    var licenses = response.response.details;
    var count = licenses.length;
    for (var i = 0; i < count; i++) {
      var license = licenses[i];
      if(sku_init == licenses[i].response.details.sku){ //if purchased
        purchased = true;
      }
      addLicenseDataToProduct(license);
    }
    console.log("");
  }

  function onLicenseUpdateFailed(response) {
    console.log("onLicenseUpdateFailed", response);
    console.log("Error retreiving list of purchased products.");
  }

  if(purchased == false){
    buyProduct("package2016");
  }
}



/*****************************************************************************
* Purchase an item
*****************************************************************************/


function buyProduct(sku) {
  console.log("google.payments.inapp.buy", sku);
  //var sku = "";
  google.payments.inapp.buy({
    'parameters': {'env': 'prod'},
    'sku': sku,
    'success': onPurchase,
    'failure': onPurchaseFailed
  });
}


function onPurchase(purchase) {
  console.log("onPurchase", purchase);
  var jwt = purchase.jwt;
  var cartId = purchase.request.cardId;
  var orderId = purchase.response.orderId;
  console.log("Purchase completed. Order ID: " + orderId);
  getLicenses();
}

function onPurchaseFailed(purchase) {
  console.log("onPurchaseFailed", purchase);
  var reason = purchase.response.errorType;
  console.log("Purchase failed. " + reason);
}

以下是在控制台中打印的内容:

google.payments.inapp.buy package2016

当我关闭应用内支付界面时,会打印出以下内容:

onPurchaseFailed Object {request: Object, response: Object} 购买失败。PURCHASE_CANCELED


请尝试仔细检查您是否正确遵循了此文档中提供的步骤。 - KENdi
@KENdi,你觉得我在“创建和管理您的虚拟商品”部分犯了错误吗?我的代码看起来是否正常? - I-Parliament
@I-Parliament,你能帮我解决这个问题吗? http://stackoverflow.com/questions/40045344/getting-an-oauth-access-token-to-work-for-chrome-extension - uncivilized
2个回答

5

我给Chrome Dev支持发送了一封电子邮件,他们回答说:

在Chrome Web商店中,您不允许购买自己的应用程序/扩展程序。为了测试您的项目,您需要从您拥有的不同帐户访问它(而不是从您的开发者帐户访问)。


0

您可能需要确保不更改/更新buy.js中提供的扩展ID(nmmhkkegccagdldgiimedpiccmgmieda)。

此外,请将onPurchaseFailed对象字符串化并共享,以便我可以帮助确认问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接