Skip to content
Preston Pham edited this page Jun 19, 2015 · 1 revision

For Stripe management, if we need to apply an update to all restaurants we have to make n api calls to stripe. Their reasoning is https://en.wikipedia.org/wiki/Robustness_principle.

Here is a one-time script to change all restaurants to manual transferring:

var utils = require('utils');
var db = require('db');

var q = utils.async.queue(function (id, callback) {
  utils.stripe.accounts.update(id, {
    transfer_schedule: {
      interval: 'manual'
    }
  }, callback);
}, 5);


// assign a callback
q.drain = function() {
    console.log('all items have been processed');
}

db.restaurants.find({ stripe_id: { $notNull: true }}, function(err, restaurants) {
  if (err) {
    return console.error(err);
  }

  var ids = utils.pluck(restaurants, 'stripe_id');
  console.log('Queueing ' + restaurants.length + ' restaurants to manual transfers');
  q.push(ids, function(err, acct) {
    if (err) console.log('error processing', err);
    console.log('finished processing ', acct.business_name, acct.id);
  });
});

I didn't have time to set up a proper post-delta script, but I think template will be helpful later down the line when making batched updates.

Clone this wiki locally