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 = [];
|
|
|
|
|
|
|
|
|
|
function updateProductInfo(p) {
|
|
|
|
|
|
|
|
|
|
updatedProducts = updatedProducts.filter(function (r) {
|
|
|
|
|
return r.alias != p.alias;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
updatedProducts.push(p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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',
|
|
|
|
|
alias: "premium features"
|
|
|
|
|
|
|
|
|
|
}, 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',
|
|
|
|
|
alias: "premium features"
|
|
|
|
|
|
|
|
|
|
}, 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',
|
|
|
|
|
alias: "premium features"
|
|
|
|
|
|
|
|
|
|
}, deferred);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function validateFeature(info, deferred) {
|
|
|
|
|
|
|
|
|
|
var products = updatedProducts.filter(function (r) {
|
|
|
|
|
return r.alias == info.alias;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var product = products.length ? products[0] : null;
|
|
|
|
|
|
|
|
|
|
if (product && product.owned) {
|
|
|
|
|
deferred.resolve();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get supporter status
|
|
|
|
|
ConnectionManager.getRegistrationInfo('appunlock', ApiClient).done(function (registrationInfo) {
|
|
|
|
|
|
|
|
|
|
if (registrationInfo.IsRegistered) {
|
|
|
|
|
deferred.resolve();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
showInAppPurchaseInfo(info, product, registrationInfo, deferred);
|
|
|
|
|
|
|
|
|
|
}).fail(function () {
|
|
|
|
|
deferred.reject();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showInAppPurchaseInfo(info, product, serverRegistrationInfo, deferred) {
|
|
|
|
|
|
|
|
|
|
var requiresLocalValidation = serverRegistrationInfo.IsLocalValidationRequired;
|
|
|
|
|
var canPurchase = product != null && product.canPurchase;
|
|
|
|
|
|
|
|
|
|
// Can only purchase if product != null
|
2015-05-22 12:16:14 -07:00
|
|
|
|
deferred.resolve();
|
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() {
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
|
|
if (isAndroid) {
|
|
|
|
|
store.register({
|
|
|
|
|
id: "premiumunlock",
|
|
|
|
|
alias: "premium features",
|
|
|
|
|
type: store.NON_CONSUMABLE
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
// iOS
|
|
|
|
|
store.register({
|
|
|
|
|
id: "appunlock",
|
|
|
|
|
alias: "premium features",
|
|
|
|
|
type: store.NON_CONSUMABLE
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// When purchase of the full version is approved,
|
|
|
|
|
// show some logs and finish the transaction.
|
|
|
|
|
store.when("premium feautres").approved(function (order) {
|
|
|
|
|
log('You just unlocked the FULL VERSION!');
|
|
|
|
|
order.finish();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// The play button can only be accessed when the user
|
|
|
|
|
// owns the full version.
|
|
|
|
|
store.when("premium feautres").updated(function (product) {
|
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
})();
|