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

112 lines
2.8 KiB
JavaScript
Raw Normal View History

2015-05-28 05:49:46 -07:00
(function () {
var updatedProducts = [];
2015-10-01 23:14:04 -07:00
function getStoreFeatureId(feature) {
if (feature == 'embypremieremonthly') {
2015-10-10 17:39:30 -07:00
return "emby.supporter.monthly";
2015-10-01 23:14:04 -07:00
}
return "com.mb.android.unlock";
}
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
}
2015-10-01 23:14:04 -07:00
function getProduct(feature) {
var id = getStoreFeatureId(feature);
2015-05-28 05:49:46 -07:00
var products = updatedProducts.filter(function (r) {
return r.id == id;
});
return products.length ? products[0] : null;
}
2015-10-10 17:39:30 -07:00
var storeReady = false;
function onStoreReady() {
storeReady = true;
refreshPurchases();
}
2015-10-01 23:14:04 -07:00
function isPurchaseAvailable(feature) {
2015-05-28 05:49:46 -07:00
2015-10-10 17:39:30 -07:00
return storeReady;
2015-05-28 05:49:46 -07:00
}
2015-10-01 23:14:04 -07:00
function beginPurchase(feature, email) {
2015-10-10 17:39:30 -07:00
if (feature == 'embypremieremonthly') {
return MainActivity.purchasePremiereMonthly(email);
}
if (feature == 'embypremiereweekly') {
return MainActivity.purchasePremiereWeekly(email);
}
return MainActivity.purchaseUnlock(email);
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() {
2015-10-01 23:14:04 -07:00
NativeIapManager.isPurchased(getStoreFeatureId("") + "|" + getStoreFeatureId("embypremieremonthly"), "window.IapManager.updateProduct");
//NativeIapManager.isPurchased(getStoreFeatureId("embypremieremonthly"), "window.IapManager.updateProduct");
}
function getSubscriptionOptions() {
var deferred = DeferredBuilder.Deferred();
var options = [];
options.push({
feature: 'embypremieremonthly',
2015-10-08 09:22:14 -07:00
buttonText: 'EmbyPremiereMonthly'
2015-10-01 23:14:04 -07:00
});
options = options.filter(function (o) {
return getProduct(o.feature) != null;
}).map(function (o) {
2015-10-02 10:55:26 -07:00
o.buttonText = Globalize.translate(o.buttonText, getProduct(o.feature).price);
2015-11-02 10:25:01 -07:00
o.owned = getProduct(o.feature).owned;
2015-10-01 23:14:04 -07:00
return o;
});
deferred.resolveWith(null, [options]);
return deferred.promise();
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,
2015-10-01 23:14:04 -07:00
onPurchaseComplete: onPurchaseComplete,
2015-10-10 17:39:30 -07:00
getSubscriptionOptions: getSubscriptionOptions,
onStoreReady: onStoreReady
2015-05-28 05:49:46 -07:00
};
2015-10-10 17:39:30 -07:00
NativeIapManager.initStore();
2015-05-28 05:49:46 -07:00
})();