stripe-cohort
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -0,1 +1,4 @@ | ||
0.0.3 - February 26, 2014 | ||
------------------------- | ||
Normalizing subscriptions for MRR | ||
@@ -2,0 +5,0 @@ 0.0.1 - February 26, 2014 |
@@ -1,2 +0,1 @@ | ||
var util = require('util'); | ||
@@ -172,3 +171,3 @@ | ||
var mrr = this.started(start, end).subscriptions.reduce(function (memo, subscription) { | ||
return memo + amount(subscription); | ||
return memo + amountMrr(subscription); | ||
}, 0.00); | ||
@@ -187,4 +186,5 @@ | ||
function amount (subscription) { | ||
function amountMrr (subscription) { | ||
var res = (subscription.plan.amount / 100.0); | ||
res = normalizeMonths(subscription, res); | ||
if (res > 0.0) { | ||
@@ -202,2 +202,20 @@ var discount = subscription.customer.discount; | ||
return res; | ||
} | ||
} | ||
// | ||
function normalizeMonths (subscription, res) { | ||
var interval = subscription.plan.interval; | ||
var count = subscription.plan.interval_count; | ||
if (interval === 'day') | ||
res *= 30 / count; | ||
else if (interval === 'week') | ||
res *= 4 / count; | ||
else if (interval === 'month') | ||
res *= 1 / count; | ||
else if (interval === 'year'){ | ||
res = res / 12 / count; | ||
} | ||
else | ||
throw new Error('Unexpected interval ' + interval); | ||
return res; | ||
} |
{ | ||
"name": "stripe-cohort", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"main": "./lib", | ||
@@ -5,0 +5,0 @@ "repository": "git://github.com/segmentio/stripe-cohort.git", |
18098
467