Created
April 3, 2019 07:22
-
-
Save catalanska/b0785970d75b3340f721da7945144c65 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ok!