Last active
October 19, 2017 15:46
-
-
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
This file contains 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 characters
# 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