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

171 lines
4.2 KiB
JavaScript
Raw Normal View History

2015-05-28 05:49:46 -07:00
(function () {
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
}
2015-10-01 23:14:04 -07:00
function getProduct(feature) {
var id;
if (feature == 'embypremieremonthly') {
2015-11-10 11:58:05 -07:00
id = NativeIapManager.getPremiereMonthlySku();
} else {
2015-11-10 11:58:05 -07:00
id = NativeIapManager.getUnlockProductSku();
}
2015-10-01 23:14:04 -07:00
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();
}
function isPurchaseAvailable() {
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);
}
2015-11-13 21:19:05 -07:00
return MainActivity.purchaseUnlock();
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.getPurchaseInfos("window.IapManager.updateProduct");
2015-10-01 23:14:04 -07:00
}
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-11-10 11:58:05 -07:00
var prod = getProduct(o.feature);
o.buttonText = Globalize.translate(o.buttonText, prod.price);
o.owned = prod.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-11-06 08:02:22 -07:00
function isUnlockedOverride(feature) {
var deferred = DeferredBuilder.Deferred();
2015-11-13 21:19:05 -07:00
if (feature == 'playback' || feature == 'livetv') {
deferred.resolveWith(null, [false]);
//isPlaybackUnlockedViaOldApp(deferred);
2015-11-06 08:02:22 -07:00
} else {
deferred.resolveWith(null, [false]);
}
return deferred.promise();
}
function isPlaybackUnlockedViaOldApp(deferred) {
testDeviceId(ConnectionManager.deviceId()).done(function (isUnlocked) {
if (isUnlocked) {
deferred.resolveWith(null, [true]);
return;
}
testDeviceId(device.uuid).done(function (isUnlocked) {
if (isUnlocked) {
deferred.resolveWith(null, [true]);
return;
}
deferred.resolveWith(null, [false]);
});
});
}
function testDeviceId(deviceId) {
var cacheKey = 'oldapp-' + deviceId;
var cacheValue = appStorage.getItem(cacheKey);
if (cacheValue) {
2015-11-13 21:19:05 -07:00
var deferred = DeferredBuilder.Deferred();
2015-11-06 08:02:22 -07:00
deferred.resolveWith(null, [cacheValue == 'true']);
2015-11-13 21:19:05 -07:00
return deferred.promise();
2015-11-06 08:02:22 -07:00
} else {
2015-11-13 21:19:05 -07:00
return HttpClient.send({
2015-11-06 08:02:22 -07:00
type: 'GET',
url: 'https://mb3admin.com/admin/service/statistics/appAccess?application=AndroidV1&deviceId=' + deviceId
}).done(function () {
appStorage.setItem(cacheKey, 'true');
}).fail(function (e) {
if (e.status == 404) {
appStorage.setItem(cacheKey, 'false');
}
});
}
}
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,
2015-11-06 08:02:22 -07:00
onStoreReady: onStoreReady,
isUnlockedOverride: isUnlockedOverride
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
})();