7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'app/workers/invoice_capture_funds_worker.rb', line 7
def perform(invoice_id)
invoice = Invoice.find(invoice_id)
if invoice.paid?
logger.info "Invoice id: #{invoice_id} is already paid, skipping capture"
return
end
unless invoice.unpaid?
logger.warn "Invoice id: #{invoice_id} is in state '#{invoice.state}', cannot capture funds (must be 'unpaid')"
return
end
invoice.capture_funds?
logger.info "Invoice capture finished for invoice id: #{invoice_id}, state: #{invoice.state}"
rescue StateMachines::InvalidTransition => e
logger.warn "Invoice id: #{invoice_id} state transition failed: #{e.message}"
ErrorReporting.warning(e, source: :background, invoice_id: invoice_id, invoice_state: invoice.state)
end
|