Class: Vpago::PaymentProcessor

Inherits:
Object
  • Object
show all
Includes:
PaymentProcessable
Defined in:
app/services/vpago/payment_processor.rb

Instance Method Summary collapse

Methods included from PaymentProcessable

#available_actions, #enqueue_capture_payment_if_available!, #enqueue_void_or_cancel_payment_if_available!, #extract_completer_failure_reason_code, #failure, #log_process, #success?, #user_informer

Constructor Details

#initialize(payment:) ⇒ PaymentProcessor

Returns a new instance of PaymentProcessor.



12
13
14
15
# File 'app/services/vpago/payment_processor.rb', line 12

def initialize(payment:)
  @payment = payment
  @error = nil
end

Instance Method Details

#callObject



17
18
19
# File 'app/services/vpago/payment_processor.rb', line 17

def call
  log_process('call!') { call! }
end

#call!Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/services/vpago/payment_processor.rb', line 21

def call!
  process_payment! if available_actions.include?('process')
  process_order! if @payment.completed? || @payment.pending?
rescue Spree::Core::GatewayError => e
  if e.message == Spree.t(:unable_to_connect_to_gateway)
    user_informer.payment_is_retrying(processing: true)

    # Re-raise to trigger Sidekiq retry mechanism.
    raise
  end

  handle_payment_failure(:gateway_error, e.message)
rescue StateMachines::InvalidTransition => e
  handle_payment_failure(:invalid_state_machine_transition, e.message)
end