1
-
2
1
var util = require ( 'util' ) ;
3
2
4
3
/**
@@ -169,7 +168,7 @@ Subscriptions.prototype.print = function () {
169
168
170
169
Subscriptions . prototype . mrr = function ( start , end ) {
171
170
var mrr = this . started ( start , end ) . subscriptions . reduce ( function ( memo , subscription ) {
172
- return memo + amount ( subscription ) ;
171
+ return memo + amountMrr ( subscription ) ;
173
172
} , 0.00 ) ;
174
173
175
174
return Math . round ( mrr * 100 ) / 100.0 ; // to two decimal points
@@ -183,8 +182,9 @@ Subscriptions.prototype.mrr = function (start, end) {
183
182
* @return {Number }
184
183
*/
185
184
186
- function amount ( subscription ) {
185
+ function amountMrr ( subscription ) {
187
186
var res = ( subscription . plan . amount / 100.0 ) ;
187
+ res = normalizeMonths ( subscription , res ) ;
188
188
if ( res > 0.0 ) {
189
189
var discount = subscription . customer . discount ;
190
190
if ( discount && discount . coupon ) {
@@ -197,4 +197,22 @@ function amount (subscription) {
197
197
res *= ( 1.00 - 0.029 ) ; // Stripe fees
198
198
}
199
199
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
+ }
0 commit comments