jellyfin-web/dashboard-ui/cordova/android/iap.js

61 lines
1.3 KiB
JavaScript
Raw Normal View History

2015-05-28 05:49:46 -07:00
(function () {
2015-05-31 14:07:44 -07:00
var unlockId = "com.mb.android.unlock";
2015-05-28 05:49:46 -07:00
var updatedProducts = [];
2015-06-03 21:50:10 -07:00
function updateProductInfo(id, owned, price) {
2015-05-28 05:49:46 -07:00
updatedProducts = updatedProducts.filter(function (r) {
return r.id != id;
});
2015-06-01 07:49:23 -07:00
var product = {
2015-05-28 05:49:46 -07:00
id: id,
2015-06-03 21:50:10 -07:00
owned: owned,
price: price
2015-06-01 07:49:23 -07:00
};
updatedProducts.push(product);
Events.trigger(IapManager, 'productupdated', [product]);
2015-05-28 05:49:46 -07:00
}
function getProduct(id) {
var products = updatedProducts.filter(function (r) {
return r.id == id;
});
return products.length ? products[0] : null;
}
function isPurchaseAvailable(id) {
return NativeIapManager.isStoreAvailable();
}
function beginPurchase(id) {
2015-05-31 11:22:51 -07:00
return MainActivity.beginPurchase(id);
2015-05-28 05:49:46 -07:00
}
2015-05-31 12:12:58 -07:00
function onPurchaseComplete(result) {
2015-06-01 07:49:23 -07:00
if (result) {
refreshPurchases();
}
}
function refreshPurchases() {
NativeIapManager.isPurchased(unlockId, "window.IapManager.updateProduct");
2015-05-31 12:12:58 -07:00
}
2015-05-28 05:49:46 -07:00
window.IapManager = {
isPurchaseAvailable: isPurchaseAvailable,
2015-06-03 21:50:10 -07:00
getProductInfo: getProduct,
2015-05-28 05:49:46 -07:00
updateProduct: updateProductInfo,
2015-05-31 12:12:58 -07:00
beginPurchase: beginPurchase,
onPurchaseComplete: onPurchaseComplete
2015-05-28 05:49:46 -07:00
};
2015-06-01 07:49:23 -07:00
refreshPurchases();
2015-05-28 05:49:46 -07:00
})();