Created
July 6, 2017 15:24
-
-
Save iloveitaly/0111973978b8146a07b88374fb03ffda to your computer and use it in GitHub Desktop.
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
# Description: Identify all unpaid & open invoices that won't be attempted again and close them | |
require 'stripe' | |
Stripe.api_key = ENV['STRIPE_KEY'] | |
# NOTE adjust the start & end dates to avoid processing *all* invoices in Stripe | |
start_timestamp = Time.now.to_i | |
end_timestamp = Time.now.to_i - (60 * 60 * 24 * 30) | |
# NOTE the API does not support filtering invoices by status. In order to find | |
Stripe::Invoice.list(date: { gte: start_timestamp, lte: start_timestamp }, limit: 100).auto_paging_each do |invoice| | |
if !invoice.closed && !invoice.paid && invoice.next_payment_attempt.nil? | |
puts "closing\tinvoice.id" | |
invoice.closed = true | |
invoice.save | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment