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) {
|
|
|
|
|
|
2015-11-04 16:49:06 -07:00
|
|
|
|
var id;
|
|
|
|
|
if (feature == 'embypremieremonthly') {
|
2015-11-10 11:58:05 -07:00
|
|
|
|
id = NativeIapManager.getPremiereMonthlySku();
|
2015-11-04 16:49:06 -07:00
|
|
|
|
} else {
|
2015-11-10 11:58:05 -07:00
|
|
|
|
id = NativeIapManager.getUnlockProductSku();
|
2015-11-04 16:49:06 -07:00
|
|
|
|
}
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-04 16:49:06 -07:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
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-11-04 16:49:06 -07:00
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
if (feature == 'playback') {
|
|
|
|
|
isPlaybackUnlockedViaOldApp(deferred);
|
|
|
|
|
} else if (feature == 'livetv') {
|
|
|
|
|
isLiveTvUnlockedViaOldApp(deferred);
|
|
|
|
|
} 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 deferred = DeferredBuilder.Deferred();
|
|
|
|
|
|
|
|
|
|
var cacheKey = 'oldapp-' + deviceId;
|
|
|
|
|
var cacheValue = appStorage.getItem(cacheKey);
|
|
|
|
|
if (cacheValue) {
|
|
|
|
|
|
|
|
|
|
deferred.resolveWith(null, [cacheValue == 'true']);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
HttpClient.send({
|
|
|
|
|
|
|
|
|
|
type: 'GET',
|
|
|
|
|
url: 'https://mb3admin.com/admin/service/statistics/appAccess?application=AndroidV1&deviceId=' + deviceId
|
|
|
|
|
|
|
|
|
|
}).done(function () {
|
|
|
|
|
|
|
|
|
|
appStorage.setItem(cacheKey, 'true');
|
|
|
|
|
deferred.resolveWith(null, [true]);
|
|
|
|
|
|
|
|
|
|
}).fail(function (e) {
|
|
|
|
|
|
|
|
|
|
if (e.status == 404) {
|
|
|
|
|
appStorage.setItem(cacheKey, 'false');
|
|
|
|
|
}
|
|
|
|
|
deferred.resolveWith(null, [false]);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return deferred.promise();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isLiveTvUnlockedViaOldApp(deferred) {
|
|
|
|
|
|
|
|
|
|
isPlaybackUnlockedViaOldApp(deferred);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
})();
|