Skip to content

Instantly share code, notes, and snippets.

@iloveitaly
Last active October 19, 2018 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iloveitaly/3e4447e6d61cce7b79942296d9400ab0 to your computer and use it in GitHub Desktop.
Save iloveitaly/3e4447e6d61cce7b79942296d9400ab0 to your computer and use it in GitHub Desktop.
Close invoices for a specific Stripe customer
# Description: close open invoices on a Stripe customer
# Link: https://gist.github.com/iloveitaly/3e4447e6d61cce7b79942296d9400ab0
require 'stripe'
Stripe.api_key = ENV['STRIPE_KEY']
customer = Stripe::Customer.retrieve('cus_123')
customer.invoices.data.each do |invoice|
if !invoice.closed
# NOTE you can also mark as invoice as forgiven: `invoice.forgiven = true`
# this has the same effect in NetSuite of creating a credit memo
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