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