Class: Spree::BankPayments::ExpireSessionsJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
app/jobs/spree/bank_payments/expire_sessions_job.rb

Instance Method Summary collapse

Instance Method Details

#performObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/jobs/spree/bank_payments/expire_sessions_job.rb', line 6

def perform
  Spree::BankPayments::Gateway.find_each do |payment_method|
    unless payment_method.reconciler_healthy?
      # Never cancel while blind: the customer may have paid and we simply
      # cannot see it. Alert and leave everything untouched.
      Spree::Events.publish(
        'bank_transfer.reconciler_unhealthy',
        {
          payment_method_id: payment_method.id,
          reconciler: payment_method.preferred_reconciler,
          last_successful_run_at: payment_method.reconciler_state.last_successful_run_at&.iso8601,
          last_error: payment_method.reconciler_state.last_error
        }
      )
      next
    end

    expire_for(payment_method)
  rescue StandardError => e
    # One payment method's failure (a bad state transition, a reconciler
    # gem gone missing, anything) must not wedge expiry for every other
    # payment method processed after it in this loop.
    Spree::Events.publish(
      'bank_transfer.expiry_failed',
      {
        payment_method_id: payment_method.id,
        error: e.message
      }
    )
    Rails.error.report(e, source: 'spree_bank_payments.expire_sessions')
    next
  end
end