Created
October 31, 2015 20:00
-
-
Save spencerroan/e83bbe3dbeb8bf12e5ef to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| def lines(invoice) | |
| (invoice.lines.count / 100.0).ceil.times.map do |page| | |
| offset = page * 100 | |
| invoice.lines.all(count: 100, offset: offset).map do |line| | |
| Stripe::InvoiceItem.construct_from line | |
| end | |
| end.flatten | |
| end | |
| def del_iis(iis) | |
| pb = ProgressBar.new("die", iis.size) | |
| iis.each do |ii| | |
| ii.delete | |
| pb.inc | |
| end | |
| pb.finish | |
| end | |
| def delete_invoice_items_for_customer(cust_id) | |
| invoice = Stripe::Invoice.upcoming(customer: cust_id) | |
| lis = lines(invoice) | |
| iis = lis.select { |line| line.metadata.present? && line.metadata[:invoice_line] == 'cash_issued'} | |
| del_iis(iis) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment