应用内购买不适用于Chrome扩展程序 [英] In-App purchases not working in chrome extension

查看:114
本文介绍了应用内购买不适用于Chrome扩展程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应用内购买屏幕正在返回:

应用程序屏幕截图



错误是:


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


正如您所看到的,其中一半也是黑色的。



Buy.js:

  / * GOOGLE的代码
...
* /



/ *应用内购买代码* /


var prodButPrefix =btnProdID-;
var statusDiv;

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


$ b $(#div1)。click(function(){
checkIfBought(package2016);
});


/ ************************************* ****************************************
*获取购买清单Chrome网上应用店的产品
**************************************** ************************************* /
var purchased = false;
函数getLicenses(){
console.log(google.payments.inapp.getPurchases);
console.log(购买产品的退货列表...);
google.payments.inapp.getPurchases({$ b $'参数':{env:prod},
'成功':onLicenseUpdate,
'失败':onLicenseUpdateFailed
});
}

函数checkIfBought(sku_init){
getLicenses();
函数getLicenses(){
console.log(google.payments.inapp.getPurchases);
console.log(购买产品的退货列表...);
google.payments.inapp.getPurchases({$ b $'参数':{env:prod},
'成功':onLicenseUpdate,
'失败':onLicenseUpdateFailed
});
}

函数onLicenseUpdate(响应){
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){//如果购买
购买= true;
}
addLicenseDataToProduct(license);
}
console.log();
}

函数onLicenseUpdateFailed(响应){
console.log(onLicenseUpdateFailed,response);
console.log(购买产品的错误检索清单);
}

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



/ *********************** ************************************************** ****
*购买一件商品
********************************** ******************************************* /


函数buyProduct(sku){
console.log(google.payments.inapp.buy,sku);
// var sku =;
google.payments.inapp.buy({
'参数':{'env':'prod'},
'sku':sku,
'成功':onPurchase ,
'失败':onPurchaseFailed
});
}


功能on购物(购买){
console.log(onPurchase,购买);
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);

$ / code>

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


google.payments.inapp.buy package2016


当我关闭打印应用内支付屏幕:


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



解决方案

我通过电子邮件发送Chrome Dev支持,他们表示: b


在Chrome网上应用店中,您不能购买自己的
应用/扩展程序。为了测试您的物品,您需要从您拥有的不同帐户访问
。 (不是来自您的开发者帐户)。



The In-App purchases screen is returning:

Screenshot of In-App screen

The error is:

An unexpected error has occurred. Please try again later. Dismiss

And as you can see, half of it is also black.

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

This is what is being printed in the console:

google.payments.inapp.buy package2016

When I close the In-App payment screen this is printed:

onPurchaseFailed Object {request: Object, response: Object} Purchase failed. PURCHASE_CANCELED

解决方案

I emailed Chrome Dev support, they said:

In the Chrome Web Store, You are not allowed to purchase your own Apps/Extensions. In order to test your item, you need to access it from different account you have. (Not from your developer account).

这篇关于应用内购买不适用于Chrome扩展程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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