2015-05-22 12:16:14 -07:00
|
|
|
|
(function () {
|
2015-05-16 12:09:02 -07:00
|
|
|
|
|
2015-05-26 08:31:50 -07:00
|
|
|
|
function isAndroid() {
|
2015-05-17 18:27:48 -07:00
|
|
|
|
|
2015-05-22 12:16:14 -07:00
|
|
|
|
var platform = (device.platform || '').toLowerCase();
|
2015-05-16 12:09:02 -07:00
|
|
|
|
|
2015-05-26 08:31:50 -07:00
|
|
|
|
return platform.indexOf('android') != -1;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-31 14:07:44 -07:00
|
|
|
|
function getPremiumUnlockFeatureId() {
|
2015-05-26 08:31:50 -07:00
|
|
|
|
|
|
|
|
|
if (isAndroid()) {
|
2015-05-31 14:07:44 -07:00
|
|
|
|
return "com.mb.android.unlock";
|
2015-05-22 12:16:14 -07:00
|
|
|
|
}
|
2015-05-16 12:09:02 -07:00
|
|
|
|
|
2015-06-03 21:50:10 -07:00
|
|
|
|
return 'appunlock';
|
2015-05-22 12:16:14 -07:00
|
|
|
|
}
|
2015-05-16 12:09:02 -07:00
|
|
|
|
|
2015-05-31 14:07:44 -07:00
|
|
|
|
function validatePlayback(deferred) {
|
2015-05-17 18:27:48 -07:00
|
|
|
|
|
2015-05-31 14:07:44 -07:00
|
|
|
|
// Don't require validation on android
|
|
|
|
|
if (isAndroid()) {
|
2015-05-26 08:31:50 -07:00
|
|
|
|
deferred.resolve();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-03 21:50:10 -07:00
|
|
|
|
validateFeature(getPremiumUnlockFeatureId(), deferred);
|
2015-05-26 08:31:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-31 14:07:44 -07:00
|
|
|
|
function validateLiveTV(deferred) {
|
2015-05-22 13:15:29 -07:00
|
|
|
|
|
2015-06-03 21:50:10 -07:00
|
|
|
|
validateFeature(getPremiumUnlockFeatureId(), deferred);
|
2015-05-26 08:31:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-26 10:48:05 -07:00
|
|
|
|
function getRegistrationInfo(feature, enableSupporterUnlock) {
|
|
|
|
|
|
|
|
|
|
if (!enableSupporterUnlock) {
|
|
|
|
|
var deferred = $.Deferred();
|
|
|
|
|
deferred.resolveWith(null, [{}]);
|
|
|
|
|
return deferred.promise();
|
|
|
|
|
}
|
|
|
|
|
return ConnectionManager.getRegistrationInfo(feature, ApiClient);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-03 21:50:10 -07:00
|
|
|
|
function validateFeature(id, deferred) {
|
|
|
|
|
|
|
|
|
|
var info = IapManager.getProductInfo(id) || {};
|
2015-05-26 08:31:50 -07:00
|
|
|
|
|
2015-06-03 21:50:10 -07:00
|
|
|
|
if (info.owned) {
|
2015-05-26 08:31:50 -07:00
|
|
|
|
deferred.resolve();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-26 10:48:05 -07:00
|
|
|
|
var productInfo = {
|
|
|
|
|
enableSupporterUnlock: isAndroid(),
|
2015-06-03 21:50:10 -07:00
|
|
|
|
enableAppUnlock: IapManager.isPurchaseAvailable(id),
|
|
|
|
|
id: id,
|
|
|
|
|
price: info.price
|
2015-05-26 10:48:05 -07:00
|
|
|
|
};
|
|
|
|
|
|
2015-05-27 22:51:48 -07:00
|
|
|
|
var prefix = isAndroid() ? 'android' : 'ios';
|
|
|
|
|
|
2015-05-26 08:31:50 -07:00
|
|
|
|
// Get supporter status
|
2015-05-27 22:51:48 -07:00
|
|
|
|
getRegistrationInfo(prefix + 'appunlock', productInfo.enableSupporterUnlock).done(function (registrationInfo) {
|
2015-05-26 08:31:50 -07:00
|
|
|
|
|
|
|
|
|
if (registrationInfo.IsRegistered) {
|
|
|
|
|
deferred.resolve();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-26 10:48:05 -07:00
|
|
|
|
showInAppPurchaseInfo(productInfo, registrationInfo, deferred);
|
2015-05-26 08:31:50 -07:00
|
|
|
|
|
|
|
|
|
}).fail(function () {
|
|
|
|
|
deferred.reject();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-26 10:48:05 -07:00
|
|
|
|
function getInAppPurchaseElement(info) {
|
|
|
|
|
|
|
|
|
|
cancelInAppPurchase();
|
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
html += '<div class="inAppPurchaseOverlay" style="background-image:url(css/images/splash.jpg);top:0;left:0;right:0;bottom:0;position:fixed;background-position:center center;background-size:100% 100%;background-repeat:no-repeat;z-index:999999;">';
|
|
|
|
|
html += '<div class="inAppPurchaseOverlayInner" style="background:rgba(10,10,10,.8);width:100%;height:100%;color:#eee;">';
|
|
|
|
|
|
|
|
|
|
|
2015-06-03 21:50:10 -07:00
|
|
|
|
html += '<div class="inAppPurchaseForm" style="margin: 0 auto;padding: 30px 1em 0;">';
|
2015-05-26 10:48:05 -07:00
|
|
|
|
|
|
|
|
|
html += '<h1 style="color:#fff;">' + Globalize.translate('HeaderUnlockApp') + '</h1>';
|
|
|
|
|
|
|
|
|
|
html += '<p style="margin:2em 0;">';
|
|
|
|
|
|
|
|
|
|
if (info.enableSupporterUnlock && info.enableAppUnlock) {
|
|
|
|
|
html += Globalize.translate('MessageUnlockAppWithPurchaseOrSupporter');
|
|
|
|
|
}
|
|
|
|
|
else if (info.enableSupporterUnlock) {
|
|
|
|
|
html += Globalize.translate('MessageUnlockAppWithSupporter');
|
|
|
|
|
} else if (info.enableAppUnlock) {
|
|
|
|
|
html += Globalize.translate('MessageUnlockAppWithPurchase');
|
|
|
|
|
} else {
|
|
|
|
|
html += '<span style="color:red;">';
|
|
|
|
|
html += Globalize.translate('MessagePaymentServicesUnavailable');
|
|
|
|
|
html += '</span>';
|
|
|
|
|
}
|
|
|
|
|
html += '</p>';
|
|
|
|
|
|
|
|
|
|
if (info.enableSupporterUnlock) {
|
|
|
|
|
html += '<p style="margin:2em 0;">';
|
|
|
|
|
html += Globalize.translate('MessageToValidateSupporter');
|
|
|
|
|
html += '</p>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (info.enableAppUnlock) {
|
2015-06-03 21:50:10 -07:00
|
|
|
|
|
|
|
|
|
var unlockText = Globalize.translate('ButtonUnlockWithPurchase');
|
|
|
|
|
if (info.price) {
|
|
|
|
|
unlockText = Globalize.translate('ButtonUnlockPrice', info.price);
|
|
|
|
|
}
|
|
|
|
|
html += '<button class="btn btnActionAccent btnAppUnlock" data-role="none" type="button"><span>' + unlockText + '</span><i class="fa fa-check"></i></button>';
|
2015-05-26 10:48:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (info.enableSupporterUnlock) {
|
|
|
|
|
html += '<button class="btn btnSignInSupporter" data-role="none" type="button"><span>' + Globalize.translate('ButtonUnlockWithSupporter') + '</span><i class="fa fa-check"></i></button>';
|
|
|
|
|
}
|
2015-05-26 08:31:50 -07:00
|
|
|
|
|
2015-05-26 10:48:05 -07:00
|
|
|
|
html += '<button class="btn btnCancel" data-role="none" type="button"><span>' + Globalize.translate('ButtonCancel') + '</span><i class="fa fa-close"></i></button>';
|
2015-05-26 08:31:50 -07:00
|
|
|
|
|
2015-06-03 21:50:10 -07:00
|
|
|
|
html += '</div>';
|
2015-05-26 10:48:05 -07:00
|
|
|
|
|
|
|
|
|
html += '</div>';
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
|
|
$(document.body).append(html);
|
|
|
|
|
|
|
|
|
|
return $('.inAppPurchaseOverlay');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function cancelInAppPurchase() {
|
|
|
|
|
|
|
|
|
|
$('.inAppPurchaseOverlay').remove();
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-01 07:49:23 -07:00
|
|
|
|
var currentDisplayingProductInfo = null;
|
|
|
|
|
var currentDisplayingDeferred = null;
|
|
|
|
|
|
|
|
|
|
function clearCurrentDisplayingInfo() {
|
|
|
|
|
currentDisplayingProductInfo = null;
|
|
|
|
|
currentDisplayingDeferred = null;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-26 10:48:05 -07:00
|
|
|
|
function showInAppPurchaseInfo(info, serverRegistrationInfo, deferred) {
|
|
|
|
|
|
|
|
|
|
var elem = getInAppPurchaseElement(info);
|
|
|
|
|
|
2015-06-01 07:49:23 -07:00
|
|
|
|
currentDisplayingProductInfo = info;
|
|
|
|
|
currentDisplayingDeferred = deferred;
|
|
|
|
|
|
2015-06-03 21:50:10 -07:00
|
|
|
|
$('.btnAppUnlock', elem).on('click', function () {
|
2015-05-26 10:48:05 -07:00
|
|
|
|
|
2015-05-28 05:49:46 -07:00
|
|
|
|
IapManager.beginPurchase(info.id);
|
2015-05-26 10:48:05 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.btnCancel', elem).on('click', function () {
|
2015-06-01 07:49:23 -07:00
|
|
|
|
|
|
|
|
|
clearCurrentDisplayingInfo();
|
2015-05-26 10:48:05 -07:00
|
|
|
|
cancelInAppPurchase();
|
|
|
|
|
|
2015-06-03 21:50:10 -07:00
|
|
|
|
deferred.reject();
|
2015-05-26 10:48:05 -07:00
|
|
|
|
});
|
|
|
|
|
$('.btnSignInSupporter', elem).on('click', function () {
|
|
|
|
|
|
2015-06-01 07:49:23 -07:00
|
|
|
|
clearCurrentDisplayingInfo();
|
|
|
|
|
|
2015-05-26 10:48:05 -07:00
|
|
|
|
Dashboard.alert({
|
2015-05-26 12:53:12 -07:00
|
|
|
|
message: Globalize.translate('MessagePleaseSignInLocalNetwork'),
|
2015-05-26 10:48:05 -07:00
|
|
|
|
callback: function () {
|
|
|
|
|
cancelInAppPurchase();
|
|
|
|
|
Dashboard.logout();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-05-17 18:27:48 -07:00
|
|
|
|
}
|
2015-05-22 12:16:14 -07:00
|
|
|
|
|
2015-06-01 07:49:23 -07:00
|
|
|
|
function onProductUpdated(e, product) {
|
|
|
|
|
|
|
|
|
|
var currentInfo = currentDisplayingProductInfo;
|
|
|
|
|
var deferred = currentDisplayingDeferred;
|
|
|
|
|
|
|
|
|
|
if (currentInfo && deferred) {
|
|
|
|
|
if (product.owned && product.id == currentInfo.id) {
|
|
|
|
|
|
|
|
|
|
clearCurrentDisplayingInfo();
|
|
|
|
|
cancelInAppPurchase();
|
|
|
|
|
deferred.resolve();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-22 12:16:14 -07:00
|
|
|
|
window.RegistrationServices = {
|
|
|
|
|
|
|
|
|
|
renderPluginInfo: function (page, pkg, pluginSecurityInfo) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
addRecurringFields: function (page, period) {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
initSupporterForm: function (page) {
|
|
|
|
|
|
|
|
|
|
$('.recurringSubscriptionCancellationHelp', page).html('');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
validateFeature: function (name) {
|
|
|
|
|
var deferred = DeferredBuilder.Deferred();
|
|
|
|
|
|
|
|
|
|
if (name == 'playback') {
|
2015-05-23 13:44:15 -07:00
|
|
|
|
validatePlayback(deferred);
|
2015-05-22 12:16:14 -07:00
|
|
|
|
} else if (name == 'livetv') {
|
2015-05-23 13:44:15 -07:00
|
|
|
|
validateLiveTV(deferred);
|
2015-05-22 12:16:14 -07:00
|
|
|
|
} else {
|
|
|
|
|
deferred.resolve();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return deferred.promise();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-06-01 07:49:23 -07:00
|
|
|
|
function onIapManagerLoaded() {
|
|
|
|
|
Events.on(IapManager, 'productupdated', onProductUpdated);
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-31 14:07:44 -07:00
|
|
|
|
if (isAndroid()) {
|
2015-06-03 21:50:10 -07:00
|
|
|
|
requirejs(['thirdparty/cordova/android/iap'], onIapManagerLoaded);
|
2015-05-31 14:07:44 -07:00
|
|
|
|
} else {
|
2015-06-03 21:50:10 -07:00
|
|
|
|
requirejs(['thirdparty/cordova/iap'], onIapManagerLoaded);
|
2015-05-31 14:07:44 -07:00
|
|
|
|
}
|
2015-05-26 08:31:50 -07:00
|
|
|
|
|
2015-05-22 12:16:14 -07:00
|
|
|
|
})();
|