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

99 lines
2.5 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') {
return "emby.supporter.weekly";
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-01 23:14:04 -07:00
function isPurchaseAvailable(feature) {
2015-05-28 05:49:46 -07:00
return NativeIapManager.isStoreAvailable();
}
2015-10-01 23:14:04 -07:00
function beginPurchase(feature, email) {
var id = getStoreFeatureId(feature);
return MainActivity.beginPurchase(id, 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',
buttonText: 'EmbyPremiereMonthlyWithPrice'
});
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-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,
getStoreFeatureId: getStoreFeatureId,
getSubscriptionOptions: getSubscriptionOptions
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
})();