Skip to content

Instantly share code, notes, and snippets.

@catalanska
Created April 3, 2019 07:22
Show Gist options
  • Save catalanska/b0785970d75b3340f721da7945144c65 to your computer and use it in GitHub Desktop.
Save catalanska/b0785970d75b3340f721da7945144c65 to your computer and use it in GitHub Desktop.
due_date = Date.parse('2019-03-31')
instalments = Installment.delinquent.
where(due_date: due_date).
joins(:loan => :merchant).
where('DATE(loans.delinquent_at) = ?',due_date).
merge(Merchant.active)
instalments.find_each do |installment|
begin
if installment.payment_method&.debit?
ChargeInstallments::DebitJob.perform_later(installment.id)
elsif installment.payment_method&.paypal?
ChargeInstallments::PaypalJob.perform_later(installment.id)
elsif installment.payment_method&.bank_account?
ChargeInstallments::BankAccountJob.perform_later(installment.id)
else
Rollbar.warning("Installment #{installment.id} has no valid payment method to be charged")
ChargeInstallments::NoPaymentMethodJob.perform_later(installment.id)
end
rescue StandardError => error
Rollbar.error error, installment_id: installment.id
end
end
@aurelian
Copy link

aurelian commented Apr 3, 2019

ok!

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