Created
August 11, 2014 17:09
-
-
Save Arkham/8f82282cf45dbe2ade2a to your computer and use it in GitHub Desktop.
Fix delayed job invoices
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
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice job Ju !