Add test rake job for processing dummy payment

This commit is contained in:
Alex Sherman 2021-05-31 14:10:51 +05:00
parent fb810e5ccb
commit 76a0b80f85
4 changed files with 27 additions and 10 deletions

View file

@ -21,7 +21,7 @@ class SendEInvoiceJob < ApplicationJob
end
def process(invoice:, payable:)
invoice.to_e_invoice(payable: payable).deliver
invoice.to_e_invoice(payable: payable).deliver unless Rails.env.development?
invoice.update(e_invoice_sent_at: Time.zone.now)
log_success(invoice)
end

View file

@ -15,7 +15,7 @@ module Invoice::Cancellable
end
def cancelled?
cancelled_at
cancelled_at.present?
end
def not_cancelled?

View file

@ -105,7 +105,7 @@ class Registrar < ApplicationRecord
.deliver_later(wait: 1.minute)
end
SendEInvoiceJob.perform_later(invoice.id, payable)
SendEInvoiceJob.perform_now(invoice.id, payable)
invoice
end

View file

@ -22,6 +22,30 @@ namespace :invoices do
end
end
process_transactions(incoming_transactions)
puts "Transactions processed: #{incoming_transactions.size}"
end
task test_payments: :environment do
registrar = Invoice.last.buyer
transactions = [OpenStruct.new(amount: 0.1,
currency: 'EUR',
date: Time.zone.today,
payment_reference_number: registrar.reference_no,
payment_description: "description #{registrar.reference_no}")]
process_transactions(transactions)
puts 'Last registrar invoice is'
pp registrar.invoices.last
puts "Last invoice paid at #{registrar.invoices.last.receipt_date}"
end
def log(msg)
@log ||= Logger.new(STDOUT)
@log.info(msg)
end
def process_transactions(incoming_transactions)
if incoming_transactions.any?
log 'Got incoming transactions'
log incoming_transactions
@ -51,12 +75,5 @@ namespace :invoices do
else
log 'Got no incoming transactions parsed, aborting'
end
puts "Transactions processed: #{incoming_transactions.size}"
end
def log(msg)
@log ||= Logger.new(STDOUT)
@log.info(msg)
end
end