Last active
October 19, 2018 19:03
-
-
Save iloveitaly/5ecbffc012e8ea84e373f9d23dcfcb50 to your computer and use it in GitHub Desktop.
Identify closed or forgiven Stripe invoices that won't be collected on. Useful if you are not leveraging the credit memo creation feature of http://SuiteSync.io/
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
# Mike Bianco <mike@suitesync.io> | |
# Link: https://gist.github.com/iloveitaly/5ecbffc012e8ea84e373f9d23dcfcb50 | |
require 'stripe' | |
Stripe.api_key = 'sk_live_123' | |
def find_closed_invoices | |
limit = 2000 | |
invoices = [] | |
created_after = Date.new(2016,05,15) | |
Stripe::Invoice.list(limit: 100).auto_paging_each do |invoice| | |
limit -= 1 | |
if Time.at(invoice.date) < created_after | |
break | |
end | |
if invoice.closed && !invoice.paid | |
invoices << invoice | |
end | |
if limit < 0 | |
break | |
end | |
end | |
invoices | |
end | |
closed_invoices = find_closed_invoices |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment