Module: RailsTrade::PaymentMethod

Extended by:
ActiveSupport::Concern
Included in:
PaymentMethod
Defined in:
app/models/rails_trade/payment_method.rb

Defined Under Namespace

Modules: StripeMethod

Instance Method Summary collapse

Instance Method Details

#account_typesObject



22
23
24
# File 'app/models/rails_trade/payment_method.rb', line 22

def 
  PaymentReference.pluck(:account_type).uniq
end

#detect_repetitionObject



35
36
37
38
39
40
41
# File 'app/models/rails_trade/payment_method.rb', line 35

def detect_repetition
  if self.persisted?
    self.class.unscoped.where.not(id: self.id).exists?(account_name: self., account_num: self.)
  else
    self.class.unscoped.exists?(account_name: self., account_num: self.)
  end
end

#detective_saveObject



26
27
28
29
30
31
32
33
# File 'app/models/rails_trade/payment_method.rb', line 26

def detective_save
  if detect_repetition
    self.verified = false
  else
    self.verified = true
  end
  self.save
end

#kindObject



60
61
62
# File 'app/models/rails_trade/payment_method.rb', line 60

def kind
  type.to_s.sub('Method', '').downcase
end

#merge_from(other_id) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/models/rails_trade/payment_method.rb', line 47

def merge_from(other_id)
  other = self.class.unscoped.find other_id

  self.class.transaction do
    other.payment_references.each do |payment_reference|
      payment_reference.payment_method_id = self.id  # for callback, do not use update
      payment_reference.save
    end
    other.payment_references.reload
    other.destroy
  end
end

#repeat_resultsObject



43
44
45
# File 'app/models/rails_trade/payment_method.rb', line 43

def repeat_results
  self.class.where.not(id: self.id).where(account_name: self., account_num: self.)
end