2015-05-22 12:16:14 -07:00
|
|
|
|
(function () {
|
2015-05-16 12:09:02 -07:00
|
|
|
|
|
2015-10-01 23:14:04 -07:00
|
|
|
|
function getRegistrationInfo(feature) {
|
2015-05-26 10:48:05 -07:00
|
|
|
|
|
|
|
|
|
return ConnectionManager.getRegistrationInfo(feature, ApiClient);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-01 23:14:04 -07:00
|
|
|
|
function validateFeature(feature, deferred) {
|
2015-06-03 21:50:10 -07:00
|
|
|
|
|
2015-11-02 10:25:01 -07:00
|
|
|
|
var unlockableProduct = IapManager.getProductInfo(feature) || {};
|
2015-05-26 08:31:50 -07:00
|
|
|
|
|
2015-11-02 10:25:01 -07:00
|
|
|
|
if (unlockableProduct.owned) {
|
2015-05-26 08:31:50 -07:00
|
|
|
|
deferred.resolve();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-02 10:55:26 -07:00
|
|
|
|
var unlockableProductInfo = IapManager.isPurchaseAvailable(feature) ? {
|
2015-11-02 10:25:01 -07:00
|
|
|
|
enableAppUnlock: true,
|
|
|
|
|
id: unlockableProduct.id,
|
|
|
|
|
price: unlockableProduct.price,
|
2015-10-01 23:14:04 -07:00
|
|
|
|
feature: feature
|
2015-10-02 10:55:26 -07:00
|
|
|
|
|
|
|
|
|
} : null;
|
2015-05-26 10:48:05 -07:00
|
|
|
|
|
2015-10-01 23:14:04 -07:00
|
|
|
|
var prefix = $.browser.android ? 'android' : 'ios';
|
2015-05-27 22:51:48 -07:00
|
|
|
|
|
2015-11-06 08:02:22 -07:00
|
|
|
|
IapManager.isUnlockedOverride(feature).done(function (isUnlocked) {
|
2015-05-26 08:31:50 -07:00
|
|
|
|
|
2015-11-06 08:02:22 -07:00
|
|
|
|
if (isUnlocked) {
|
2015-05-26 08:31:50 -07:00
|
|
|
|
deferred.resolve();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-06 08:02:22 -07:00
|
|
|
|
// Get supporter status
|
|
|
|
|
getRegistrationInfo(prefix + 'appunlock').done(function (registrationInfo) {
|
2015-10-01 23:14:04 -07:00
|
|
|
|
|
2015-11-06 08:02:22 -07:00
|
|
|
|
if (registrationInfo.IsRegistered) {
|
2015-11-02 10:25:01 -07:00
|
|
|
|
deferred.resolve();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-06 08:02:22 -07:00
|
|
|
|
IapManager.getSubscriptionOptions().done(function (subscriptionOptions) {
|
2015-10-02 10:55:26 -07:00
|
|
|
|
|
2015-11-06 08:02:22 -07:00
|
|
|
|
if (subscriptionOptions.filter(function (p) {
|
|
|
|
|
return p.owned;
|
|
|
|
|
}).length > 0) {
|
|
|
|
|
deferred.resolve();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var dialogOptions = {
|
|
|
|
|
title: Globalize.translate('HeaderUnlockApp')
|
|
|
|
|
};
|
2015-05-26 08:31:50 -07:00
|
|
|
|
|
2015-11-06 08:02:22 -07:00
|
|
|
|
showInAppPurchaseInfo(subscriptionOptions, unlockableProductInfo, registrationInfo, dialogOptions, deferred);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}).fail(function () {
|
|
|
|
|
deferred.reject();
|
|
|
|
|
});
|
2015-05-26 08:31:50 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-02 10:55:26 -07:00
|
|
|
|
function cancelInAppPurchase() {
|
|
|
|
|
|
|
|
|
|
var elem = document.querySelector('.inAppPurchaseOverlay');
|
|
|
|
|
if (elem) {
|
|
|
|
|
PaperDialogHelper.close(elem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var isCancelled = true;
|
|
|
|
|
var currentDisplayingProductInfos = [];
|
|
|
|
|
var currentDisplayingDeferred = null;
|
|
|
|
|
|
|
|
|
|
function clearCurrentDisplayingInfo() {
|
|
|
|
|
currentDisplayingProductInfos = [];
|
|
|
|
|
currentDisplayingDeferred = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showInAppPurchaseElement(subscriptionOptions, unlockableProductInfo, dialogOptions, deferred) {
|
|
|
|
|
|
|
|
|
|
cancelInAppPurchase();
|
|
|
|
|
|
|
|
|
|
// clone
|
|
|
|
|
currentDisplayingProductInfos = subscriptionOptions.slice(0);
|
|
|
|
|
|
|
|
|
|
if (unlockableProductInfo) {
|
|
|
|
|
currentDisplayingProductInfos.push(unlockableProductInfo);
|
|
|
|
|
}
|
2015-05-26 10:48:05 -07:00
|
|
|
|
|
2015-10-01 23:14:04 -07:00
|
|
|
|
var dlg = PaperDialogHelper.createDialog();
|
2015-05-26 10:48:05 -07:00
|
|
|
|
|
|
|
|
|
var html = '';
|
2015-10-01 23:14:04 -07:00
|
|
|
|
html += '<h2 class="dialogHeader">';
|
2015-10-20 22:10:02 -07:00
|
|
|
|
html += '<paper-fab icon="arrow-back" mini class="btnCloseDialog"></paper-fab>';
|
2015-10-02 10:55:26 -07:00
|
|
|
|
html += '<div style="display:inline-block;margin-left:.6em;vertical-align:middle;">' + dialogOptions.title + '</div>';
|
2015-10-01 23:14:04 -07:00
|
|
|
|
html += '</h2>';
|
2015-05-26 10:48:05 -07:00
|
|
|
|
|
2015-10-01 23:14:04 -07:00
|
|
|
|
html += '<div class="editorContent">';
|
2015-05-26 10:48:05 -07:00
|
|
|
|
|
2015-10-01 23:14:04 -07:00
|
|
|
|
html += '<form style="max-width: 800px;margin:auto;">';
|
2015-05-26 10:48:05 -07:00
|
|
|
|
html += '<p style="margin:2em 0;">';
|
|
|
|
|
|
2015-10-02 10:55:26 -07:00
|
|
|
|
if (unlockableProductInfo) {
|
2015-05-26 10:48:05 -07:00
|
|
|
|
html += Globalize.translate('MessageUnlockAppWithPurchaseOrSupporter');
|
|
|
|
|
}
|
2015-10-01 23:14:04 -07:00
|
|
|
|
else {
|
2015-05-26 10:48:05 -07:00
|
|
|
|
html += Globalize.translate('MessageUnlockAppWithSupporter');
|
|
|
|
|
}
|
|
|
|
|
html += '</p>';
|
|
|
|
|
|
2015-10-01 23:14:04 -07:00
|
|
|
|
html += '<p style="margin:2em 0;">';
|
|
|
|
|
html += Globalize.translate('MessageToValidateSupporter');
|
|
|
|
|
html += '</p>';
|
2015-05-26 10:48:05 -07:00
|
|
|
|
|
2015-10-02 10:55:26 -07:00
|
|
|
|
if (unlockableProductInfo) {
|
2015-06-03 21:50:10 -07:00
|
|
|
|
|
|
|
|
|
var unlockText = Globalize.translate('ButtonUnlockWithPurchase');
|
2015-10-02 10:55:26 -07:00
|
|
|
|
if (unlockableProductInfo.price) {
|
|
|
|
|
unlockText = Globalize.translate('ButtonUnlockPrice', unlockableProductInfo.price);
|
2015-06-03 21:50:10 -07:00
|
|
|
|
}
|
2015-06-23 15:13:06 -07:00
|
|
|
|
html += '<p>';
|
2015-10-02 10:55:26 -07:00
|
|
|
|
html += '<paper-button raised class="secondary block btnPurchase" data-feature="' + unlockableProductInfo.feature + '"><iron-icon icon="check"></iron-icon><span>' + unlockText + '</span></paper-button>';
|
2015-06-23 15:13:06 -07:00
|
|
|
|
html += '</p>';
|
2015-10-01 23:14:04 -07:00
|
|
|
|
}
|
2015-09-08 13:40:48 -07:00
|
|
|
|
|
2015-10-01 23:14:04 -07:00
|
|
|
|
for (var i = 0, length = subscriptionOptions.length; i < length; i++) {
|
|
|
|
|
|
|
|
|
|
html += '<p>';
|
|
|
|
|
html += '<paper-button raised class="submit block btnPurchase" data-email="true" data-feature="' + subscriptionOptions[i].feature + '"><iron-icon icon="check"></iron-icon><span>';
|
|
|
|
|
html += subscriptionOptions[i].buttonText;
|
|
|
|
|
html += '</span></paper-button>';
|
|
|
|
|
html += '</p>';
|
2015-05-26 10:48:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-01 23:14:04 -07:00
|
|
|
|
if (IapManager.restorePurchase) {
|
|
|
|
|
html += '<p>';
|
|
|
|
|
html += '<paper-button raised class="secondary block btnRestorePurchase" style="background-color: #673AB7;"><iron-icon icon="check"></iron-icon><span>' + Globalize.translate('ButtonRestorePreviousPurchase') + '</span></paper-button>';
|
|
|
|
|
html += '</p>';
|
|
|
|
|
}
|
2015-05-26 08:31:50 -07:00
|
|
|
|
|
2015-10-01 23:14:04 -07:00
|
|
|
|
html += '</form>';
|
2015-06-03 21:50:10 -07:00
|
|
|
|
html += '</div>';
|
2015-05-26 10:48:05 -07:00
|
|
|
|
|
2015-10-01 23:14:04 -07:00
|
|
|
|
dlg.innerHTML = html;
|
|
|
|
|
document.body.appendChild(dlg);
|
|
|
|
|
|
2015-10-02 10:55:26 -07:00
|
|
|
|
initInAppPurchaseElementEvents(dlg, deferred);
|
2015-05-26 10:48:05 -07:00
|
|
|
|
|
2015-10-01 23:14:04 -07:00
|
|
|
|
PaperDialogHelper.openWithHash(dlg, 'iap');
|
2015-05-26 10:48:05 -07:00
|
|
|
|
|
2015-10-01 23:14:04 -07:00
|
|
|
|
$('.btnCloseDialog', dlg).on('click', function () {
|
|
|
|
|
|
|
|
|
|
PaperDialogHelper.close(dlg);
|
|
|
|
|
});
|
|
|
|
|
|
2015-10-07 14:42:29 -07:00
|
|
|
|
$(dlg).on('iron-overlay-closed', function () {
|
|
|
|
|
|
|
|
|
|
if (window.TabBar) {
|
|
|
|
|
TabBar.show();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2015-10-01 23:14:04 -07:00
|
|
|
|
dlg.classList.add('inAppPurchaseOverlay');
|
2015-06-01 07:49:23 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-02 10:55:26 -07:00
|
|
|
|
function initInAppPurchaseElementEvents(elem, deferred) {
|
2015-05-26 10:48:05 -07:00
|
|
|
|
|
2015-10-02 10:55:26 -07:00
|
|
|
|
isCancelled = true;
|
2015-05-26 10:48:05 -07:00
|
|
|
|
|
2015-10-02 10:55:26 -07:00
|
|
|
|
$('.btnPurchase', elem).on('click', function () {
|
2015-06-01 07:49:23 -07:00
|
|
|
|
|
2015-10-02 10:55:26 -07:00
|
|
|
|
isCancelled = false;
|
2015-05-26 10:48:05 -07:00
|
|
|
|
|
2015-10-02 10:55:26 -07:00
|
|
|
|
if (this.getAttribute('data-email') == 'true') {
|
|
|
|
|
promptForEmail(this.getAttribute('data-feature'));
|
|
|
|
|
} else {
|
|
|
|
|
IapManager.beginPurchase(this.getAttribute('data-feature'));
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-05-26 10:48:05 -07:00
|
|
|
|
|
2015-10-02 10:55:26 -07:00
|
|
|
|
$('.btnRestorePurchase', elem).on('click', function () {
|
2015-09-08 13:40:48 -07:00
|
|
|
|
|
2015-10-02 10:55:26 -07:00
|
|
|
|
isCancelled = false;
|
2015-10-10 17:39:30 -07:00
|
|
|
|
IapManager.restorePurchase();
|
2015-10-02 10:55:26 -07:00
|
|
|
|
});
|
2015-09-08 13:40:48 -07:00
|
|
|
|
|
2015-10-02 10:55:26 -07:00
|
|
|
|
$(elem).on('iron-overlay-closed', function () {
|
2015-06-01 07:49:23 -07:00
|
|
|
|
|
2015-10-24 08:33:22 -07:00
|
|
|
|
clearCurrentDisplayingInfo();
|
2015-05-26 10:48:05 -07:00
|
|
|
|
|
2015-10-24 08:33:22 -07:00
|
|
|
|
if (isCancelled) {
|
2015-10-02 10:55:26 -07:00
|
|
|
|
deferred.reject();
|
|
|
|
|
}
|
2015-10-24 08:33:22 -07:00
|
|
|
|
|
2015-10-02 10:55:26 -07:00
|
|
|
|
$(this).remove();
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-05-26 10:48:05 -07:00
|
|
|
|
|
2015-10-02 10:55:26 -07:00
|
|
|
|
function showInAppPurchaseInfo(subscriptionOptions, unlockableProductInfo, serverRegistrationInfo, dialogOptions, deferred) {
|
2015-10-01 23:14:04 -07:00
|
|
|
|
|
2015-10-02 10:55:26 -07:00
|
|
|
|
require(['components/paperdialoghelper'], function () {
|
2015-06-01 07:49:23 -07:00
|
|
|
|
|
2015-10-07 14:42:29 -07:00
|
|
|
|
if (window.TabBar) {
|
|
|
|
|
TabBar.hide();
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-02 10:55:26 -07:00
|
|
|
|
showInAppPurchaseElement(subscriptionOptions, unlockableProductInfo, dialogOptions, deferred);
|
2015-10-01 23:14:04 -07:00
|
|
|
|
|
2015-10-02 10:55:26 -07:00
|
|
|
|
currentDisplayingDeferred = deferred;
|
2015-10-01 23:14:04 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function promptForEmail(feature) {
|
|
|
|
|
|
|
|
|
|
require(['prompt'], function (prompt) {
|
|
|
|
|
|
|
|
|
|
prompt({
|
|
|
|
|
text: Globalize.translate('TextPleaseEnterYourEmailAddressForSubscription'),
|
|
|
|
|
title: Globalize.translate('HeaderEmailAddress'),
|
2015-10-02 10:55:26 -07:00
|
|
|
|
callback: function (email) {
|
|
|
|
|
|
2015-10-01 23:14:04 -07:00
|
|
|
|
if (email) {
|
2015-10-02 10:55:26 -07:00
|
|
|
|
IapManager.beginPurchase(feature, email);
|
2015-10-01 23:14:04 -07:00
|
|
|
|
}
|
2015-05-26 10:48:05 -07:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
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) {
|
|
|
|
|
|
2015-10-29 12:01:04 -07:00
|
|
|
|
if (product.owned) {
|
2015-06-01 07:49:23 -07:00
|
|
|
|
|
2015-10-29 12:01:04 -07:00
|
|
|
|
var deferred = currentDisplayingDeferred;
|
2015-10-01 23:14:04 -07:00
|
|
|
|
|
2015-10-29 12:01:04 -07:00
|
|
|
|
if (deferred && currentDisplayingProductInfos.filter(function (p) {
|
2015-10-01 23:14:04 -07:00
|
|
|
|
|
|
|
|
|
return product.id == p.id;
|
2015-06-01 07:49:23 -07:00
|
|
|
|
|
2015-10-01 23:14:04 -07:00
|
|
|
|
}).length) {
|
2015-10-02 10:55:26 -07:00
|
|
|
|
|
|
|
|
|
isCancelled = false;
|
|
|
|
|
|
2015-06-01 07:49:23 -07:00
|
|
|
|
cancelInAppPurchase();
|
|
|
|
|
deferred.resolve();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-29 19:08:35 -07:00
|
|
|
|
function validateSync(deferred) {
|
|
|
|
|
|
|
|
|
|
Dashboard.getPluginSecurityInfo().done(function (pluginSecurityInfo) {
|
|
|
|
|
|
2015-07-29 20:02:37 -07:00
|
|
|
|
if (pluginSecurityInfo.IsMBSupporter) {
|
2015-07-29 19:08:35 -07:00
|
|
|
|
deferred.resolve();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-02 10:55:26 -07:00
|
|
|
|
// Get supporter status
|
|
|
|
|
getRegistrationInfo('Sync').done(function (registrationInfo) {
|
2015-07-29 19:08:35 -07:00
|
|
|
|
|
2015-07-29 20:02:37 -07:00
|
|
|
|
if (registrationInfo.IsRegistered) {
|
2015-07-29 19:08:35 -07:00
|
|
|
|
deferred.resolve();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-02 10:55:26 -07:00
|
|
|
|
IapManager.getSubscriptionOptions().done(function (subscriptionOptions) {
|
2015-07-29 19:08:35 -07:00
|
|
|
|
|
2015-10-02 10:55:26 -07:00
|
|
|
|
var dialogOptions = {
|
|
|
|
|
title: Globalize.translate('HeaderUnlockSync')
|
|
|
|
|
};
|
2015-07-29 19:08:35 -07:00
|
|
|
|
|
2015-10-02 10:55:26 -07:00
|
|
|
|
showInAppPurchaseInfo(subscriptionOptions, null, registrationInfo, dialogOptions, deferred);
|
2015-07-29 19:08:35 -07:00
|
|
|
|
});
|
|
|
|
|
|
2015-10-02 10:55:26 -07:00
|
|
|
|
}).fail(function () {
|
|
|
|
|
deferred.reject();
|
|
|
|
|
});
|
2015-07-29 19:08:35 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-22 12:16:14 -07:00
|
|
|
|
window.RegistrationServices = {
|
|
|
|
|
|
|
|
|
|
renderPluginInfo: function (page, pkg, pluginSecurityInfo) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
validateFeature: function (name) {
|
|
|
|
|
var deferred = DeferredBuilder.Deferred();
|
|
|
|
|
|
|
|
|
|
if (name == 'playback') {
|
2015-10-01 23:14:04 -07:00
|
|
|
|
validateFeature(name, deferred);
|
2015-05-22 12:16:14 -07:00
|
|
|
|
} else if (name == 'livetv') {
|
2015-10-01 23:14:04 -07:00
|
|
|
|
validateFeature(name, deferred);
|
2015-07-29 19:08:35 -07:00
|
|
|
|
} else if (name == 'sync') {
|
|
|
|
|
validateSync(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-10-01 23:14:04 -07:00
|
|
|
|
if ($.browser.android) {
|
2015-06-19 21:48:45 -07:00
|
|
|
|
requirejs(['cordova/android/iap'], onIapManagerLoaded);
|
2015-05-31 14:07:44 -07:00
|
|
|
|
} else {
|
2015-06-19 21:48:45 -07:00
|
|
|
|
requirejs(['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
|
|
|
|
})();
|