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
|
|
|
|
var updatedProducts = [];
|
|
|
|
|
|
2015-05-27 22:51:48 -07:00
|
|
|
|
var unlockAlias = "premium features";
|
|
|
|
|
|
2015-05-26 08:31:50 -07:00
|
|
|
|
function updateProductInfo(p) {
|
|
|
|
|
|
|
|
|
|
updatedProducts = updatedProducts.filter(function (r) {
|
|
|
|
|
return r.alias != p.alias;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
updatedProducts.push(p);
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-27 22:51:48 -07:00
|
|
|
|
function getProduct(alias) {
|
|
|
|
|
var products = updatedProducts.filter(function (r) {
|
|
|
|
|
return r.alias == alias;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return products.length ? products[0] : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function hasPurchased(alias) {
|
|
|
|
|
var product = getProduct(alias);
|
|
|
|
|
|
|
|
|
|
return product != null && product.owned;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isPurchaseAvailable(alias) {
|
|
|
|
|
var product = getProduct(alias);
|
|
|
|
|
|
|
|
|
|
return product != null && product.canPurchase;
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function validatePlayback(deferred) {
|
|
|
|
|
|
2015-05-22 13:15:29 -07:00
|
|
|
|
// Don't require validation on android
|
2015-05-26 08:31:50 -07:00
|
|
|
|
if (isAndroid()) {
|
2015-05-22 12:16:14 -07:00
|
|
|
|
deferred.resolve();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-05-16 12:09:02 -07:00
|
|
|
|
|
2015-05-26 08:31:50 -07:00
|
|
|
|
validateFeature({
|
|
|
|
|
|
|
|
|
|
id: 'appunlock',
|
2015-05-27 22:51:48 -07:00
|
|
|
|
alias: unlockAlias
|
2015-05-26 08:31:50 -07:00
|
|
|
|
|
|
|
|
|
}, deferred);
|
2015-05-22 12:16:14 -07:00
|
|
|
|
}
|
2015-05-16 12:09:02 -07:00
|
|
|
|
|
2015-05-22 12:16:14 -07:00
|
|
|
|
function validateLiveTV(deferred) {
|
2015-05-17 18:27:48 -07:00
|
|
|
|
|
2015-05-26 08:31:50 -07:00
|
|
|
|
// Don't require validation if not android
|
|
|
|
|
if (!isAndroid()) {
|
|
|
|
|
deferred.resolve();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
validateFeature({
|
|
|
|
|
|
|
|
|
|
id: 'premiumunlock',
|
2015-05-27 22:51:48 -07:00
|
|
|
|
alias: unlockAlias
|
2015-05-26 08:31:50 -07:00
|
|
|
|
|
|
|
|
|
}, deferred);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function validateSmb(deferred) {
|
2015-05-22 13:15:29 -07:00
|
|
|
|
|
|
|
|
|
// Don't require validation if not android
|
2015-05-26 08:31:50 -07:00
|
|
|
|
if (!isAndroid()) {
|
2015-05-22 13:15:29 -07:00
|
|
|
|
deferred.resolve();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-26 08:31:50 -07:00
|
|
|
|
validateFeature({
|
|
|
|
|
|
|
|
|
|
id: 'premiumunlock',
|
2015-05-27 22:51:48 -07:00
|
|
|
|
alias: unlockAlias
|
2015-05-26 08:31:50 -07:00
|
|
|
|
|
|
|
|
|
}, deferred);
|
|
|
|
|
}
|
|
|
|
|
|
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-05-26 08:31:50 -07:00
|
|
|
|
function validateFeature(info, deferred) {
|
|
|
|
|
|
2015-05-27 22:51:48 -07:00
|
|
|
|
if (hasPurchased(info.alias)) {
|
2015-05-26 08:31:50 -07:00
|
|
|
|
deferred.resolve();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-26 10:48:05 -07:00
|
|
|
|
var productInfo = {
|
|
|
|
|
enableSupporterUnlock: isAndroid(),
|
2015-05-27 22:51:48 -07:00
|
|
|
|
enableAppUnlock: isPurchaseAvailable(info.alias)
|
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;">';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
html += '<form class="inAppPurchaseForm" style="margin: 0 auto;padding: 30px 1em 0;">';
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
html += '<p style="margin:2em 0;">';
|
|
|
|
|
html += Globalize.translate('MessageToValidateSupporter');
|
|
|
|
|
html += '</p>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (info.enableAppUnlock) {
|
|
|
|
|
html += '<button class="btn btnActionAccent btnAppUnlock" data-role="none" type="button"><span>' + Globalize.translate('ButtonUnlockWithPurchase') + '</span><i class="fa fa-check"></i></button>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-05-26 10:48:05 -07:00
|
|
|
|
html += '</form>';
|
|
|
|
|
|
|
|
|
|
html += '</div>';
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
|
|
$(document.body).append(html);
|
|
|
|
|
|
|
|
|
|
return $('.inAppPurchaseOverlay');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function cancelInAppPurchase() {
|
|
|
|
|
|
|
|
|
|
$('.inAppPurchaseOverlay').remove();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showInAppPurchaseInfo(info, serverRegistrationInfo, deferred) {
|
|
|
|
|
|
|
|
|
|
var elem = getInAppPurchaseElement(info);
|
|
|
|
|
|
|
|
|
|
$('.inAppPurchaseForm', elem).on('submit', function () {
|
|
|
|
|
|
|
|
|
|
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({
|
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();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.btnAppUnlock', elem).on('click', function () {
|
|
|
|
|
|
|
|
|
|
alert('coming soon');
|
|
|
|
|
});
|
2015-05-17 18:27:48 -07:00
|
|
|
|
}
|
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-05-26 08:31:50 -07:00
|
|
|
|
function validateProduct(product, callback) {
|
|
|
|
|
|
|
|
|
|
// product attributes:
|
|
|
|
|
// https://github.com/j3k0/cordova-plugin-purchase/blob/master/doc/api.md#validation-error-codes
|
|
|
|
|
|
|
|
|
|
callback(true, {
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//callback(true, { ... transaction details ... }); // success!
|
|
|
|
|
|
|
|
|
|
//// OR
|
|
|
|
|
//callback(false, {
|
|
|
|
|
// error: {
|
|
|
|
|
// code: store.PURCHASE_EXPIRED,
|
|
|
|
|
// message: "XYZ"
|
|
|
|
|
// }
|
|
|
|
|
//});
|
|
|
|
|
|
|
|
|
|
//// OR
|
|
|
|
|
//callback(false, "Impossible to proceed with validation");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function initializeStore() {
|
|
|
|
|
|
2015-05-27 22:51:48 -07:00
|
|
|
|
if (isAndroid()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-05-26 08:31:50 -07:00
|
|
|
|
// Let's set a pretty high verbosity level, so that we see a lot of stuff
|
|
|
|
|
// in the console (reassuring us that something is happening).
|
|
|
|
|
store.verbosity = store.INFO;
|
|
|
|
|
|
|
|
|
|
store.validator = validateProduct;
|
|
|
|
|
|
2015-05-27 22:51:48 -07:00
|
|
|
|
// iOS
|
|
|
|
|
store.register({
|
|
|
|
|
id: "appunlock",
|
|
|
|
|
alias: unlockAlias,
|
|
|
|
|
type: store.NON_CONSUMABLE
|
|
|
|
|
});
|
2015-05-26 08:31:50 -07:00
|
|
|
|
|
|
|
|
|
// When purchase of the full version is approved,
|
|
|
|
|
// show some logs and finish the transaction.
|
2015-05-27 22:51:48 -07:00
|
|
|
|
store.when(unlockAlias).approved(function (order) {
|
2015-05-26 08:31:50 -07:00
|
|
|
|
log('You just unlocked the FULL VERSION!');
|
|
|
|
|
order.finish();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// The play button can only be accessed when the user
|
|
|
|
|
// owns the full version.
|
2015-05-27 22:51:48 -07:00
|
|
|
|
store.when(unlockAlias).updated(function (product) {
|
2015-05-26 08:31:50 -07:00
|
|
|
|
|
|
|
|
|
updateProductInfo(product);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// When every goes as expected, it's time to celebrate!
|
|
|
|
|
// The "ready" event should be welcomed with music and fireworks,
|
|
|
|
|
// go ask your boss about it! (just in case)
|
|
|
|
|
store.ready(function () {
|
|
|
|
|
|
|
|
|
|
console.log("Store ready");
|
|
|
|
|
});
|
2015-05-27 22:51:48 -07:00
|
|
|
|
|
|
|
|
|
// After we've done our setup, we tell the store to do
|
|
|
|
|
// it's first refresh. Nothing will happen if we do not call store.refresh()
|
|
|
|
|
store.refresh();
|
2015-05-26 08:31:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We must wait for the "deviceready" event to fire
|
|
|
|
|
// before we can use the store object.
|
|
|
|
|
initializeStore();
|
|
|
|
|
|
2015-05-22 12:16:14 -07:00
|
|
|
|
})();
|