Skip to content
This repository was archived by the owner on Aug 22, 2023. It is now read-only.

Commit 1fc45cb

Browse files
committed
normalizing subscriptions to mrr
1 parent dbc3bd7 commit 1fc45cb

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

History.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
0.0.3 - February 26, 2014
2+
-------------------------
3+
Normalizing subscriptions for MRR
14

25
0.0.1 - February 26, 2014
36
-------------------------

lib/subscriptions.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
var util = require('util');
32

43
/**
@@ -169,7 +168,7 @@ Subscriptions.prototype.print = function () {
169168

170169
Subscriptions.prototype.mrr = function (start, end) {
171170
var mrr = this.started(start, end).subscriptions.reduce(function (memo, subscription) {
172-
return memo + amount(subscription);
171+
return memo + amountMrr(subscription);
173172
}, 0.00);
174173

175174
return Math.round(mrr * 100) / 100.0; // to two decimal points
@@ -183,8 +182,9 @@ Subscriptions.prototype.mrr = function (start, end) {
183182
* @return {Number}
184183
*/
185184

186-
function amount (subscription) {
185+
function amountMrr (subscription) {
187186
var res = (subscription.plan.amount / 100.0);
187+
res = normalizeMonths(subscription, res);
188188
if (res > 0.0) {
189189
var discount = subscription.customer.discount;
190190
if (discount && discount.coupon) {
@@ -197,4 +197,22 @@ function amount (subscription) {
197197
res *= (1.00 - 0.029); // Stripe fees
198198
}
199199
return res;
200-
}
200+
}
201+
202+
//
203+
function normalizeMonths (subscription, res) {
204+
var interval = subscription.plan.interval;
205+
var count = subscription.plan.interval_count;
206+
if (interval === 'day')
207+
res *= 30 / count;
208+
else if (interval === 'week')
209+
res *= 4 / count;
210+
else if (interval === 'month')
211+
res *= 1 / count;
212+
else if (interval === 'year'){
213+
res = res / 12 / count;
214+
}
215+
else
216+
throw new Error('Unexpected interval ' + interval);
217+
return res;
218+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "stripe-cohort",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"main": "./lib",
55
"repository": "git://github.com/segmentio/stripe-cohort.git",
66
"license": "MIT",

0 commit comments

Comments
 (0)