(function () { function isAndroid() { var platform = (device.platform || '').toLowerCase(); return platform.indexOf('android') != -1; } function validatePlayback(deferred) { // Don't require validation on android if (isAndroid()) { deferred.resolve(); return; } validateFeature({ id: 'premiumunlock' }, deferred); } function validateLiveTV(deferred) { // Don't require validation if not android if (!isAndroid()) { deferred.resolve(); return; } validateFeature({ id: 'premiumunlock' }, deferred); } function validateSmb(deferred) { // Don't require validation if not android if (!isAndroid()) { deferred.resolve(); return; } validateFeature({ id: 'premiumunlock' }, deferred); } function getRegistrationInfo(feature, enableSupporterUnlock) { if (!enableSupporterUnlock) { var deferred = $.Deferred(); deferred.resolveWith(null, [{}]); return deferred.promise(); } return ConnectionManager.getRegistrationInfo(feature, ApiClient); } function validateFeature(info, deferred) { if (IapManager.hasPurchased(info.id)) { deferred.resolve(); return; } var productInfo = { enableSupporterUnlock: isAndroid(), enableAppUnlock: IapManager.isPurchaseAvailable(info.id), id: info.id }; 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) { 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) { html += ''; } if (info.enableSupporterUnlock) { html += ''; } html += ''; html += '
'; html += '
'; html += '
'; $(document.body).append(html); return $('.inAppPurchaseOverlay'); } function cancelInAppPurchase() { $('.inAppPurchaseOverlay').remove(); } function showInAppPurchaseInfo(info, serverRegistrationInfo, deferred) { var elem = getInAppPurchaseElement(info); $('.inAppPurchaseForm', elem).on('submit', function () { IapManager.beginPurchase(info.id); return false; }); $('.btnCancel', elem).on('click', function () { cancelInAppPurchase(); // For testing purposes if (!info.enableSupporterUnlock && !info.enableAppUnlock) { deferred.resolve(); } else { deferred.reject(); } }); $('.btnSignInSupporter', elem).on('click', function () { Dashboard.alert({ message: Globalize.translate('MessagePleaseSignInLocalNetwork'), callback: function () { cancelInAppPurchase(); Dashboard.logout(); } }); }); } 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 { deferred.resolve(); } return deferred.promise(); } }; var depends = isAndroid() ? 'thirdparty/cordova/android/iap' : 'thirdparty/cordova/iap'; requirejs([depends]); })();