Module: SolidusNexio::PaymentDecorator

Defined in:
app/decorators/models/solidus_nexio/payment_decorator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nexio_apm_transaction_idObject

Returns the value of attribute nexio_apm_transaction_id.



5
6
7
# File 'app/decorators/models/solidus_nexio/payment_decorator.rb', line 5

def nexio_apm_transaction_id
  @nexio_apm_transaction_id
end

Instance Method Details

#authorize!Object



15
16
17
# File 'app/decorators/models/solidus_nexio/payment_decorator.rb', line 15

def authorize!
  authorize_apm_safely or clean_nexio_after { super }
end

#nexio_apm?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'app/decorators/models/solidus_nexio/payment_decorator.rb', line 7

def nexio_apm?
  payment_method.is_a?(::SolidusNexio::AlternativePaymentMethod)
end

#nexio_card?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'app/decorators/models/solidus_nexio/payment_decorator.rb', line 11

def nexio_card?
  payment_method.is_a?(::SolidusNexio::PaymentMethod)
end

#purchase!Object



19
20
21
# File 'app/decorators/models/solidus_nexio/payment_decorator.rb', line 19

def purchase!
  fetch_nexio_amp_transaction('Purchase') or clean_nexio_after { super }
end

#update_payment_state_from_nexio(action = nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/decorators/models/solidus_nexio/payment_decorator.rb', line 23

def update_payment_state_from_nexio(action = nil)
  return unless response_code.present?

  transaction = payment_method.gateway.get_transaction(response_code)
  unless transaction&.data.present? && transaction.status.present?
    error_message = "#{action}: The transaction is not found."
    record_response(build_response(false, error_message))
    return
  end

  message = "#{action}: The transaction #{transaction.data['id']} is updated."
  record_response(build_response(true, message, transaction.data))
  self.state = SolidusNexio::Mappings.payment_state(transaction.status)
  self.amount = failed? || void? ? 0 : transaction.amount
  save
end