(function () { function isAndroid() { var platform = (device.platform || '').toLowerCase(); return platform.indexOf('android') != -1; } function getPremiumUnlockFeatureId() { if (isAndroid()) { return "com.mb.android.unlock"; } return 'appunlock'; } function validatePlayback(deferred) { // Don't require validation on android if (isAndroid()) { deferred.resolve(); return; } validateFeature(getPremiumUnlockFeatureId(), deferred); } function validateLiveTV(deferred) { if (!isAndroid()) { deferred.resolve(); return; } validateFeature(getPremiumUnlockFeatureId(), deferred); } function validateServerManagement(deferred) { deferred.resolve(); } function getRegistrationInfo(feature, enableSupporterUnlock) { if (!enableSupporterUnlock) { var deferred = $.Deferred(); deferred.resolveWith(null, [{}]); return deferred.promise(); } return ConnectionManager.getRegistrationInfo(feature, ApiClient); } function validateFeature(id, deferred) { var info = IapManager.getProductInfo(id) || {}; if (info.owned) { deferred.resolve(); return; } var productInfo = { enableSupporterUnlock: isAndroid(), enableAppUnlock: IapManager.isPurchaseAvailable(id), id: id, price: info.price }; var prefix = isAndroid() ? 'android' : 'ios'; // Get supporter status getRegistrationInfo(prefix + 'appunlock', productInfo.enableSupporterUnlock).done(function (registrationInfo) { if (registrationInfo.IsRegistered) { deferred.resolve(); return; } showInAppPurchaseInfo(productInfo, registrationInfo, deferred); }).fail(function () { deferred.reject(); }); } function getInAppPurchaseElement(info) { require(['paperbuttonstyle']); cancelInAppPurchase(); var html = ''; html += '
'; html += '
'; html += '
'; html += '

' + Globalize.translate('HeaderUnlockApp') + '

'; html += '

'; 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 += ''; html += Globalize.translate('MessagePaymentServicesUnavailable'); html += ''; } html += '

'; if (info.enableSupporterUnlock) { html += '

'; html += Globalize.translate('MessageToValidateSupporter'); html += '

'; } if (info.enableAppUnlock) { var unlockText = Globalize.translate('ButtonUnlockWithPurchase'); if (info.price) { unlockText = Globalize.translate('ButtonUnlockPrice', info.price); } html += '

'; html += '' + unlockText + ''; html += '

'; } if (info.enableSupporterUnlock) { html += '

'; html += '' + Globalize.translate('ButtonUnlockWithSupporter') + ''; html += '

'; } html += '

'; html += '' + Globalize.translate('ButtonCancel') + ''; html += '

'; html += '
'; html += '
'; html += '
'; $(document.body).append(html); return $('.inAppPurchaseOverlay'); } function cancelInAppPurchase() { $('.inAppPurchaseOverlay').remove(); } var currentDisplayingProductInfo = null; var currentDisplayingDeferred = null; function clearCurrentDisplayingInfo() { currentDisplayingProductInfo = null; currentDisplayingDeferred = null; } function showInAppPurchaseInfo(info, serverRegistrationInfo, deferred) { var elem = getInAppPurchaseElement(info); currentDisplayingProductInfo = info; currentDisplayingDeferred = deferred; $('.btnAppUnlock', elem).on('click', function () { IapManager.beginPurchase(info.id); }); $('.btnCancel', elem).on('click', function () { clearCurrentDisplayingInfo(); cancelInAppPurchase(); deferred.reject(); }); $('.btnSignInSupporter', elem).on('click', function () { clearCurrentDisplayingInfo(); Dashboard.alert({ message: Globalize.translate('MessagePleaseSignInLocalNetwork'), callback: function () { cancelInAppPurchase(); Dashboard.logout(); } }); }); } function onProductUpdated(e, product) { var currentInfo = currentDisplayingProductInfo; var deferred = currentDisplayingDeferred; if (currentInfo && deferred) { if (product.owned && product.id == currentInfo.id) { clearCurrentDisplayingInfo(); cancelInAppPurchase(); deferred.resolve(); } } } 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') { validatePlayback(deferred); } else if (name == 'livetv') { validateLiveTV(deferred); } else if (name == 'manageserver') { validateServerManagement(deferred); } else { deferred.resolve(); } return deferred.promise(); } }; function onIapManagerLoaded() { Events.on(IapManager, 'productupdated', onProductUpdated); } if (isAndroid()) { requirejs(['cordova/android/iap'], onIapManagerLoaded); } else { requirejs(['cordova/iap'], onIapManagerLoaded); } })();