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> | |
# 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