Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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/
# Mike Bianco <mike@suitesync.io>
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