Skip to content

Instantly share code, notes, and snippets.

@dennmart
Created September 8, 2014 23:43
Show Gist options
  • Save dennmart/2b1cbb7d835dddca0340 to your computer and use it in GitHub Desktop.
Save dennmart/2b1cbb7d835dddca0340 to your computer and use it in GitHub Desktop.
Ruby script to find duplicate Stripe customers
require 'stripe'
Stripe.api_key = "YOUR_STRIPE_API_KEY"
duplicate_customers = []
last_customer_id = nil # Cursor for paginating through results
# Stripe can retrieve a maximum of 100 customers in one go, so we need to loop.
loop do
customers = Stripe::Customer.all(limit: 100, starting_after: last_customer_id)
emails = customers.data.each.map { |d| d["email"] }
emails.detect { |email| duplicate_customers << email if emails.count(email) > 1 }
break if customers.count != 100
last_customer_id = customers.data[99]["id"]
end
if duplicate_customers.empty?
puts "No duplicate customers found!"
else
puts "Duplicate Customers:\n"
puts "--------------------\n"
duplicate_customers.each { |dup| puts dup }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment