Created
April 4, 2018 02:25
-
-
Save chrisshiplet/669c700b54ed7de0899ada8f86be1cf8 to your computer and use it in GitHub Desktop.
Revisions
-
chrisshiplet created this gist
Apr 4, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ #!/usr/bin/env node // Example usage: TOKEN=sk_test_abcdef node index.js "[email protected]" if (!process.env.TOKEN) { throw new Error('Missing TOKEN environment variable'); } var stripe = require("stripe")(process.env.TOKEN); if (!process.argv[2]) { throw new Error('Missing email argument'); } var ids = []; (function getPage(startingAfter) { var opt = { email: process.argv[2], limit: 100 }; if (startingAfter) { opt.starting_after = startingAfter; } stripe.customers.list(opt, (err, customers) => { if (err) { console.log(err); } else { ids.push(...customers.data.map(cus => cus.id)); if (customers.has_more) { getPage(customers.data[customers.data.length - 1].id); } else { console.log(`${ids.length} customers found`); if (ids.length) { console.log('deleting...'); (function deleteCustomer() { var id = ids.pop(); console.log(id); stripe.customers.del(id, (err, confirm) => { if (err) { console.log(err); } else if (ids.length > 0) { deleteCustomer(); } else { console.log('done'); } }); })(); } } } }); })();