Skip to content

Instantly share code, notes, and snippets.

@iloveitaly
Last active October 19, 2017 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iloveitaly/7c3ba728f14ac00337125fa617afdf27 to your computer and use it in GitHub Desktop.
Save iloveitaly/7c3ba728f14ac00337125fa617afdf27 to your computer and use it in GitHub Desktop.
Get a list of Stripe customers whose email was changed on a specific day
# Author <mike@suitesync.io>
require 'stripe'
Stripe.api_key = 'sk_test_123'
Stripe.api_version = '2017-08-15'
target_date = 1500422400
events = []
Stripe::Event.list({
limit: 100,
type:'customer.updated',
created: {
gte: Time.at(target_date).to_datetime.utc.beginning_of_day.to_i,
lte: Time.at(target_date).to_datetime.utc.end_of_day.to_i
}
}).auto_paging_each { |e| events << e }
changed_customers = events.select { |e|
!e.data.previous_attributes["email"].nil? &&
e.data.previous_attributes["email"] != e.data.object.email
}
puts changed_customers.map { |e| "#{e.data.object.id}\t#{e.data.previous_attributes["email"]}\t#{e.data.object.email}" }
puts changed_customers.map { |e| e.data.object.id }.join("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment