Class: Payment::BankUpdater

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree/payment/bank_updater.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payment, params = {}) ⇒ BankUpdater

Returns a new instance of BankUpdater.



5
6
7
8
9
# File 'app/models/spree/payment/bank_updater.rb', line 5

def initialize(payment, params = {})
  @payment = payment
  @params = params
  @errors = []
end

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



3
4
5
# File 'app/models/spree/payment/bank_updater.rb', line 3

def errors
  @errors
end

#paramsObject

Returns the value of attribute params.



3
4
5
# File 'app/models/spree/payment/bank_updater.rb', line 3

def params
  @params
end

#paymentObject

Returns the value of attribute payment.



3
4
5
# File 'app/models/spree/payment/bank_updater.rb', line 3

def payment
  @payment
end

Instance Method Details

#updateObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/spree/payment/bank_updater.rb', line 11

def update
  if @payment.
    @errors << "Payment Details can be submitted only once."
    return false
  end

  @payment.validate_bank_details = true

  ActiveRecord::Base.transaction do
    unless @payment.update(permit_params)
      raise StandardError, @payment.errors.full_messages.to_sentence
    end

    unless update_order_state
      raise StandardError, "Failed to update order state."
    end
  end    

  true
rescue StandardError => e
  @errors << e.message
  false
end