Skip to content

Instantly share code, notes, and snippets.

@Arkham
Created August 11, 2014 17:09
Show Gist options
  • Save Arkham/8f82282cf45dbe2ade2a to your computer and use it in GitHub Desktop.
Save Arkham/8f82282cf45dbe2ade2a to your computer and use it in GitHub Desktop.
Fix delayed job invoices
# Select all invoices with last_error
blob = Invoice.where("last_error ILIKE ?", "Invalid field%").includes(advisor: :bank_account).map do |invoice|
[ invoice.id, invoice.bank_account.account_number_crypted, invoice.bank_account.aba_crypted ]
end.to_json
# On blueberry
require_relative 'app'
require 'json'
key = Crypto.private_key(DA_KEY)
data = JSON.parse(PISTACHIO_BLOB)
data.map do |id, account_number_crypted, aba_crypted|
[ id, Crypto.decrypt(key, account_number_crypted), Crypto.decrypt(key, aba_crypted) ]
end.to_json
# back on pistachio console
info = JSON.parse(BLUEBERRY_BLOB)
info.each do |id, account_number, aba|
invoice = Invoice.find(id)
invoice.update(payment_initiated_at: nil, last_error: nil)
bank_account = invoice.bank_account
updated_bank_info = OpenStruct.new(bank_account.ach_info.to_h.merge(account_number: account_number, aba: aba))
Payment.new(invoice, invoice.amount, updated_bank_info).delay.perform
end
@bhaity
Copy link

bhaity commented Aug 11, 2014

Nice job Ju !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment