Add convenience function to determine if subscription is 'free' or not

This commit is contained in:
Johannes Zellner
2018-05-29 13:16:36 +02:00
parent 915e04eb08
commit 541fabcb2e
3 changed files with 9 additions and 6 deletions
+5
View File
@@ -5,6 +5,7 @@ exports = module.exports = {
unpurchase: unpurchase,
getSubscription: getSubscription,
isFreePlan: isFreePlan,
sendAliveStatus: sendAliveStatus,
@@ -90,6 +91,10 @@ function getSubscription(callback) {
});
}
function isFreePlan(subscription) {
return !subscription || subscription.plan.id === 'free';
}
function purchase(appId, appstoreId, callback) {
assert.strictEqual(typeof appId, 'string');
assert.strictEqual(typeof appstoreId, 'string');
+2 -4
View File
@@ -28,11 +28,9 @@ function maybeSend(callback) {
var pendingAppUpdates = updateInfo.apps || {};
pendingAppUpdates = Object.keys(pendingAppUpdates).map(function (key) { return pendingAppUpdates[key]; });
appstore.getSubscription(function (error, result) {
appstore.getSubscription(function (error, subscription) {
if (error) debug('Error getting subscription:', error);
var hasSubscription = result && result.plan.id !== 'free';
eventlog.getByCreationTime(new Date(new Date() - 7*86400000), function (error, events) {
if (error) return callback(error);
@@ -46,7 +44,7 @@ function maybeSend(callback) {
if (error) return callback(error);
var info = {
hasSubscription: hasSubscription,
hasSubscription: appstore.isFreePlan(subscription),
pendingAppUpdates: pendingAppUpdates,
pendingBoxUpdate: updateInfo.box || null,
+2 -2
View File
@@ -105,7 +105,7 @@ function checkAppUpdates(callback) {
}
// always send notifications if user is on the free plan
if (result.plan.id === 'free') {
if (appstore.isFreePlan(result)) {
debug('Notifying user of app update for %s from %s to %s', app.id, app.manifest.version, updateInfo.manifest.version);
mailer.appUpdateAvailable(app, false /* subscription */, updateInfo);
return iteratorDone();
@@ -162,7 +162,7 @@ function checkBoxUpdates(callback) {
}
// always send notifications if user is on the free plan
if (result.plan.id === 'free') {
if (appstore.isFreePlan(result)) {
mailer.boxUpdateAvailable(false /* hasSubscription */, updateInfo.version, updateInfo.changelog);
return done();
}