mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-04-07 10:34:46 -04:00
Added a script for getting some subscription data more easily.
This commit is contained in:
parent
1d8f91c42f
commit
097dbd11dd
1 changed files with 69 additions and 0 deletions
69
scripts/analytics/subscriptionStats.js
Normal file
69
scripts/analytics/subscriptionStats.js
Normal file
|
@ -0,0 +1,69 @@
|
|||
// To use: set the range you want below, make sure your environment has the stripe key, then run:
|
||||
// node scripts/analytics/subscriptions.js
|
||||
|
||||
require('coffee-script');
|
||||
require('coffee-script/register');
|
||||
config = require('../../server_config');
|
||||
if(config.stripe.secretKey.indexOf('sk_test_')==0) {
|
||||
throw new Error('You should not run this on the test data... Get your environment in gear.');
|
||||
}
|
||||
|
||||
stripe = require('stripe')(config.stripe.secretKey);
|
||||
|
||||
var range = {
|
||||
gt: ''+(new Date('2015-01-01').getTime()/1000),
|
||||
lt: ''+(new Date('2015-02-01').getTime()/1000)
|
||||
};
|
||||
|
||||
begin = function(starting_after) {
|
||||
var query = {date: range, limit: 100};
|
||||
if(starting_after) {
|
||||
query.starting_after = starting_after;
|
||||
}
|
||||
stripe.invoices.list(query, onInvoicesReceived);
|
||||
}
|
||||
|
||||
customersPaid = []
|
||||
|
||||
onInvoicesReceived = function(err, invoices) {
|
||||
for(var i in invoices.data) {
|
||||
var invoice = invoices.data[i];
|
||||
if(!invoice.paid) { continue; }
|
||||
customersPaid.push(invoice.customer);
|
||||
}
|
||||
if(invoices.has_more) {
|
||||
console.log('Loaded', customersPaid.length, 'invoices.')
|
||||
begin(invoices.data[i].id);
|
||||
}
|
||||
else {
|
||||
console.log('How many customers paid for a subscription:', customersPaid.length);
|
||||
loadNewCustomers();
|
||||
}
|
||||
}
|
||||
|
||||
loadNewCustomers = function(starting_after) {
|
||||
query = {created: range, limit: 100};
|
||||
if(starting_after) {
|
||||
query.starting_after = starting_after;
|
||||
}
|
||||
stripe.customers.list(query, onCustomersReceived);
|
||||
}
|
||||
|
||||
newCustomersPaid = [];
|
||||
|
||||
onCustomersReceived = function(err, customers) {
|
||||
for(var i in customers.data) {
|
||||
var customer = customers.data[i];
|
||||
if(customersPaid.indexOf(customer.id) == -1) { continue; }
|
||||
newCustomersPaid.push(customer.id);
|
||||
}
|
||||
if(customers.has_more) {
|
||||
console.log('Loaded', newCustomersPaid.length, 'new customers.');
|
||||
loadNewCustomers(customers.data[i].id);
|
||||
}
|
||||
else {
|
||||
console.log('How many new customers paid for a subscription:', newCustomersPaid.length);
|
||||
}
|
||||
}
|
||||
|
||||
begin();
|
Loading…
Add table
Reference in a new issue